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 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: The MIT License
Location: class_registry.php
Properties summary
-
$__config
publicarray
Default constructor parameter settings, indexed by type -
$__map
publicarray
Names of class names mapped to the object in the registry. -
$__objects
publicarray
Names of classes with their objects.
Method Summary
-
__duplicate() public
Checks to see if $alias is a duplicate $class Object -
__getMap() public
Return the name of a class in the registry. -
addObject() public
Add $object to the registry, associating it with the name $key. -
config() public
Sets the default constructor parameter for an object type -
flush() public
Flushes all objects from the ClassRegistry. -
getInstance() public
Return a singleton instance of the ClassRegistry. -
getObject() public
Return object which corresponds to given key. -
init() public
Loads a class, registers the object in the registry and returns instance of the object. -
isKeySet() public
Returns true if given key is present in the ClassRegistry. -
keys() public
Get all keys from the registry. -
map() public
Add a key name pair to the registry to map name to class in the registry. -
mapKeys() public
Get all keys from the map in the registry. -
removeObject() public
Remove object which corresponds to given key.
Method Detail
__duplicate() public ¶
__duplicate( string $alias , string $class )
Checks to see if $alias is a duplicate $class Object
Parameters
- string $alias
- string $class
Returns
__getMap() public ¶
__getMap( string $key )
Return the name of a class in the registry.
Parameters
- string $key
- Key to find in map
Returns
Mapped value
addObject() public ¶
addObject( string $key , mixed $object )
Add $object to the registry, associating it with the name $key.
Parameters
- string $key
- Key for the object in registry
- mixed $object
- Object to store
Returns
True if the object was written, false if $key already exists
config() public ¶
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
Void if $param is being set. Otherwise, if only $type is passed, returns the previously-set value of $param, or null if not set.
getObject() public ¶
getObject( string $key )
Return object which corresponds to given key.
Parameters
- string $key
- Key of object to look for
Returns
Object stored in registry or boolean false if the object does not exist.
init() public ¶
init( mixed $class , string $type = null )
Loads a class, registers the object in the registry and returns instance of the object.
Examples
Simple Use: Get a Post model instance ClassRegistry::init('Post');
Exapanded: array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass');
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', 'type' => 'TypeOfClass'), array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass'), array('class' => 'ClassName', 'alias' => 'AliasNameStoredInTheRegistry', 'type' => 'TypeOfClass') ); }}}
Parameters
- mixed $class
as a string or a single key => value array instance will be created, stored in the registry and returned.
- string $type optional null
- TypeOfClass
Returns
instance of ClassName
isKeySet() public ¶
isKeySet( string $key )
Returns true if given key is present in the ClassRegistry.
Parameters
- string $key
- Key to look for
Returns
true if key exists in registry, false otherwise
map() public ¶
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() public ¶
mapKeys( )
Get all keys from the map in the registry.
Returns
Keys of registry's map
removeObject() public ¶
removeObject( string $key )
Remove object which corresponds to given key.
Parameters
- string $key
- Key of object to remove from registry