pushHandler(new PrettyPageHandler); $whoops->register(); } $locator = new FileLocator(__DIR__ . '/../'); $loader = new YamlFileLoader($locator); $collection = $loader->load('routes.yml'); $context = new RequestContext(); $request = Request::createFromGlobals(); $context->fromRequest($request); $matcher = new UrlMatcher($collection, $context); try { $parameters = $matcher->match($context->getPathInfo()); if (isset($whoops) && $whoops instanceof \Whoops\Run) { if (isset($parameters)) { foreach ($whoops->getHandlers() as $handler) { if ($handler instanceof PrettyPageHandler) { $handler->addDataTable('Parameters', $parameters); } } } } if (!class_exists($parameters['_controller'])) { throw new \Exception('Class "' . $parameters['_controller'] . '" does not exist.'); } $class = new $parameters['_controller']; if (!$class instanceof BaseController) { throw new \BadMethodCallException('Class must be an instance of \QBNK\Frontend\ViewController'); } else if (!method_exists($class, $parameters['_method'])) { throw new \BadMethodCallException('Method "' . $parameters['_method'] . '" does not exist in class "' . $parameters['_controller'] .'".'); } $generator = new UrlGenerator($collection, $context); $class->setUrlGenerator($generator); $class->$parameters['_method']($parameters, $request); } catch (ResourceNotFoundException $rnfe) { header('HTTP/1.1 404 Not Found'); echo '

404 File not found

'; if (DEBUG) { throw $rnfe; } } catch (\Exception $e) { header('HTTP/1.1 500 Internal Server Error'); echo '

500 Internal server error

'; if (DEBUG || $_SERVER['REMOTE_ADDR'] == '213.136.36.90') { var_dump($e); throw $e; } error_log($e->getMessage()); }