Ejemplo n.º 1
0
 public function __invoke($request, $response, $next)
 {
     $container = $this->app->getContainer();
     $settings = DotArray::newDotArray($container['settings']);
     if ($settings['app.debug'] === true) {
         // Enable PrettyPageHandler with editor options
         $prettyPageHandler = new PrettyPageHandler();
         if ($settings->has('whoops.editor')) {
             $prettyPageHandler->setEditor($settings['whoops.editor']);
         }
         // Enable JsonResponseHandler when request is AJAX
         $jsonResponseHandler = new JsonResponseHandler();
         $jsonResponseHandler->onlyForAjaxRequests(true);
         // Add more information to the PrettyPageHandler
         $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($this->app), 'Script Name' => $this->app->environment->get('SCRIPT_NAME'), 'Request URI' => $this->app->environment->get('PATH_INFO') ?: '<none>']);
         $prettyPageHandler->addDataTable('Slim Application (Request)', ['Accept Charset' => $this->app->request->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $this->app->request->getContentCharset() ?: '<none>', 'Path' => $this->app->request->getUri()->getPath(), 'Query String' => $this->app->request->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $this->app->request->getMethod(), 'Base URL' => (string) $this->app->request->getUri(), 'Scheme' => $this->app->request->getUri()->getScheme(), 'Port' => $this->app->request->getUri()->getPort(), 'Host' => $this->app->request->getUri()->getHost()]);
         $prettyPageHandler->addDataTable('SlimFastShake Settings', $settings->flatten());
         // Set Whoops to default exception handler
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($prettyPageHandler);
         $whoops->pushHandler($jsonResponseHandler);
         if (isset($container['logger'])) {
             $logger = $container['logger'];
             $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) {
                 $logger->critical('Whoops: ' . $exception->getMessage());
             });
         }
         $whoops->register();
         $container['errorHandler'] = function ($c) use($whoops) {
             return new WhoopsErrorHandler($whoops);
         };
         $container['whoops'] = $whoops;
     }
     return $next($request, $response);
 }
Ejemplo n.º 2
0
 public function testMerge()
 {
     $this->assertEquals(['this' => ['that' => 'and', 'another' => 'thing']], DotArray::merge(['this' => ['that' => 'and']], ['this' => ['another' => 'thing']]));
 }
Ejemplo n.º 3
0
 public function readConfiguration()
 {
     // Load default settings
     $settings = DotArray::newDotArray(require join(DIRECTORY_SEPARATOR, [ROOT_PATH, 'vendor', 'itguy614', 'slim-fast-shake', 'src', 'default_config.php']));
     // Load environment settings
     $envFile = join(DIRECTORY_SEPARATOR, [ROOT_PATH, '.env']);
     if (file_exists($envFile)) {
         $settings->mergeIn(parse_ini_file($envFile, true, INI_SCANNER_NORMAL));
     }
     // Load application mode settings
     $modeFile = join(DIRECTORY_SEPARATOR, [$settings['paths.config'], $settings['app.env'], 'config.php']);
     if (file_exists($modeFile)) {
         $settings->mergeIn(require $modeFile);
     }
     return $settings;
 }