protected function _init() { parent::_init(); unset($this->_config['type']); foreach ($this->_config as $key => $val) { if (method_exists($this, $key) && $val !== null) { $this->_config[$key] = is_array($this->_config[$key]) ? array() : null; $this->{$key}($val); } } if ($list = $this->_config['whitelist']) { $this->_config['whitelist'] = array_combine($list, $list); } if ($this->_config['with']) { $this->_associate($this->_config['with']); } $joins = $this->_config['joins']; $this->_config['joins'] = array(); foreach ($joins as $i => $join) { $this->join($i, $join); } if ($this->_entity && !$this->_config['model']) { $this->model($this->_entity->model()); } unset($this->_config['entity'], $this->_config['init'], $this->_config['with']); }
/** * Initializes default rules to use. * * @return void */ protected function _init() { parent::_init(); $this->_rules += array( 'allowAll' => function() { return true; }, 'denyAll' => function() { return false; }, 'allowAnyUser' => function($user) { return $user ? true : false; }, 'allowIp' => function($user, $request, $options) { $options += array('ip' => false); if (is_string($options['ip']) && strpos($options['ip'], '/') === 0) { return (boolean) preg_match($options['ip'], $request->env('REMOTE_ADDR')); } if (is_array($options['ip'])) { return in_array($request->env('REMOTE_ADDR'), $options['ip']); } return $request->env('REMOTE_ADDR') == $options['ip']; } ); }
/** * Constructor. * * @param array $config Configuration array. You can override the default algorithm. */ public function __construct(array $config = []) { if (!isset($config['secret'])) { throw new ConfigException('Jwt strategy requires a secret key.'); } parent::__construct($config + $this->_defaults); }
/** * Constructor. * * @param array $config Optional configuration parameters. * @return void */ public function __construct(array $config = []) { if (!isset($config['header'])) { throw new ConfigException('Token adapter requires a header.'); } parent::__construct($config + $this->_defaults); }
protected function _init() { parent::_init(); $this->_methods += array('GET' => array('view' => 'id', 'index' => null), 'POST' => array('edit' => 'id', 'add' => null), 'PUT' => array('edit' => 'id'), 'PATCH' => array('edit' => 'id'), 'DELETE' => array('delete' => 'id')); $this->_classes += array('entity' => 'lithium\\data\\Entity', 'response' => 'lithium\\action\\Response', 'resources' => 'li3_resources\\net\\http\\Resources', 'responder' => 'li3_resources\\action\\resource\\Responder'); $this->_responder = $this->_responder ?: $this->_instance('responder'); }
/** * Class constructor. * * Takes care of setting appropriate configurations for this object. * * @param array $config Optional configuration parameters. */ public function __construct(array $config = array()) { if (empty($config['name'])) { $config['name'] = basename(LITHIUM_APP_PATH) . 'cookie'; } parent::__construct($config + $this->_defaults); }
/** * Constructor. * * Takes care of setting appropriate configurations for this object. * * @param array $config Optional configuration parameters. * @return void */ public function __construct(array $config = array()) { if (empty($config['name'])) { $config['name'] = basename(Libraries::get(true, 'path')) . 'cookie'; } parent::__construct($config + $this->_defaults); }
protected function _init() { parent::_init(); if ($this->_config['autoConnect']) { $this->connect(); } }
/** * Perform initialization. * * @return void */ protected function _init() { Object::_init(); $type = isset($this->_config['type']) ? $this->_config['type'] : null; if ($type === 'text') { $h = function ($data) { return $data; }; } else { $encoding = 'UTF-8'; if ($this->_message) { $encoding =& $this->_message->charset; } $h = function ($data) use(&$encoding) { return htmlspecialchars((string) $data, ENT_QUOTES, $encoding); }; } $this->outputFilters += compact('h') + $this->_config['outputFilters']; foreach (array('loader', 'renderer') as $key) { if (is_object($this->_config[$key])) { $this->{'_' . $key} = $this->_config[$key]; continue; } $class = $this->_config[$key]; $config = array('view' => $this) + $this->_config; $path = 'adapter.template.mail'; $instance = Libraries::instance($path, $class, $config); $this->{'_' . $key} = $instance; } }
/** * Constructor. * * @see lithium\util\String::insert() * @param array $config Settings used to configure the adapter. Available options: * - `'path'` _string_: The directory to write log files to. Defaults to * `<app>/resources/tmp/logs`. * - `'timestamp'` _string_: The `date()`-compatible timestamp format. Defaults to * `'Y-m-d H:i:s'`. * - `'file'` _\Closure_: A closure which accepts two parameters: an array * containing the current log message details, and an array containing the `File` * adapter's current configuration. It must then return a file name to write the * log message to. The default will produce a log file name corresponding to the * priority of the log message, i.e. `"debug.log"` or `"alert.log"`. * - `'format'` _string_: A `String::insert()`-compatible string that specifies how * the log message should be formatted. The default format is * `"{:timestamp} {:message}\n"`. * @return void */ public function __construct(array $config = array()) { $defaults = array('path' => Libraries::get(true, 'resources') . '/tmp/logs', 'timestamp' => 'Y-m-d H:i:s', 'file' => function ($data, $config) { return "{$data['priority']}.log"; }, 'format' => "{:timestamp} {:message}\n"); parent::__construct($config + $defaults); }
/** * Class constructor. * * @param array $config */ public function __construct(array $config = array()) { $defaults = array( 'prefix' => '', 'expiry' => '+1 hour' ); parent::__construct($config + $defaults); }
/** * Initializer function called by the constructor unless the constructor * * @see lithium\core\Object::_init() * @throws ConfigException */ protected function _init() { parent::_init(); if (!$this->_connection) { throw new ConfigException("The `'connection'` option must be set."); } }
/** * Initialization of the cookie adapter. * * @return void */ protected function _init() { parent::_init(); if (!$this->_config['name']) { $this->_config['name'] = Inflector::slug(basename(LITHIUM_APP_PATH)) . 'cookie'; } }
/** * Class constructor. * * @param array $config */ public function __construct(array $config = array()) { $defaults = array( 'config' => null, 'expiry' => '+999 days', 'key' => 'log_{:type}_{:timestamp}' ); parent::__construct($config + $defaults); }
/** * Object constructor * * Instantiates the `Redis` object and connects it to the configured server. * * @todo Implement configurable & optional authentication * @see lithium\storage\Cache::config() * @see lithium\storage\cache\adapter\Redis::_ttl() * @param array $config Configuration parameters for this cache adapter. * These settings are indexed by name and queryable through `Cache::config('name')`. The * available settings for this adapter are as follows: * - `'host'` _string_: A string in the form of `'host:port'` indicating the Redis server * to connect to. Defaults to `'127.0.0.1:6379'`. * - `'expiry'` _mixed_: Default expiration for cache values written through this * adapter. Defaults to `'+1 hour'`. For acceptable values, see the `$expiry` parameter * of `Redis::_ttl()`. * - `'persistent'` _boolean_: Indicates whether the adapter should use a persistent * connection when attempting to connect to the Redis server. If `true`, it will * attempt to reuse an existing connection when connecting, and the connection will * not close when the request is terminated. Defaults to `false`. */ public function __construct(array $config = array()) { $defaults = array( 'host' => '127.0.0.1:6379', 'expiry' => '+1 hour', 'persistent' => false ); parent::__construct($config + $defaults); }
/** * Connect to FTP server on initialization */ protected function _init() { parent::_init(); if ($this->_config['url'] && substr($this->_config['url'], -1) === '/') { $this->_config['url'] = rtrim($this->_config['url'], '/'); } $this->_connect(); }
protected function _init() { parent::_init(); $class = Libraries::locate('socket.util', $this->_classes['socket']); if (is_string($class)) { $this->_connection = new $class($this->_config); } }
public function __construct(array $config = array()) { if (isset($config['autoConfig'])) { $this->_autoConfig = (array) $config['autoConfig']; unset($config['autoConfig']); } parent::__construct($config); }
protected function _init() { parent::_init(); $this->_classes += array('router' => 'lithium\\net\\http\\Router', 'resources' => 'li3_resources\\action\\Resources'); $classes = $this->_classes; $this->_fields += array('$links.self' => function ($entity) use($classes) { }); }
/** * Constructor * * @param array $options Options */ public function __construct(array $options) { parent::__construct($options); $this->client = new GearmanClient(); foreach ($this->_config['servers'] as $server) { $this->client->addServer($server); } }
/** * Adds config values to the public properties when a new object is created. * * @param array $config Configuration options : default value * - `scheme`: tcp * - `host`: localhost * - `port`: null * - `username`: null * - `password`: null * - `path`: null * - `body`: null */ public function __construct(array $config = array()) { $defaults = array('scheme' => 'tcp', 'host' => 'localhost', 'port' => null, 'username' => null, 'password' => null, 'path' => null, 'body' => null); $config += $defaults; foreach (array_intersect_key(array_filter($config), $defaults) as $key => $value) { $this->{$key} = $value; } parent::__construct($config); }
public function __construct(array $config = array()) { $defaults = array('method' => null, 'data' => null, 'options' => array()); $this->_requestTypes = array('use' => function ($tube, $options) { return sprintf('use %s', $tube); }, 'put' => function ($data, $options) { extract($options, EXTR_OVERWRITE); $cmd = sprintf('put %d %d %d %d', $pri, $delay, $ttr, strlen($data)); return join("\r\n", array($cmd, $data)); }, 'reserve' => function ($data, array $options = array()) { return 'reserve'; }, 'reserve-with-timeout' => function ($data, array $options = array()) { extract($options, EXTR_OVERWRITE); return sprintf('reserve-with-timeout %d', $timeout); }, 'release' => function ($id, array $options = array()) { extract($options, EXTR_OVERWRITE); return sprintf('release %d %d %d', $id, $pri, $delay); }, 'delete' => function ($id, array $options = array()) { return sprintf('delete %d', $id); }, 'bury' => function ($id, array $options = array()) { return sprintf('delete %d %d', $id, $pri); }, 'touch' => function ($id, array $options = array()) { return sprintf('touch %d', $id); }, 'watch' => function ($tube, array $options = array()) { return sprintf('watch %s', $tube); }, 'ignore' => function ($tube, array $options = array()) { return sprintf('ignore %s', $tube); }, 'peek' => function ($id, array $options = array()) { return sprintf('peek %d', $id); }, 'peek-ready' => function ($data, array $options = array()) { return sprintf('peek-ready'); }, 'peek-delayed' => function ($data, array $options = array()) { return sprintf('peek-delayed'); }, 'peek-buried' => function ($data, array $options = array()) { return sprintf('peek-buried'); }, 'kick' => function ($bound, array $options = array()) { return sprintf('kick %d', $bound); }, 'kick-job' => function ($id, array $options = array()) { return sprintf('kick-job %d', $id); }, 'stats-job' => function ($id, array $options = array()) { return sprintf('stats-job %d', $id); }, 'stats-tube' => function ($tube, array $options = array()) { return sprintf('stats-tube %s', $tube); }, 'stats' => function ($data, array $options = array()) { return 'stats'; }, 'list-tubes' => function ($data, array $options = array()) { return 'list-tubes'; }, 'list-tube-used' => function ($data, array $options = array()) { return 'list-tube-used'; }, 'list-tubes-watched' => function ($data, array $options = array()) { return 'list-tubes-watched'; }, 'pause-tube' => function ($data, array $options = array()) { return 'pause-tube'; }); return parent::__construct($config + $defaults); }
/** * Object constructor. * Instantiates the Memcached object, adds appropriate servers to the pool, * and configures any optional settings passed. * * @see lithium\storage\Cache::config() * @param array $config Configuration parameters for this cache adapter. * These settings are indexed by name and queryable * through `Cache::config('name')`. * @return void */ public function __construct(array $config = array()) { $defaults = array('prefix' => '', 'expiry' => '+1 hour', 'servers' => array(array('127.0.0.1', 11211, 100))); if (is_null(static::$connection)) { static::$connection = new \Memcached(); } $configuration = Set::merge($defaults, $config); parent::__construct($configuration); static::$connection->addServers($this->_config['servers']); }
/** * Object constructor * * Instantiates the Redis object and connects it to the configured server. * * @param array $config Configuration parameters for this cache adapter. * These settings are indexed by name and queryable through `Cache::config('name')`. * * @return void * @see lithium\storage\Cache::config() * @todo Implement configurable & optional authentication */ public function __construct($config = array()) { $defaults = array('prefix' => '', 'server' => '127.0.0.1:6379'); if (is_null(static::$_Redis)) { static::$_Redis = new \Redis(); } $config += $defaults; parent::__construct($config); list($IP, $port) = explode(':', $this->_config['server']); static::$_Redis->connect($IP, $port); }
/** * Imports local string definitions into rendering context. * * @return void */ protected function _init() { parent::_init(); if (!$this->_context) { return; } $this->_context->strings($this->_strings); if ($this->_config['handlers']) { $this->_context->handlers($this->_config['handlers']); } }
/** * undocumented function * * @return void */ protected function _init() { parent::_init(); if (empty($this->_file)) { $this->_file = LITHIUM_APP_PATH . '/resources/oauth/storage/oauth.json'; return; } if ($this->_file[0] !== '/') { $this->_file = LITHIUM_APP_PATH . '/resources/oauth/' . $this->_file; } }
/** * Growl logger constructor. Accepts an array of settings which are merged with the default * settings and used to create the connection and handle notifications. * * @see lithium\analysis\Logger::write() * @param array $config The settings to configure the logger. Available settings are as follows: * - `'name`' _string_: The name of the application as it should appear in Growl's * system settings. Defaults to the directory name containing your application. * - `'host'` _string_: The Growl host with which to communicate, usually your * local machine. Use this setting to send notifications to another machine on * the network. Defaults to `'127.0.0.1'`. * - `'port'` _integer_: Port of the host machine. Defaults to the standard Growl * port, `9887`. * - `'password'` _string_: Only required if the host machine requires a password. * If notification or registration fails, check this against the host machine's * Growl settings. * - '`protocol'` _string_: Protocol to use when opening socket communication to * Growl. Defaults to `'udp'`. * - `'title'` _string_: The default title to display when showing Growl messages. * The default value is the same as `'name'`, but can be changed on a per-message * basis by specifying a `'title'` key in the `$options` parameter of * `Logger::write()`. * - `'notification'` _array_: A list of message types you wish to register with * Growl to be able to send. Defaults to `array('Errors', 'Messages')`. * @return void */ public function __construct(array $config = array()) { $name = basename(LITHIUM_APP_PATH); $defaults = array('name' => $name, 'host' => '127.0.0.1', 'port' => 9887, 'password' => null, 'protocol' => 'udp', 'title' => Inflector::humanize($name), 'notifications' => array('Errors', 'Messages'), 'connection' => function ($host, $port) { if ($conn = fsockopen($host, $port, $message, $code)) { return $conn; } throw new NetworkException("Growl connection failed: ({$code}) {$message}"); }); parent::__construct($config + $defaults); }
/** * Initializer. Populates the `response` property with a new instance of the `Response` * class passing it configuration and assigns the values from named parameters of the * request (if applicable) to properties of the command. * * @return void */ protected function _init() { parent::_init(); $this->request = $this->_config['request']; $this->response = new $this->_classes['response']($this->_config['response']); if (!empty($this->request->params)) { $params = (array) array_diff_key($this->request->params, array('command' => null, 'action' => null, 'args' => null)); foreach ($params as $key => $param) { $this->{$key} = $param; } } }
protected function _init() { parent::_init(); $model = $this->_config['model']; $behavior = $this; $this->_config = static::_config($model, $behavior, $this->_config, static::$_defaults); static::_filters($model, $behavior); static::_finders($model, $behavior); if ($methods = static::_methods($model, $behavior)) { $model::instanceMethods($methods); } }
/** * Sets the default output handlers for string template inputs. * * Please note: skips lithium\template\view\Renderer::_init() * to skip setting handlers. * * @return void */ protected function _init() { Object::_init(); $classes =& $this->_classes; $message =& $this->_message; if (!$this->_request && $message) { $media = $classes['media']; $this->_request = $media::invokeMethod('_request', array($message)); } $request =& $this->_request; $context =& $this->_context; $h = $this->_view ? $this->_view->outputFilters['h'] : null; $this->_handlers += array('url' => function ($url, $ref, array $options = array()) use($classes, &$request, $h) { $router = $classes['router']; $options += array('absolute' => true); $url = $router::match($url ?: '', $request, $options); return $h ? str_replace('&', '&', $h($url)) : $url; }, 'path' => function ($path, $ref, array $options = array()) use($classes, &$request, &$message) { $embed = isset($options['embed']) && $options['embed']; unset($options['embed']); if ($embed) { return 'cid:' . $message->embed($path, $options); } else { $type = 'generic'; if (is_array($ref) && $ref[0] && $ref[1]) { list($helper, $methodRef) = $ref; list($class, $method) = explode('::', $methodRef); $type = $helper->contentMap[$method]; } $httpMedia = $classes['http_media']; $base = $request ? $request->env('base') : ''; $options += compact('base'); $path = $httpMedia::asset($path, $type, $options); if ($path[0] === '/') { $host = ''; if ($request) { $https = $request->env('HTTPS') ? 's' : ''; $host .= "http{$https}://"; $host .= $request->env('HTTP_HOST'); } $path = $host . $path; } return $path; } }, 'options' => '_attributes', 'title' => 'escape', 'scripts' => function ($scripts) use(&$context) { return "\n\t" . join("\n\t", $context['scripts']) . "\n"; }, 'styles' => function ($styles) use(&$context) { return "\n\t" . join("\n\t", $context['styles']) . "\n"; }, 'head' => function ($head) use(&$context) { return "\n\t" . join("\n\t", $context['head']) . "\n"; }); unset($this->_config['view']); }