PHP Class lithium\core\Adaptable

Adaptable provides the logic necessary for generic configuration of named adapter configurations (such as the ones used in Cache) as well as a unified method of locating and obtaining an instance to a specified adapter. All immediate subclasses to Adaptable must define the protected attributes $_configurations and $_adapters. The former is where all local adapter named configurations will be stored (as an array of named configuration settings), and the latter must contain the Libraries::locate()-compatible path string (or array of strings) specifying how adapter classes should be located. This static class should **never** be called explicitly.
Inheritance: extends StaticObject
Show file Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_adapters Must always be re-defined in sub-classes. Holds the Libraries::locate() compatible path string where the adapter in question may be found i.e. 'adapter.storage.cache'.
$_configurations Example: array( 'production' => array(), 'development' => array(), 'test' => array() )
$_strategies Holds the Libraries::locate() compatible path string where the strategy in question may be found i.e. 'strategy.storage.cache'.

Public Methods

Method Description
adapter ( string | null $name = null ) : object Returns adapter class name for given $name configuration, using the $_adapter path defined in Adaptable subclasses.
applyStrategies ( string $method, string $name, mixed $data, array $options = [] ) : mixed Applies strategies configured in $name for $method on $data.
config ( array | string $config = null ) : array | void Sets configurations for a particular adaptable implementation, or returns the current configuration settings.
enabled ( string $name ) : boolean Determines if the adapter specified in the named configuration is enabled.
reset ( ) : void Clears all configurations.
strategies ( string $name ) : object Obtain an SplDoublyLinkedList of the strategies for the given $name configuration, using the $_strategies path defined in Adaptable subclasses.

Protected Methods

Method Description
_class ( array $config, array $paths = [] ) : string Looks up an adapter by class by name.
_config ( string $name ) : array | null Gets an array of settings for the given named configuration in the current environment.
_initAdapter ( string $class, array $config ) : object Provides an extension point for modifying how adapters are instantiated.
_initConfig ( string $name, array $config ) : array A stub method called by _config() which allows Adaptable subclasses to automatically assign or auto-generate additional configuration data, once a configuration is first accessed. This allows configuration data to be lazy-loaded from adapters or other data sources.
_locate ( string | array $paths, string $name ) : string Perform library location for an array of paths or a single string-based path.
_strategy ( string $name, array $paths = [] ) : string Looks up a strategy by class by name.

Method Details

_class() protected static method

Looks up an adapter by class by name.
See also: lithium\core\libraries::locate()
protected static _class ( array $config, array $paths = [] ) : string
$config array Configuration array of class to be found.
$paths array Optional array of search paths that will be checked.
return string Returns a fully-namespaced class reference to the adapter class.

_config() protected static method

The default types of settings for all adapters will contain keys for: adapter - The class name of the adapter filters - An array of filters to be applied to the adapter methods
See also: lithium\core\Environment
protected static _config ( string $name ) : array | null
$name string Named configuration.
return array | null Settings for the named configuration.

_initAdapter() protected static method

Provides an extension point for modifying how adapters are instantiated.
See also: lithium\core\Object::__construct()
protected static _initAdapter ( string $class, array $config ) : object
$class string The fully-namespaced class name of the adapter to instantiate.
$config array The configuration array to be passed to the adapter instance. See the `$config` parameter of `Object::__construct()`.
return object The adapter's class.

_initConfig() protected static method

A stub method called by _config() which allows Adaptable subclasses to automatically assign or auto-generate additional configuration data, once a configuration is first accessed. This allows configuration data to be lazy-loaded from adapters or other data sources.
protected static _initConfig ( string $name, array $config ) : array
$name string The name of the configuration which is being accessed. This is the key name containing the specific set of configuration passed into `config()`.
$config array Contains the configuration assigned to `$name`. If this configuration is segregated by environment, then this will contain the configuration for the current environment.
return array Returns the final array of settings for the given named configuration.

_locate() protected static method

Perform library location for an array of paths or a single string-based path.
protected static _locate ( string | array $paths, string $name ) : string
$paths string | array Paths that Libraries::locate() will utilize.
$name string The name of the class to be located.
return string Fully-namespaced path to the class, or null if not found.

_strategy() protected static method

Looks up a strategy by class by name.
See also: lithium\core\libraries::locate()
protected static _strategy ( string $name, array $paths = [] ) : string
$name string The strategy to locate.
$paths array Optional array of search paths that will be checked.
return string Returns a fully-namespaced class reference to the adapter class.

adapter() public static method

Returns adapter class name for given $name configuration, using the $_adapter path defined in Adaptable subclasses.
public static adapter ( string | null $name = null ) : object
$name string | null Class name of adapter to load.
return object Adapter object.

applyStrategies() public static method

Applies strategies configured in $name for $method on $data.
public static applyStrategies ( string $method, string $name, mixed $data, array $options = [] ) : mixed
$method string The strategy method to be applied.
$name string The named configuration
$data mixed The data to which the strategies will be applied.
$options array If `mode` is set to 'LIFO', the strategies are applied in reverse. order of their definition.
return mixed Result of application of strategies to data. If no strategies have been configured, this method will simply return the original data.

config() public static method

Sets configurations for a particular adaptable implementation, or returns the current configuration settings.
public static config ( array | string $config = null ) : array | void
$config array | string An array of configurations, indexed by name to set configurations in one go or a name for which to return the configuration.
return array | void Configuration or void if setting configurations.

enabled() public static method

Enabled can mean various things, e.g. having a PECL memcached extension compiled & loaded, as well as having the memcache server up & available.
public static enabled ( string $name ) : boolean
$name string The named configuration whose adapter will be checked.
return boolean True if adapter is enabled, false if not. This method will return null if no configuration under the given $name exists.

reset() public static method

Clears all configurations.
public static reset ( ) : void
return void

strategies() public static method

Obtain an SplDoublyLinkedList of the strategies for the given $name configuration, using the $_strategies path defined in Adaptable subclasses.
public static strategies ( string $name ) : object
$name string Class name of adapter to load.
return object `SplDoublyLinkedList` of strategies, or `null` if none are defined.

Property Details

$_adapters protected static property

Must always be re-defined in sub-classes. Holds the Libraries::locate() compatible path string where the adapter in question may be found i.e. 'adapter.storage.cache'.
protected static $_adapters

$_configurations protected static property

Example: array( 'production' => array(), 'development' => array(), 'test' => array() )
protected static $_configurations

$_strategies protected static property

Holds the Libraries::locate() compatible path string where the strategy in question may be found i.e. 'strategy.storage.cache'.
protected static $_strategies