/** * Method to show the content. * * @return mixed * @throws \Exception If not supported request method or bad controller */ public function render() { if (Sapi::isCli() && Config::get('environment') == 'production') { $suffix = 'CliAction'; $action = $this->request->fromCli()->get('action', 'index'); } else { $suffix = 'Action'; if ($this->request->getMethod() != 'GET' && $this->request->getMethod() != 'POST') { $redirectUrl = new Value($this->env->REDIRECT_URL); $redirectUrl = $redirectUrl->deleteLeading('/')->deleteTrailing('/')->explode('/'); $action = isset($redirectUrl[1]) ? $redirectUrl[1] : 'index'; } else { $bag = sprintf('from%s', ucfirst(strtolower($this->request->getMethod()))); $action = $this->request->{$bag}()->get('action', 'index'); } if (Config::get('app.routeable') === true && $this->router instanceof \Pimf\Router) { $target = $this->router->find(); if ($target instanceof \Pimf\Route\Target) { $action = $target->getAction(); Request::$getData = new Param(array_merge($target->getParams(), Request::$getData->getAll())); } } } $action = strtolower($action) . $suffix; if (method_exists($this, 'init')) { call_user_func(array($this, 'init')); } if (!method_exists($this, $action)) { throw new Bomb("no action '{$action}' defined at controller " . get_class($this)); } return call_user_func(array($this, $action)); }
/** * Method to show the content. * * @return mixed * @throws \Exception If not supported request method or bad controller */ public function render() { $conf = Registry::get('conf'); if (Sapi::isCli() && $conf['environment'] == 'production') { $suffix = 'CliAction'; $action = $this->request->fromCli()->get('action', 'index'); } else { $suffix = 'Action'; $bag = 'from' . ucfirst(strtolower($this->response->getMethod())); $action = $this->request->{$bag}()->get('action', 'index'); if ($conf['app']['routeable'] === true) { $target = Registry::get('router')->find(); if ($target instanceof \Pimf\Route\Target) { $action = $target->getAction(); Request::$getData = new Param((array) Request::stripSlashesIfMagicQuotes(array_merge($target->getParams(), Request::$getData->getAll()))); } } } $action = strtolower($action) . $suffix; if (method_exists($this, 'init')) { call_user_func(array($this, 'init')); } if (!method_exists($this, $action)) { throw new Bomb("no action '{$action}' defined at controller " . get_class($this)); } return call_user_func(array($this, $action)); }
/** * @param Request $request * @param string $repositoryPath * @param string $prefix * * @throws Resolver\Exception */ public function __construct(Request $request, $repositoryPath = '/Controller', $prefix = 'Pimf\\') { $conf = Registry::get('conf'); $controllerName = $request->fromGet()->get('controller'); if ($conf['app']['routeable'] === true) { $target = Registry::get('router')->find(); if ($target instanceof \Pimf\Route\Target) { $controllerName = $target->getController(); } } if (Sapi::isCli() && $conf['environment'] == 'production') { $controllerName = $request->fromCli()->get('controller'); } if (!$controllerName) { $controllerName = $conf['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 found at the repository path; ' . $this->controllerPath); } }