static function create($options) { $options = Hash::create($options, Hash::OPT_DEFAULT | Hash::OPT_ALLOW_UNDEFINED_KEY_GET | Hash::OPT_IGNORE_CASE); // フォーマット $class = sprintf('Nora\\System\\Logging\\Logger\\Formatter\\%sFormatter', ucfirst($options->getVal('type', 'string'))); return new $class($options); }
public function __construct($settings, $context) { $this->_loggers = Hash::create([], Hash::OPT_DEFAULT | Hash::OPT_IGNORE_CASE); foreach ($settings as $k => $v) { $this->setup($k, $v, $context); } }
public function testHash() { $hash = Hash::create(['a' => 1, 'b' => 2, 'C' => 3], Hash::OPT_SECURE | Hash::OPT_IGNORE_CASE); $this->assertTrue($hash->hasVal("c")); $hash->setVal("xx", "4"); $this->assertTrue($hash->hasVal("xx")); $this->assertEquals($hash->getVal("xX"), "4"); }
public static function create($spec) { if (is_object($spec) && !$spec instanceof ServiceSpec) { return new ServiceSpecObject($spec); } $opt = Hash::create($spec, Hash::OPT_IGNORE_CASE | Hash::OPT_ALLOW_UNDEFINED_KEY_GET); return new static($opt); }
public static function init() { $context = new static(); $context->_ENV = Hash::create($_ENV, Hash::OPT_ALLOW_ALL | Hash::OPT_IGNORE_CASE); $context->_GET = Hash::create($_GET, Hash::OPT_ALLOW_ALL | Hash::OPT_IGNORE_CASE); $context->_POST = Hash::create($_POST, Hash::OPT_ALLOW_ALL | Hash::OPT_IGNORE_CASE); $context->_COOKIE = Hash::create($_COOKIE, Hash::OPT_ALLOW_ALL | Hash::OPT_IGNORE_CASE); $context->setVal(['cache' => '/tmp']); return $context; }
/** * ロガーをビルドアップする */ public static function build($options) { $options = Hash::create($options, Hash::OPT_ALLOW_UNDEFINED_KEY_GET); $logger = self::create($options->getVal('name', 'Nora')); foreach ($options->getVal('handlers', []) as $h) { $logger->addHandler(Handler::create($h)); } if ($options->getVal('withPHPError', false)) { // ハンドラ系の登録 set_error_handler([$logger, 'phpErrorHandler']); set_exception_handler([$logger, 'phpExceptionHandler']); register_shutdown_function([$logger, 'phpShutdownHandler']); } if ($options->getVal('asMainLogger', false)) { Nora::setLogger($logger); } return $logger; }
/** * パスをフォーマットする */ public static function format($str) { static $data = false; if ($data === false) { $data['user'] = function ($params) { static $user = false; if ($user === false) { $user = posix_getpwuid(posix_getuid())['name']; } return $user; }; $data['time'] = function ($params) { $opt = Hash::create($params, Hash::OPT_ALLOW_UNDEFINED_KEY_GET); $format = $opt->getVal(0, 'Y-m-d G:i:s'); return date($format, time()); }; } return Formatter::format($str, $data); }
static function create($options) { $options = Hash::create($options, Hash::OPT_DEFAULT | Hash::OPT_ALLOW_UNDEFINED_KEY_GET | Hash::OPT_IGNORE_CASE); // ハンドラクラス名を作成 if (false === ($class = $options->getVal('class', false))) { $type = $options->getVal('type', 'echo'); $class = sprintf('Nora\\System\\Logging\\Logger\\Handler\\%sHandler', ucfirst($type)); } $handler = new $class($options); // レベルが設定されていたらレベルフィルターを仕込む if ($options->hasVal('level')) { $handler->addFilter(Filter::create(['level' => $options->getVal('level')])); } // フォーマッタが指定されていたら if ($options->hasVal('formatter')) { $formatter->setFormatter(Formatter::create($options->getVal('formatter'))); } // プロセッサが指定されていたら foreach ($options->getVal('processer', []) as $p) { $handler->addProceccer($p); } return $handler; }
public function __construct($services = []) { $this->_specs = Hash::create([], Hash::OPT_STRICT | Hash::OPT_IGNORE_CASE | Hash::OPT_ALLOW_UNDEFINED_KEY_SET); $this->_cache = Hash::create([], Hash::OPT_STRICT | Hash::OPT_IGNORE_CASE | Hash::OPT_ALLOW_UNDEFINED_KEY_SET); $this->set($services); }
public static function hash($data = [], $options = Hash::OPT_DEFAULT) { return Hash::create($data, $options); }
public function __construct() { $this->_matched = Hash::create([], Hash::OPT_ALLOW_UNDEFINED_KEY_SET | Hash::OPT_ALLOW_UNDEFINED_KEY_GET); }
private function formatTime(Log $log, $params) { $opt = Hash::create($params, Hash::OPT_ALLOW_UNDEFINED_KEY_GET); $format = $opt->getVal(0, 'Y-m-d G:i:s'); return date($format, $log->getTime()); }