Esempio n. 1
0
 /**
  * Bootstrap the application.
  */
 protected function bootstrap()
 {
     // Read all config files
     $config = new Repository($this->loadConfigFiles());
     // Register the configuration instance for later use.
     // Note that Slim framework already used a service key named 'settings' for
     // accessing the framework settings. Here, we will use a separate key for
     // the application configurations. If you want to reuse the service key,
     // you should merge the framework settings with the application configurations.
     $container = $this->getContainer();
     $container['config'] = function () use($config) {
         return $config;
     };
     date_default_timezone_set($config['app.timezone']);
     mb_internal_encoding('UTF-8');
     // Register route handler strategy
     $container['foundHandler'] = function () {
         return new \Slim\Handlers\Strategies\RequestResponseArgs();
     };
     // Register a logger used in the application
     $container['logger'] = function () use($container) {
         $logger = new \Monolog\Logger('logger');
         $logger->pushProcessor(new \Monolog\Processor\WebProcessor());
         $logger->pushHandler(new \Monolog\Handler\StreamHandler($container['path.storage'] . 'logs' . DIRECTORY_SEPARATOR . 'error.log'));
         return $logger;
     };
     // Register 500 System Error handler
     $container['errorHandler'] = function () use($container) {
         $errorHandler = new \Core\Handlers\Error($container['config']['app.debug']);
         if (isset($container['logger'])) {
             $errorHandler->setLogger($container['logger']);
         }
         return $errorHandler;
     };
     // Register 404 Not Found handler
     $container['notFoundHandler'] = function () {
         return new \Core\Handlers\NotFound();
     };
     // Register 405 Method Not Allowed handler
     $container['notAllowedHandler'] = function () {
         return new \Core\Handlers\NotAllowed();
     };
     // Register the specified providers.
     $providers = $config['app.providers'];
     foreach ($providers as $provider) {
         $container->register(new $provider());
     }
     // Register facades which are shortcuts
     // for accessing registered services.
     Facade::setContainer($container);
 }