PHP Class lithium\core\Object

Options defined: - 'init' boolean Controls constructor behaviour for calling the _init method. If false the method is not called, otherwise it is. Defaults to true.
Datei anzeigen Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_autoConfig array Holds an array of values that should be processed on initialization. Each value should have a matching protected property (prefixed with _) defined in the class. If the property is an array, the property name should be the key and the value should be 'merge'. See the _init() method for more details.
$_config array **Do not override.** Pass any additional variables to parent::__construct().
$_methodFilters array Contains a 2-dimensional array of filters applied to this object's methods, indexed by method name. See the associated methods for more details.
$_parents array Parents of the current class.

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor. Initializes class configuration ($_config), and assigns object properties using the _init() method, unless otherwise specified by configuration. See below for details.
__set_state ( array $data ) : object PHP magic method used in conjunction with var_export() to allow objects to be re-instantiated with their pre-existing properties and values intact. This method can be called statically on any class that extends Object to return an instance of it.
applyFilter ( mixed $method, Closure $filter = null ) : void Apply a closure to a method of the current object instance.
invokeMethod ( string $method, array $params = [] ) : mixed Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.

Protected Methods

Method Description
_filter ( string $method, array $params, Closure $callback, array $filters = [] ) : mixed Executes a set of filters against a method by taking a method's main implementation as a callback, and iteratively wrapping the filters around it. This, along with the Filters class, is the core of Lithium's filters system. This system allows you to "reach into" an object's methods which are marked as _filterable_, and intercept calls to those methods, optionally modifying parameters or return values.
_init ( ) : void Initializer function called by the constructor unless the constructor 'init' flag is set to false. May be used for testing purposes, where objects need to be manipulated in an un-initialized state, or for high-overhead operations that require more control than the constructor provides. Additionally, this method iterates over the $_autoConfig property to automatically assign configuration settings to their corresponding properties.
_instance ( string | object $name, array $options = [] ) : object Returns an instance of a class with given config. The name could be a key from the classes array, a fully-namespaced class name, or an object. Typically this method is used in _init to create the dependencies used in the current class.
_parents ( ) : array Gets and caches an array of the parent methods of a class.
_stop ( integer | string $status ) : void Exit immediately. Primarily used for overrides during testing.

Method Details

__construct() public method

Constructor. Initializes class configuration ($_config), and assigns object properties using the _init() method, unless otherwise specified by configuration. See below for details.
See also: lithium\core\Object::$_config
See also: lithium\core\Object::_init()
public __construct ( array $config = [] ) : void
$config array The configuration options which will be assigned to the `$_config` property. This method accepts one configuration option: - `'init'` _boolean_: Controls constructor behavior for calling the `_init()` method. If `false`, the method is not called, otherwise it is. Defaults to `true`.
return void

__set_state() public static method

PHP magic method used in conjunction with var_export() to allow objects to be re-instantiated with their pre-existing properties and values intact. This method can be called statically on any class that extends Object to return an instance of it.
public static __set_state ( array $data ) : object
$data array An array of properties and values with which to re-instantiate the object. These properties can be both public and protected.
return object Returns an instance of the requested object with the given properties set.

_filter() protected method

Executes a set of filters against a method by taking a method's main implementation as a callback, and iteratively wrapping the filters around it. This, along with the Filters class, is the core of Lithium's filters system. This system allows you to "reach into" an object's methods which are marked as _filterable_, and intercept calls to those methods, optionally modifying parameters or return values.
See also: lithium\core\Object::applyFilter()
See also: lithium\util\collection\Filters
protected _filter ( string $method, array $params, Closure $callback, array $filters = [] ) : mixed
$method string The name of the method being executed, usually the value of `__METHOD__`.
$params array An associative array containing all the parameters passed into the method.
$callback Closure The method's implementation, wrapped in a closure.
$filters array Additional filters to apply to the method for this call only.
return mixed Returns the return value of `$callback`, modified by any filters passed in `$filters` or applied with `applyFilter()`.

_init() protected method

For example, given the following: class Bar extends \lithium\core\Object { protected $_autoConfig = array('foo'); protected $_foo; } $instance = new Bar(array('foo' => 'value')); The $_foo property of $instance would automatically be set to 'value'. If $_foo was an array, $_autoConfig could be set to array('foo' => 'merge'), and the constructor value of 'foo' would be merged with the default value of $_foo and assigned to it.
See also: lithium\core\Object::$_autoConfig
protected _init ( ) : void
return void

_instance() protected method

Returns an instance of a class with given config. The name could be a key from the classes array, a fully-namespaced class name, or an object. Typically this method is used in _init to create the dependencies used in the current class.
protected _instance ( string | object $name, array $options = [] ) : object
$name string | object A `classes` key or fully-namespaced class name.
$options array The configuration passed to the constructor.
return object

_parents() protected static method

Gets and caches an array of the parent methods of a class.
protected static _parents ( ) : array
return array Returns an array of parent classes for the current class.

_stop() protected method

Exit immediately. Primarily used for overrides during testing.
protected _stop ( integer | string $status ) : void
$status integer | string integer range 0 to 254, string printed on exit
return void

applyFilter() public method

Apply a closure to a method of the current object instance.
See also: lithium\core\Object::_filter()
See also: lithium\util\collection\Filters
public applyFilter ( mixed $method, Closure $filter = null ) : void
$method mixed The name of the method to apply the closure to. Can either be a single method name as a string, or an array of method names. Can also be false to remove all filters on the current object.
$filter Closure The closure that is used to filter the method(s), can also be false to remove all the current filters for the given method.
return void

invokeMethod() public method

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.
public invokeMethod ( string $method, array $params = [] ) : mixed
$method string Name of the method to call
$params array Parameter list to use when calling $method
return mixed Returns the result of the method call

respondsTo() public method

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
return boolean Returns `true` if the method can be called, `false` otherwise.

Property Details

$_autoConfig protected_oe property

Holds an array of values that should be processed on initialization. Each value should have a matching protected property (prefixed with _) defined in the class. If the property is an array, the property name should be the key and the value should be 'merge'. See the _init() method for more details.
See also: lithium\core\Object::_init()
protected array $_autoConfig
return array

$_config protected_oe property

**Do not override.** Pass any additional variables to parent::__construct().
protected array $_config
return array

$_methodFilters protected_oe property

Contains a 2-dimensional array of filters applied to this object's methods, indexed by method name. See the associated methods for more details.
See also: lithium\core\Object::_filter()
See also: lithium\core\Object::applyFilter()
protected array $_methodFilters
return array

$_parents protected_oe static_oe property

Parents of the current class.
See also: lithium\core\Object::_parents()
protected static array $_parents
return array