Frontend\Core\Engine\AjaxAction::execute PHP Method

execute() public method

We will build the class name, require the class and call the execute method
public execute ( )
    public function execute()
    {
        // build action-class-name
        $actionClass = 'Frontend\\Modules\\' . $this->getModule() . '\\Ajax\\' . $this->getAction();
        if ($this->getModule() == 'Core') {
            $actionClass = 'Frontend\\Core\\Ajax\\' . $this->getAction();
        }
        // build the path (core is a special case)
        if ($this->getModule() == 'Core') {
            $path = FRONTEND_PATH . '/Core/Ajax/' . $this->getAction() . '.php';
        } else {
            $path = FRONTEND_PATH . '/Modules/' . $this->getModule() . '/Ajax/' . $this->getAction() . '.php';
        }
        // check if the config is present? If it isn't present there is a huge
        // problem, so we will stop our code by throwing an error
        if (!is_file($path)) {
            throw new Exception('The action file (' . $path . ') can\'t be found.');
        }
        // validate if class exists
        if (!class_exists($actionClass)) {
            throw new Exception('The action file ' . $actionClass . ' could not be found.');
        }
        // create action-object
        $object = new $actionClass($this->getKernel(), $this->getAction(), $this->getModule());
        // validate if the execute-method is callable
        if (!is_callable(array($object, 'execute'))) {
            throw new Exception('The action file should contain a callable method "execute".');
        }
        // call the execute method of the real action (defined in the module)
        $object->execute();
        return $object->getContent();
    }

Usage Example

コード例 #1
0
ファイル: Ajax.php プロジェクト: forkcms/forkcms
 /**
  * This method exists because the service container needs to be set before
  * the request's functionality gets loaded.
  */
 public function initialize()
 {
     $request = $this->getContainer()->get('request');
     // get vars
     if ($request->request->has('fork')) {
         $post = $request->request->get('fork');
         $module = isset($post['module']) ? $post['module'] : '';
         $action = isset($post['action']) ? $post['action'] : '';
         $language = isset($post['language']) ? $post['language'] : '';
     } else {
         $module = $request->query->get('module');
         $action = $request->query->get('action');
         $language = $request->query->get('language');
     }
     if ($language == '') {
         $language = SITE_DEFAULT_LANGUAGE;
     }
     try {
         $this->setModule($module);
         $this->setAction($action);
         $this->setLanguage($language);
         if (extension_loaded('newrelic')) {
             newrelic_name_transaction('ajax::' . $module . '::' . $action);
         }
         $this->ajaxAction = new AjaxAction($this->getKernel(), $this->getAction(), $this->getModule());
         $this->output = $this->ajaxAction->execute();
     } catch (InvalidArgumentException $e) {
         $message = Model::getContainer()->getParameter('fork.debug_message');
         $this->ajaxAction = new FrontendBaseAJAXAction($this->getKernel(), '', '');
         $this->ajaxAction->output(FrontendBaseAJAXAction::ERROR, null, $message);
         $this->output = $this->ajaxAction->execute();
     } catch (Exception $e) {
         if (Model::getContainer()->getParameter('kernel.debug')) {
             $message = $e->getMessage();
         } else {
             $message = Model::getContainer()->getParameter('fork.debug_message');
         }
         $this->ajaxAction = new FrontendBaseAJAXAction($this->getKernel(), '', '');
         $this->ajaxAction->output(FrontendBaseAJAXAction::ERROR, null, $message);
         $this->output = $this->ajaxAction->execute();
     }
 }
All Usage Examples Of Frontend\Core\Engine\AjaxAction::execute