CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.5 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.5
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeNumber
  • CakeTime
  • ClassRegistry
  • Debugger
  • File
  • Folder
  • Hash
  • Inflector
  • ObjectCollection
  • Sanitize
  • Security
  • Set
  • String
  • Validation
  • Xml

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
Location: Cake/Utility/ClassRegistry.php

Properties summary

  • $_config protected
    array
    Default constructor parameter settings, indexed by type
  • $_map protected
    array
    Names of class names mapped to the object in the registry.
  • $_objects protected
    array
    Names of classes with their objects.

Method Summary

  • _duplicate() protected
    Checks to see if $alias is a duplicate $class Object
  • _getMap() protected
    Return the name of a class in the registry.
  • addObject() public static
    Add $object to the registry, associating it with the name $key.
  • config() public static
    Sets the default constructor parameter for an object type
  • flush() public static
    Flushes all objects from the ClassRegistry.
  • getInstance() public static
    Return a singleton instance of the ClassRegistry.
  • getObject() public static
    Return object which corresponds to given key.
  • init() public static

    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.

  • isKeySet() public static
    Returns true if given key is present in the ClassRegistry.
  • keys() public static
    Get all keys from the registry.
  • map() public static
    Add a key name pair to the registry to map name to class in the registry.
  • mapKeys() public static
    Get all keys from the map in the registry.
  • removeObject() public static
    Remove object which corresponds to given key.

Method Detail

_duplicate() 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() 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

addObject() 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

config() 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.


flush() public static ¶

flush( )

Flushes all objects from the ClassRegistry.

getInstance() public static ¶

getInstance( )

Return a singleton instance of the ClassRegistry.

Returns
ClassRegistry
instance

getObject() 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.

init() 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
object
instance of ClassName.
Throws
CakeException
when you try to construct an interface or abstract class.

isKeySet() 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

keys() public static ¶

keys( )

Get all keys from the registry.

Returns
array
Set of keys stored in registry

map() 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() public static ¶

mapKeys( )

Get all keys from the map in the registry.

Returns
array
Keys of registry's map

removeObject() public static ¶

removeObject( string $key )

Remove object which corresponds to given key.

Parameters
string $key
Key of object to remove from registry

Properties detail

$_config ¶

protected array

Default constructor parameter settings, indexed by type

array()

$_map ¶

protected array

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

array()

$_objects ¶

protected array

Names of classes with their objects.

array()
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs