/** * @todo needs lots of love * * @param string $name * @param string $type * @throws \Exception * @return string */ public static function locate($name, $type = null) { if (strpos($name, '\\') && class_exists($name)) { return $name; } $type = $type ? strtolower($type) : $type; $params = compact('name', 'type'); return static::filterStaticMethod(__FUNCTION__, $params, function ($self, $params) { extract($params); if (isset($type, $self::$classPaths[$type])) { foreach ($self::$classPaths[$type] as $path) { $app = Config::get('app.namespace'); $namespaces = array_merge([$app], $self::$namespaces, [__NAMESPACE__]); foreach ($namespaces as $namespace) { $classPath = "{$namespace}\\{$path}\\{$name}"; if (class_exists($classPath)) { return $classPath; } } } } }); $message = sprintf("Class '%s' of type '%s' not found.", $name, $type); throw new \Exception($message); }
public function renderException($self, $params, $chain) { if (ob_get_length()) { ob_end_clean(); } extract($params); $request = end(Action::$requests) ?: Action::request(); $response = Action::response(); if (!Config::get('debug')) { if ($exception instanceof ActionException) { $response->status = $exception->getStatus(); } } $errorController = new Controller($request, $response); $errorController->overload('error', function ($self) { return $self->render(); }); $view = ['view' => Config::get('debug') ? 'debug_exception' : 'error', 'view_path' => 'Error']; $data = compact('exception'); echo $errorController('error', $data, $view); $params['exit'] = true; return $chain->next($self, $params, $chain); }