Class ClassRegistry

Class Collections.

A repository for class objects, each registered with a key. If you try to add an object with the same key twice, nothing will come of it. If you need a second instance of an object, give it another key.

Package: Cake\Utility
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Located at Cake/Utility/ClassRegistry.php

Method Detail

_duplicatesource protected

_duplicate( string $alias , string $class )

Checks to see if $alias is a duplicate $class Object

Parameters

string $alias
Alias to check.
string $class
Class name.

Returns

boolean
bool

_getMapsource protected

_getMap( string $key )

Return the name of a class in the registry.

Parameters

string $key
Key to find in map

Returns

string
Mapped value

addObjectsource public static

addObject( string $key , object $object )

Add $object to the registry, associating it with the name $key.

Parameters

string $key
Key for the object in registry
object $object
Object to store

Returns

boolean
True if the object was written, false if $key already exists

configsource public static

config( string $type , array $param array() )

Sets the default constructor parameter for an object type

Parameters

string $type
Type of object. If this parameter is omitted, defaults to "Model"
array $param optional array()
The parameter that will be passed to object constructors when objects of $type are created

Returns

mixed
Void if $param is being set. Otherwise, if only $type is passed, returns the previously-set value of $param, or null if not set.

flushsource public static

flush( )

Flushes all objects from the ClassRegistry.

getInstancesource public static

getInstance( )

Return a singleton instance of the ClassRegistry.

Returns

ClassRegistry
instance

getObjectsource public static

getObject( string $key )

Return object which corresponds to given key.

Parameters

string $key
Key of object to look for

Returns

mixed
Object stored in registry or boolean false if the object does not exist.

initsource public static

init( string|array $class , boolean $strict false )

Loads a class, registers the object in the registry and returns instance of the object. ClassRegistry::init() is used as a factory for models, and handle correct injecting of settings, that assist in testing.

Examples Simple Use: Get a Post model instance ClassRegistry::init('Post');

Expanded: array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry');

Model Classes can accept optional array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias);

When $class is a numeric keyed array, multiple class instances will be stored in the registry, no instance of the object will be returned

array(
        array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry'),
        array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry'),
        array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry')
);

Parameters

string|array $class
as a string or a single key => value array instance will be created, stored in the registry and returned.
boolean $strict optional false
if set to true it will return false if the class was not found instead of trying to create an AppModel

Returns

mixed
$class instance of ClassName.

Throws

CakeException
when you try to construct an interface or abstract class.

isKeySetsource public static

isKeySet( string $key )

Returns true if given key is present in the ClassRegistry.

Parameters

string $key
Key to look for

Returns

boolean
true if key exists in registry, false otherwise

keyssource public static

keys( )

Get all keys from the registry.

Returns

array
Set of keys stored in registry

mapsource public static

map( string $key , string $name )

Add a key name pair to the registry to map name to class in the registry.

Parameters

string $key
Key to include in map
string $name
Key that is being mapped

mapKeyssource public static

mapKeys( )

Get all keys from the map in the registry.

Returns

array
Keys of registry's map

removeObjectsource public static

removeObject( string $key )

Remove object which corresponds to given key.

Parameters

string $key
Key of object to remove from registry

Properties summary

$_configsource

protected array

Default constructor parameter settings, indexed by type

array()

$_mapsource

protected array

Names of class names mapped to the object in the registry.

array()

$_objectssource

protected array

Names of classes with their objects.

array()

© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-ClassRegistry.html