/**
  * Creates new response
  * @param string $template The name of the template
  * @param array $data An associative array of the data
  * @param string $filter Filter name
  * @return Rsc_Http_Response
  */
 public function response($template, array $data = array(), $filter = null)
 {
     $request = $this->getRequest();
     $dispatcher = $this->getEnvironment()->getDispatcher();
     if (null === $filter) {
         $filter = '@';
         if ($request->post->has('route')) {
             $route = $request->post->get('route');
             $filter .= $route['module'] . '/';
             if (!array_key_exists('action', $route)) {
                 $route['action'] = 'index';
             }
             $filter .= $route['action'];
         } else {
             $filter .= $request->query->get('module', $this->getEnvironment()->getConfig()->get('default_module')) . '/';
             $filter .= $request->query->get('action', 'index');
         }
     }
     $data = $dispatcher->apply($filter, array($data));
     if ($template !== Rsc_Http_Response::AJAX) {
         try {
             $twig = $this->getEnvironment()->getTwig();
             $content = $twig->render($template, $data);
         } catch (Exception $e) {
             wp_die($e->getMessage());
         }
     } else {
         wp_send_json($data);
     }
     return Rsc_Http_Response::create()->setContent($content);
 }
 /**
  * Makes redirects to the specified URL
  * @param string $url
  * @return \Rsc_Http_Response
  */
 public function redirect($url)
 {
     if (!headers_sent()) {
         header(sprintf('Location: %s', $url));
         exit;
     }
     $content = "<script type=\"text/javascript\">document.location.href = '{$url}'</script>";
     return Rsc_Http_Response::create()->setContent($content);
 }
Example #3
0
 public function handle()
 {
     $action = $this->request->query->get('action', 'index') . 'Action';
     if (method_exists($this->getController(), $action)) {
         return call_user_func_array(array($this->getController(), $action), array($this->request));
     }
     $twig = $this->environment->getTwig();
     return Rsc_Http_Response::create()->setContent($twig->render('404.twig'));
 }
 public function handle()
 {
     $action = $this->request->query->get('action', 'index') . 'Action';
     $welcomePageShowed = $this->environment->getConfig()->get('welcome_page_was_showed');
     $promoController = $this->environment->getConfig()->get('promo_controller');
     if ($promoController && class_exists($promoController) && !$welcomePageShowed) {
         $promoController = new $promoController($this->environment, $this->request);
         if (method_exists($promoController, 'indexAction')) {
             return call_user_func_array(array($promoController, 'indexAction'), array($this->request));
         }
     } else {
         if (method_exists($this->getController(), $action)) {
             return call_user_func_array(array($this->getController(), $action), array($this->request));
         }
     }
     $twig = $this->environment->getTwig();
     return Rsc_Http_Response::create()->setContent($twig->render('404.twig'));
 }