Ejemplo n.º 1
0
 /**
  * @param Request      $request
  * @param string       $repositoryPath
  * @param string       $prefix
  * @param \Pimf\Router $router
  *
  * @throws \Pimf\Resolver\Exception If no controller found at the repository path
  */
 public function __construct(\Pimf\Request $request, $repositoryPath = '/Controller', $prefix = 'Pimf\\', $router)
 {
     $controllerName = $request->fromGet()->get('controller');
     $this->router = $router;
     if (Config::get('app.routeable') === true) {
         $target = $this->router->find();
         if ($target instanceof \Pimf\Route\Target) {
             $controllerName = $target->getController();
         }
     }
     if (Sapi::isCli() && Config::get('environment') == 'production') {
         $controllerName = $request->fromCli()->get('controller');
     }
     if (!$controllerName) {
         $controllerName = Config::get('app.default_controller');
     }
     $this->repositoryPath = $repositoryPath;
     $this->request = $request;
     $this->controllerClass = $prefix . 'Controller\\';
     $basepath = $this->repositoryPath . '/';
     $controller = ucfirst($controllerName);
     if (Str::isEvilPath($basepath . $controller)) {
         throw new Bomb('directory traversal attack is not funny!');
     }
     $this->controllerPath = $basepath . $controller . '.php';
     if (!file_exists($this->controllerPath)) {
         throw new Bomb('no "' . $controller . '" controller found at the repository path');
     }
 }