/** * Creates the logging service. * * A logger name can be specified in config variable 'plugin'. * An instance of "Loops\Logger\%Logger" will be attached to this logger * with % being the camelized version of the loggers name. * An array can also be passed to attach multiple loggers. * Alternatively multiple loggers can be passed as a comma separated * string. * Other configuration parameters are passed to the constructor(s) of the * logging class(es). */ public static function getService(ArrayObject $config, Loops $loops) { $logger = parent::getService($config, $loops); $plugin = $config->offsetExists("plugin") ? $config->offsetGet("plugin") : "stderr"; foreach (array_filter(is_array($plugin) ? $plugin : explode(",", $plugin)) as $plugin) { $classname = "Loops\\Logger\\" . Misc::camelize($plugin) . "Logger"; $logger->attach(Misc::reflectionInstance($classname, $config)); } return $logger; }
public static function getService(ArrayObject $config, Loops $loops) { $redis = parent::getService($config, $loops); $params = static::getDefaultConfig($loops); $params->merge($config); $params = $params->toArray(); //use closure to forward connect call - Redis objects can not be analyzed for some reason by the reflection api $connect = function ($host = "localhost", $port = 6379, $timeout = 0, $persistent_id = NULL, $retry_interval = NULL, $persistent = FALSE) use($redis) { if ($persistent) { return $redis->pconnect($host, $port, $timeout, $persistent_id, $retry_interval); } else { return $redis->connect($host, $port, $timeout, $persistent_id, $retry_interval); } }; Misc::reflectionFunction($connect, $params); if (!empty($params["password"])) { $redis->auth($params["password"]); } if (!empty($params["database"])) { $redis->select((int) $params["database"]); } return $redis; }