Ejemplo n.º 1
0
 public function execute(ActionMapping $mapping, AbstractActionForm $form = null, Request $request, Response $response)
 {
     // Identify the request parameters controlling our actions
     $page = $request->get("page");
     $prefix = $request->get("prefix");
     if ($page == null || $prefix == null) {
         $message = $this->getActionKernel()->getInternal()->getMessage("switch.required", $mapping->getPath());
         throw new \Phruts\Exception($message);
     }
     // Switch to the requested module
     \Phruts\Util\RequestUtils::selectModule($request, $this->getActionKernel()->getApplication());
     if ($request->attributes->get(\Phruts\Util\Globals::MODULE_KEY) == null) {
         $message = $this->getActionKernel()->getInternal()->getMessage("switch.prefix", $prefix);
         $response->setContent(400);
         $response->setContent($message);
         return null;
     }
     // Forward control to the specified module-relative URI
     $forward = new \Phruts\Config\ForwardConfig();
     $forward->setPath($page);
     return $forward;
 }
Ejemplo n.º 2
0
 /**
  * Return a Action instance that will be used to process the current
  * request, creating a new one if necessary.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The kernel request we are
  * processing
  * @param \Symfony\Component\HttpFoundation\Response $response The kernel response we are
  * creating
  * @param \Phruts\Action\ActionMapping $mapping The mapping we are using
  * @return \Phruts\Config\ForwardConfig
  */
 protected function processActionCreate(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response, \Phruts\Action\ActionMapping $mapping)
 {
     // Acquire the Action instance we will be using (if there is one)
     $className = $mapping->getType();
     if (!empty($this->log)) {
         $this->log->debug('  Looking for Action instance for class ' . $className);
     }
     $instance = null;
     // Return any existing Action instance of this class
     if (array_key_exists($className, $this->actions)) {
         $instance = $this->actions[$className];
     }
     if (!is_null($instance)) {
         if (!empty($this->log)) {
             $this->log->debug('  Returning existing Action instance');
         }
         return $instance;
     }
     // Create an return a new Action instance
     if (!empty($this->log)) {
         $this->log->debug('  Creating new Action instance');
     }
     try {
         $instance = \Phruts\Util\ClassLoader::newInstance($className, '\\Phruts\\Action\\Action');
     } catch (\Exception $e) {
         $msg = $this->getInternal()->getMessage(null, 'actionCreate', $mapping->getPath());
         if (!empty($this->log)) {
             $this->log->error($msg . ' - ' . $e->getMessage());
         }
         throw new HttpException(500, $msg);
     }
     $instance->setActionKernel($this->actionKernel);
     $this->actions[$className] = $instance;
     return $instance;
 }
Ejemplo n.º 3
0
 /**
  * Method which is dispatched to when there is no value for specified
  * request parameter included in the request.  Subclasses of
  * <code>DispatchAction</code> should override this method if they wish
  * to provide default behavior different than producing an HTTP
  * "Bad Request" error.
  *
  */
 protected function unspecified(ActionMapping $mapping, AbstractActionForm $form = null, Request $request, Response $response)
 {
     $message = $this->getActionKernel()->getInternal()->getMessage("dispatch.parameter", $mapping->getPath(), $mapping->getParameter());
     $response->setStatusCode(400);
     $response->setContent($message);
     return null;
 }