Example #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;
     }
 }
Example #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');
 }
 /**
  * Redirect with Handling against url.
  *
  * @param string $url
  *
  * @return Response
  */
 public function toUrl($url)
 {
     $allow_not_routed_url = isset($this->config['allow_not_routed_url']) ? $this->config['allow_not_routed_url'] : false;
     $exclude_urls = isset($this->config['options']['exclude_urls']) ? $this->config['options']['exclude_urls'] : [];
     $exclude_hosts = isset($this->config['options']['exclude_hosts']) ? $this->config['options']['exclude_hosts'] : [];
     $uriTargetHost = (new Uri($url))->getHost();
     if (true === $allow_not_routed_url || in_array($url, $exclude_urls) || in_array($uriTargetHost, $exclude_hosts)) {
         return parent::toUrl($url);
     }
     $controller = $this->getController();
     $request = $controller->getRequest();
     $current_uri = $request->getRequestUri();
     $request->setUri($url);
     $uriTarget = (new Uri($url))->__toString();
     if ($current_uri === $uriTarget) {
         $this->getEventManager()->trigger('redirect-same-url');
         return;
     }
     $mvcEvent = $this->getEvent();
     $routeMatch = $mvcEvent->getRouteMatch();
     $currentRouteMatchName = $routeMatch->getMatchedRouteName();
     $router = $mvcEvent->getRouter();
     $uriCurrentHost = (new Uri($router->getRequestUri()))->getHost();
     if (($routeToBeMatched = $router->match($request)) && ($uriTargetHost === null || $uriCurrentHost === $uriTargetHost) && (($routeToBeMatchedRouteName = $routeToBeMatched->getMatchedRouteName()) !== $currentRouteMatchName && ($this->manager->has($routeToBeMatched->getParam('controller')) || $routeToBeMatched->getParam('middleware') !== false) || $routeToBeMatched->getParam('action') != $routeMatch->getParam('action') || $routeToBeMatchedRouteName === $currentRouteMatchName)) {
         return parent::toUrl($url);
     }
     $default_url = isset($this->config['default_url']) ? $this->config['default_url'] : '/';
     return parent::toUrl($default_url);
 }
Example #4
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);
 }
Example #5
0
 /**
  * Redirect to the given URL
  *
  * @param string $url
  * @return Response
  */
 public function toUrl($url)
 {
     $this->controller->view()->setTemplate(false);
     $response = parent::toUrl($url);
     if ($this->responseCode) {
         $response->setStatusCode($this->responseCode);
         $this->responseCode = null;
     }
     $response->send();
     return $response;
 }
Example #6
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;
 }
Example #7
0
 public function testPluginWithoutControllerRaisesDomainException()
 {
     $plugin = new RedirectPlugin();
     $this->setExpectedException('Zend\\Mvc\\Exception\\DomainException', 'requires a controller');
     $plugin->toRoute('home');
 }
Example #8
0
 public function logoutAction()
 {
     $this->auth->logout();
     return $this->redirect->toUrl($this->redirectToUrl);
 }
Example #9
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()]);
 }