Exemplo n.º 1
0
 /**
  * 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));
 }
Exemplo n.º 2
0
 /**
  * @param Environment   $env
  * @param Logger        $logger
  * @param EntityManager $em
  *
  * @return \Pimf\Controller\Base
  * @throws \Pimf\Resolver\Exception If no controller specified or no controller found at the repository.
  */
 public function process(Environment $env, $em, Logger $logger)
 {
     $path = str_replace($this->repositoryPath, '', $this->controllerPath);
     $name = str_replace('/', $this->controllerClass, $path);
     $controller = str_replace('.php', '', $name);
     if (!class_exists($controller)) {
         throw new Bomb('can not load class "' . $controller . '" from the repository');
     }
     return new $controller($this->request, new Response($this->request->getMethod()), $logger, $em, $this->router, $env);
 }