On this page
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.
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Utility/ClassRegistry.php
Properties summary
- 
    $_configprotectedDefault constructor parameter settings, indexed by typearray
- 
    $_mapprotectedNames of class names mapped to the object in the registry.array
- 
    $_objectsprotectedNames of classes with their objects.array
Method Summary
- 
    _duplicate() protectedChecks to see if $alias is a duplicate $class Object
- 
    _getMap() protectedReturn the name of a class in the registry.
- Add $object to the registry, associating it with the name $key.
- Sets the default constructor parameter for an object type
- Flushes all objects from the ClassRegistry.
- Return a singleton instance of the ClassRegistry.
- Return object which corresponds to given key.
- 
     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. 
- Returns true if given key is present in the ClassRegistry.
- Get all keys from the registry.
- Add a key name pair to the registry to map name to class in the registry.
- Get all keys from the map in the registry.
- Remove object which corresponds to given key.
Method Detail
_duplicate()source 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_getMap()source protected
_getMap( string $key )Return the name of a class in the registry.
Parameters
- 
     string $key
- Key to find in map
Returns
stringMapped value
addObject()source 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
booleanTrue if the object was written, false if $key already exists
config()source 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 $paramoptional array()
- 
     The parameter that will be passed to object constructors when objects of $type are created 
Returns
mixedVoid if $param is being set. Otherwise, if only $type is passed, returns the previously-set value of $param, or null if not set.
getInstance()source public static
getInstance( )Return a singleton instance of the ClassRegistry.
Returns
ClassRegistryinstance
getObject()source public static
getObject( string $key )Return object which corresponds to given key.
Parameters
- 
     string $key
- Key of object to look for
Returns
mixedObject stored in registry or boolean false if the object does not exist.
init()source 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');<pre>Expanded:array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry');```
Model Classes can accept optional <span class="php-keyword1">array</span>(<span class="php-quote">'id'</span> => <span class="php-var">$id</span>, <span class="php-quote">'table'</span> => <span class="php-var">$table</span>, <span class="php-quote">'ds'</span> => <span class="php-var">$ds</span>, <span class="php-quote">'alias'</span> => <span class="php-var">$alias</span>);
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 $strictoptional false
- 
     if set to true it will return false if the class was not found instead of trying to create an AppModel 
Returns
$class instance of ClassName.
Throws
CakeExceptionwhen you try to construct an interface or abstract class.
isKeySet()source public static
isKeySet( string $key )Returns true if given key is present in the ClassRegistry.
Parameters
- 
     string $key
- Key to look for
Returns
booleantrue if key exists in registry, false otherwise
keys()source public static
keys( )Get all keys from the registry.
Returns
arraySet of keys stored in registry
map()source 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
mapKeys()source public static
mapKeys( )Get all keys from the map in the registry.
Returns
arrayKeys of registry's map
removeObject()source public static
removeObject( string $key )Remove object which corresponds to given key.
Parameters
- 
     string $key
- Key of object to remove from registry
Properties detail
© 2005–2017 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.
 https://api.cakephp.org/2.10/class-ClassRegistry.html