Ejemplo n.º 1
0
 /**
  * @param array $config
  * @return MvcDispatcher
  */
 public static function createMvcFrom(array $config) : MvcDispatcher
 {
     $dispatcher = new MvcDispatcher();
     $dispatcher->setEventsManager(new EventManager());
     $dispatcher->setControllerSuffix(null);
     $dispatcher->setDefaultNamespace($config['controllerDefaultNamespace']);
     $dispatcher->getEventsManager()->attach('dispatch:afterDispatchLoop', function (Event $event, MvcDispatcher $dispatcher) {
         if ($dispatcher->getReturnedValue() instanceof \Phalcon\Http\Response) {
             $dispatcher->getDI()->setShared('response', $dispatcher->getReturnedValue());
         }
     });
     return $dispatcher;
 }
Ejemplo n.º 2
0
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     if ($this->_isJsonResponse) {
         $data = $dispatcher->getReturnedValue();
         $this->response->setJsonContent($data);
         $this->response->send();
     }
 }
Ejemplo n.º 3
0
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     sleep(2);
     $data = $dispatcher->getReturnedValue();
     $responseData = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
     $this->response->setContent($responseData);
     return $this->response->send();
 }
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     $this->view->disable();
     $data = $dispatcher->getReturnedValue();
     if (is_array($data)) {
         $data = json_encode($data);
     }
     $this->response->setContentType('application/json', 'UTF-8');
     $this->response->setContent($data);
     $this->response->send();
 }
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     if ($this->_isJsonResponse) {
         $data = $dispatcher->getReturnedValue();
         if (is_array($data)) {
             $data = json_encode($data);
         }
         $this->response->setContent($data);
         $this->response->send();
     }
 }
Ejemplo n.º 6
0
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     $data = $dispatcher->getReturnedValue();
     if ($this->restful) {
         if (is_array($data)) {
             $data = json_encode($data, JSON_UNESCAPED_UNICODE);
         }
     }
     $this->response->setContent($data);
     $this->response->send();
 }
 /**
  * After route executed event
  *
  * @param Dispatcher $dispatcher
  */
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     $data = $dispatcher->getReturnedValue();
     if (is_array($data)) {
         $this->response->setJsonContent($data, JSON_UNESCAPED_UNICODE);
     } elseif (is_scalar($data)) {
         $this->response->setContent($data);
     }
     $this->response->send();
     exit;
 }
Ejemplo n.º 8
0
 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Model\ModelsRepository $modelsRepository */
     $modelsRepository = $dispatcher->getDI()->getService('modelsRepository')->resolve();
     if (!$modelsRepository) {
         return;
     }
     $returnedValue = $dispatcher->getReturnedValue();
     if (is_null($returnedValue)) {
         $returnedValue = [];
     }
     $modelsRepository->getPageContent()->processContent($dispatcher->getParams(), $returnedValue);
 }
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     $this->view->disable();
     $data = $dispatcher->getReturnedValue();
     if (is_array($data) and array_key_exists('success', $data) and $data['success'] === false) {
         $this->setBadRequestStatus();
     }
     if (is_array($data)) {
         $data = json_encode($data);
     }
     $this->response->setContentType('application/json', 'UTF-8');
     $this->response->setContent($data);
     $this->response->send();
     // TODO bug fix
     exit;
 }
Ejemplo n.º 10
0
 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Phalcon\Mvc\View $view */
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $returnedValue = $dispatcher->getReturnedValue();
     if ($returnedValue instanceof \Phalcon\Http\Response) {
         return false;
     }
     if (is_array($view->getParamsToView()) && array_key_exists(self::SET_JSON_RESPONSE, $view->getParamsToView())) {
         $view->disable();
         header('Content-type: application/json');
         echo json_encode($returnedValue);
         return false;
     }
     if (is_array($returnedValue)) {
         $view->setVars($returnedValue);
     }
 }
Ejemplo n.º 11
0
 /**
  * After execute route event
  *
  * @param Dispatcher $dispatcher
  */
 public function afterExecuteRoute(Dispatcher $dispatcher)
 {
     if ($this->request->isAjax() && $this->isJsonResponse()) {
         $this->view->disable();
         $this->response->setContentType('application/json', 'UTF-8');
         $data = $dispatcher->getReturnedValue();
         if (is_array($data)) {
             $this->response->setJsonContent($data);
         }
         echo $this->response->getContent();
     }
     $this->view->setViewsDir($this->view->getViewsDir() . 'admin/');
 }
Ejemplo n.º 12
0
 public function afterExecuteRoute(\Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $this->setJsonContent($dispatcher->getReturnedValue());
 }
 public function afterDispatchLoop(Event $event, Dispatcher $dispatcher)
 {
     $di = $this->getDI();
     $response = $di->get('response');
     $content = $response->getContent();
     if ($content === '' && $dispatcher->getActiveController() instanceof RestControllerInterface) {
         $returnedResponse = $dispatcher->getReturnedValue() instanceof ResponseInterface;
         if ($returnedResponse === false) {
             /** @var \PhalconRest\Mvc\RestView $rest */
             $rest = $di->get('rest');
             /** @var Manager $eventsManager */
             $eventsManager = $this->_eventsManager;
             //$eventsManager = $dispatcher->getDI()->get('eventsManager');
             $renderStatus = true;
             if ($eventsManager instanceof ManagerInterface) {
                 $renderStatus = $eventsManager->fire('application:viewRender', $this, $rest);
             }
             if ($renderStatus) {
                 $rest->render($dispatcher->getControllerName(), $dispatcher->getActionName());
                 $content = $rest->getContent();
             }
             /** @var \Phalcon\Http\Response $response */
             $response = $di->get('response');
             $response->setContent($content)->send();
         }
     }
 }
Ejemplo n.º 14
0
 /**
  *
  * @param Event $event
  * @param Dispatcher $dispatcher
  */
 public function afterDispatch(Event $event, Dispatcher $dispatcher)
 {
     $result = $dispatcher->getReturnedValue();
     ResponseApi::sendOk($result);
 }