Esempio n. 1
0
 public function __invoke($redirect, $redirectToUrl = false)
 {
     $controller = $this->getController();
     $request = $controller->getRequest();
     $container = new Container('prg_post1');
     if ($request->isPost()) {
         $container->setExpirationHops(1, 'post');
         $container->post = $request->getPost()->toArray();
         if (method_exists($controller, 'getPluginManager')) {
             // get the redirect plugin from the plugin manager
             $redirector = $controller->getPluginManager()->get('Redirect');
         } else {
             /*
              * if the user wants to redirect to a route, the redirector has to come
              * from the plugin manager -- otherwise no router will be injected
              */
             if ($redirectToUrl === false) {
                 throw new RuntimeException('Could not redirect to a route without a router');
             }
             $redirector = new Redirect();
         }
         if ($redirectToUrl === false) {
             return $redirector->toRoute($redirect);
         }
         return $redirector->toUrl($redirect);
     } else {
         if ($container->post !== null) {
             $post = $container->post;
             unset($container->post);
             return $post;
         }
         return false;
     }
 }
Esempio n. 2
0
 public function createAction(PageViewModel $view, array $params, ServiceCreate $createService, Redirect $redirect)
 {
     $page = $createService->create($params);
     if (!$page) {
         $view->setFormData($params);
         $view->setErrors($createService->getErrors());
         return $view;
     }
     return $redirect->toRoute('admin-pages-list');
 }
Esempio n. 3
0
 public function toRoute($route = null, $params = array(), $options = array(), $reuseMatchedParams = false)
 {
     $controller = $this->getController();
     $paramsPlugin = $controller->plugin('params');
     $lang = $paramsPlugin->fromRoute('lang');
     if ($lang) {
         $params['lang'] = $lang;
     }
     return parent::toRoute($route, $params, $options, $reuseMatchedParams);
 }
Esempio n. 4
0
 /**
  * Generates a URL based on a route
  *
  * @param string $route      RouteInterface name
  * @param array  $params     Parameters to use in url generation
  * @param array  $options    RouteInterface-specific options
  * @param bool   $reuseMatchedParams
  *
  * @return Response
  */
 public function toRoute($route = null, array $params = array(), $options = array(), $reuseMatchedParams = false)
 {
     $this->controller->view()->setTemplate(false);
     $response = parent::toRoute($route, $params, $options, $reuseMatchedParams);
     if ($this->responseCode) {
         $response->setStatusCode($this->responseCode);
         $this->responseCode = null;
     }
     $response->send();
     return $response;
 }
Esempio n. 5
0
 /**
  * TODO: Good candidate for traits method in PHP 5.4 with PostRedirectGet plugin
  *
  * @param  string  $redirect
  * @param  bool    $redirectToUrl
  * @return Response
  * @throws \Zend\Mvc\Exception\RuntimeException
  */
 protected function redirect($redirect, $redirectToUrl)
 {
     $controller = $this->getController();
     $params = array();
     $options = array();
     $reuseMatchedParams = false;
     if (null === $redirect) {
         $routeMatch = $controller->getEvent()->getRouteMatch();
         $redirect = $routeMatch->getMatchedRouteName();
         //null indicates to redirect for self.
         $reuseMatchedParams = true;
     }
     if (method_exists($controller, 'getPluginManager')) {
         // get the redirect plugin from the plugin manager
         $redirector = $controller->getPluginManager()->get('Redirect');
     } else {
         /*
          * If the user wants to redirect to a route, the redirector has to come
          * from the plugin manager -- otherwise no router will be injected
          */
         if ($redirectToUrl === false) {
             throw new RuntimeException('Could not redirect to a route without a router');
         }
         $redirector = new Redirect();
     }
     if ($redirectToUrl === false) {
         $response = $redirector->toRoute($redirect, $params, $options, $reuseMatchedParams);
         $response->setStatusCode(303);
         return $response;
     }
     $response = $redirector->toUrl($redirect);
     $response->setStatusCode(303);
     return $response;
 }
Esempio n. 6
0
 public function testPluginWithoutControllerRaisesDomainException()
 {
     $plugin = new RedirectPlugin();
     $this->setExpectedException('Zend\\Mvc\\Exception\\DomainException', 'requires a controller');
     $plugin->toRoute('home');
 }
Esempio n. 7
0
 public function deleteAction(Request $request, Params $params, Delete $deleteService, Redirect $redirect)
 {
     $deleteService->delete((int) $params('id'));
     return $redirect->toRoute('admin-translate-words', [], ['query' => $request->getQuery()->toArray()]);
 }