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.
/** * Override adapter retrival by not storing the object * * @see lithium\core\Adaptable::adapter */ public static function adapter($name = null) { $object = parent::adapter($name); // Do not store the mail created unset(static::$_configurations[$name][0]['object']); return $object; }
/** * Called when an adapter configuration is first accessed, this method sets the default * configuration for session handling. While each configuration can use its own session class * and options, this method initializes them to the default dependencies written into the class. * For the session key name, the default value is set to the name of the configuration. * * @param string $name The name of the adapter configuration being accessed. * @param array $config The user-specified configuration. * @return array Returns an array that merges the user-specified configuration with the * generated default values. */ protected static function _initConfig($name, $config) { $defaults = array('session' => array('key' => $name, 'class' => static::$_classes['session'], 'options' => array())); $config = parent::_initConfig($name, $config) + $defaults; $config['session'] += $defaults['session']; return $config; }
/** * Sets configurations for this Adaptable implementation. * * @param array $config Configurations, indexed by name. * @return array `Collection` of configurations or void if setting configurations. */ public static function config($config = null) { $defaults = array('scope' => null); if (is_array($config)) { foreach ($config as $i => $item) { $config[$i] += $defaults; } } return parent::config($config); }
public static function config($config = null) { $default = array('scope' => null); if ($config) { $config = array_map(function ($i) use($default) { return $i + $default; }, $config); } return parent::config($config); }
/** * Returns the adapter object instance of the named configuration. * * @param string $name Named configuration. If not set, the last configured * adapter object instance will be returned. * @return object Adapter instance. */ public static function adapter($name = null) { if (!$name) { if (!($names = array_keys(static::$_configurations))) { return; } $name = end($names); } return parent::adapter($name); }
public static function adapter($name = null) { if (empty($name)) { if (!($names = static::$_configurations->keys())) { return; } $name = end($names); } return parent::adapter($name); }
/** * Constructs a data source or adapter object instance from a configuration array. * * @param array $config * @param array $paths * @return object */ protected static function _class($config, $paths = array()) { if (!$config['adapter']) { $config['adapter'] = $config['type']; } else { $paths = array_merge(array("adapter.data.source.{$config['type']}"), (array) $paths); } return parent::_class($config, $paths); }
/** * Initializes configuration with default settings * * @param string $name The name of the configuration which is being accessed. This is the key * name containing the specific set of configuration passed into `config()`. * @param array $config 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. */ protected static function _initConfig($name, $config) { $defaults = ['filters' => [], 'servers' => []]; $config = parent::_initConfig($name, $config) + $defaults; foreach (['filters', 'servers'] as $arrayVar) { if (!empty($config[$arrayVar]) && !is_array($config[$arrayVar])) { $config[$arrayVar] = (array) $config[$arrayVar]; } elseif (empty($config[$arrayVar])) { $config[$arrayVar] = []; } } if (empty($config['adapter'])) { $config['adapter'] = 'Job'; } return $config; }
/** * Called when an adapter configuration is first accessed, this method sets the default * configuration for session handling. While each configuration can use its own session class * and options, this method initializes them to the default dependencies written into the class. * For the session key name, the default value is set to the name of the configuration. * * @param string $name The name of the adapter configuration being accessed. * @param array $config The user-specified configuration. * @return array Returns an array that merges the user-specified configuration with the * generated default values. */ protected static function _initConfig($name, $config) { $defaults = array('adapter' => 'Model', 'events' => true, 'groups' => array()); $config = parent::_initConfig($name, $config) + $defaults; return $config; }
/** * Called when an adapter configuration is first accessed, this method sets the default * configuration for session handling. While each configuration can use its own session class * and options, this method initializes them to the default dependencies written into the class. * For the session key name, the default value is set to the name of the configuration. * * @param string $name The name of the adapter configuration being accessed. * @param array $config The user-specified configuration. * @return array Returns an array that merges the user-specified configuration with the * generated default values. */ protected static function _initConfig($name, $config) { $defaults = array(); $config = parent::_initConfig($name, $config) + $defaults; return $config; }
/** * This method is called automatically to initialize the default configuration of a log adapter, * such that the adapter defaults to accepting log messages of any priority (i.e. the * `'priority'` key is set to `true`). * * @param string $name The name of the logger configuration. * @param array $config The logger configuration as specified in application code. * @return array Returns an array of configuration data, merged with default values. */ protected static function _initConfig($name, $config) { $defaults = array('priority' => true); return parent::_initConfig($name, $config) + $defaults; }
/** * Should use ApplyStrategies() to call enabled() from the strategy class * that should check if the requirements to use the strategy are met. * * @todo * @see: lithium\core\Adaptable::enabled() */ public static function enabled($name) { return parent::enabled($name); }