public function __construct($message = \null, $code = \null, $previous = \null) { parent::__construct($message, $code, $previous); if (static::$logger !== \null) { static::$logger->log(LogLevel::ALERT, $message, array('code' => $this->getCode(), 'message' => $this->getMessage(), 'file' => $this->getFile(), 'line' => $this->getLine(), 'type' => 'exceptions')); } }
/** * @return \Micro\Application\Application */ public function registerDefaultServices() { if (!isset($this['request'])) { $this['request'] = function () { return new Http\Request(); }; } if (!isset($this['response'])) { $this['response'] = function () { return new Http\Response\HtmlResponse(); }; } if (!isset($this['event'])) { $this['event'] = function () { return new Event\Manager(); }; } if (!isset($this['exception.handler'])) { $this['exception.handler'] = function ($app) { return $app; }; } if (!isset($this['exception.handler.fallback'])) { $this['exception.handler.fallback'] = function ($app) { return $app; }; } if (!isset($this['acl'])) { $this['acl'] = function ($app) { if ($app->get('config')->get('acl.enabled', 1)) { return new Acl(); } return \null; }; } if (!isset($this['caches'])) { $this['caches'] = function ($app) { $adapters = $app['config']->get('cache.adapters', []); $caches = []; foreach ($adapters as $adapter => $config) { $caches[$adapter] = Cache::factory($config['frontend']['adapter'], $config['backend']['adapter'], $config['frontend']['options'], $config['backend']['options']); } return $caches; }; } if (!isset($this['cache'])) { $this['cache'] = function ($app) { $adapters = $app->get('caches'); $default = (string) $app['config']->get('cache.default'); return isset($adapters[$default]) ? $adapters[$default] : \null; }; } /** * Create router with routes */ if (!isset($this['router'])) { $this['router'] = function ($app) { return new Router($app['request']); }; } /** * Create default db adapter */ if (!isset($this['db'])) { $this['db'] = function ($app) { $default = $app['config']->get('db.default'); $adapters = $app['config']->get('db.adapters', []); if (!isset($adapters[$default])) { return \null; } $db = Database::factory($adapters[$default]['adapter'], $adapters[$default]); TableAbstract::setDefaultAdapter($db); TableAbstract::setDefaultMetadataCache($app['cache']); return $db; }; } /** * Create default translator */ if (!isset($this['translator'])) { $this['translator'] = function ($app) { return new Translator(); }; } /** * Register session config */ $sessionConfig = $this['config']->get('session', []); if (!empty($sessionConfig)) { Session::register($sessionConfig); } CoreLog::register(); CoreException::register(); return $this; }
public static function exceptionHandler(\Exception $e) { Log::write('(' . (int) $e->getCode() . ') ' . strip_tags($e->getMessage()) . ' - ' . $_SERVER['REMOTE_ADDR'] . ' - ' . $_SERVER['REQUEST_URI'], 'exceptions'); }
public function registerServices() { $config = $this->container->get('config'); $this->container->set('request', function () { return Request::createFromEnvironment(); }, \false); $this->container->set('response', function () { return new HtmlResponse(); }, \false); $this->container->set('router', function () { return new Router(); }, \false); $this->container->set('event', function () { return new Event\Manager(); }, \false); $this->container->set('logger', function () use($config) { return new FileLog($config->get('log')); }, \false); if ($config->get('log.enabled')) { $logger = $this->container->get('logger'); ErrorHandler::register($logger); CoreException::setLogger($logger); } $this->container->setBindings($this, ['resolver' => 'registerResolverBinder', 'exception.handler' => 'registerExceptionBinder', 'translator' => 'registerTranslatorBinder', 'caches' => 'registerCacheBinder', 'cache' => 'registerCacheBinder', 'acl' => 'registerAclBinder', 'db' => 'registerDbBinder']); }