public function __invoke() { $tz = Config::get('kernel.timezone'); if (ini_get('date.timezone') !== $tz) { date_default_timezone_set($tz); } $this->logger->info(sprintf('The application [%s] has started', (string) $this->name), ['event' => 'app.start']); }
/** * Adds a log record at an arbitrary level. * * This method allows for compatibility with common interfaces. * * @param mixed $level The log level * @param string $message The log message * @param array $context The log context * @return bool */ public function log($level = Logger::DEBUG, $message, array $context = []) { $level = static::nameToLevel($level); if (Config::get('kernel.environment.' . Kernel::env() . '.logging') == false) { // Logging is disabled for this environment return false; } return $this->getLogger()->addRecord($level, $message, $context); }
/** * Parses the content of this view * * @param array $data Additional data to be parsed as variables * @param bool $return Should the parsed view be returned as a string? * @return mixed */ public function parse(array $data = [], $return = false) { // Some pre-defined variables accessible inside the template $this->data['appname'] = Config::get('site.name'); $url = Config::get('site.url'); $this->data['appurl'] = Config::get('site.https') ? 'https://' . $url : 'http://' . $url; $this->data['description'] += Config::get('site.description'); $this->data['keywords'] += Config::get('site.keywords'); $this->data['render_time'] = Benchmark::time('start'); $this->data['memory_usage'] = Benchmark::memory('start'); $this->parsedContent = $this->parser->render($this->template, array_merge($data, $this->data)); $this->hasBeenParsed = true; if ($return) { return $this->getParsedView(); } }
/** * Handles the available processors and pushes them to the Monolog\Logger instance * * @return void */ protected function pushProcessors() { foreach (Config::get('kernel.logs.processors') as $processor) { if (!$processor || $processor == 'none') { continue; } $class = 'Monolog\\Processor\\' . $processor; $this->getLogger()->pushProcessor(new $class()); } // This processor is a fix for the original Monolog\Processor\IntrospectionProcessor $this->getLogger()->pushProcessor(new IntrospectionProcessor()); }
/** * Bootstrap the application by filling all the needed variables and RUN! * * @param array $args Argument array from CLI * @return void */ public function run(array $args = []) { $container = (require path('configs') . 'dependencies.php'); $this->slim =& new App($container); $this->logger['kernel'] = new Logger(Logger::CHANNEL_KERNEL); $this->logger['slim'] = new Logger(Logger::CHANNEL_SLIM); // ExHan if (static::env() == static::DEVELOPMENT) { $this->slim->add(new ExHanMiddleware()); } else { $this->slim->add(new ServerErrorMiddleware()); } $this->registerEvents(); //require path('configs') . 'events.php'; $this->emitter->emit('app.start'); // Defines the middleware from here. // Just a workaround... $config = new SessionConfig(['name' => Config::get('kernel.session.name', 'session'), 'autorefresh' => Config::get('kernel.session.autorefresh', false), 'lifetime' => Config::get('kernel.session.lifetime', '1 hour')]); $this->session = new Handler($config); $this->cookies = new CookieJar(); $middlewares = (require path('configs') . 'middlewares.php'); foreach ($middlewares as $middleware) { $this->slim->add($middleware); $this->emitter->emit('app.middleware.load', [$middleware]); } require path('configs') . 'routes.php'; $this->slim->run(); $this->emitter->emit('app.finish'); }