getModuleName(), $context->getActionName() ); } /** * Forward the action to execute regarding a URL * The forward runs into tha same HTTP request unlike redirect. * * @param string $url the url to forward to * @throws InterruptedActionException * @throws \ResolverException * @throws \common_exception_InconsistentData * @throws \common_exception_InvalidArgumentType * @throws ManifestNotFoundException */ public function forwardUrl($url) { $uri = new Uri($url); $query = $uri->getQuery(); $queryParams = []; if (strlen($query) > 0) { parse_str($query, $queryParams); } switch ($this->getPsrRequest()->getMethod()) { case 'GET': $params = $this->getPsrRequest()->getQueryParams(); break; case 'POST': $params = $this->getPsrRequest()->getParsedBody(); break; default: $params = []; } $request = $this->getPsrRequest() ->withUri($uri) ->withQueryParams((array) $queryParams); //resolve the given URL for routing $resolver = new Resolver($request); $resolver->setServiceLocator($this->getServiceLocator()); //update the context to the new route $context = \Context::getInstance(); $context->setExtensionName($resolver->getExtensionId()); $context->setModuleName($resolver->getControllerShortName()); $context->setActionName($resolver->getMethodName()); $context->getRequest()->addParameters($queryParams); $request = $request ->withAttribute('extension', $resolver->getExtensionId()) ->withAttribute('controller', $resolver->getControllerShortName()) ->withAttribute('method', $resolver->getMethodName()); //execute the new action $enforcer = new ActionEnforcer( $resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $params ); $enforcer->setServiceLocator($this->getServiceLocator()); $enforcer( $request, $this->response->withHeader( 'X-Tao-Forward', $resolver->getExtensionId() . '/' . $resolver->getControllerShortName() . '/' . $resolver->getMethodName() ) ); throw new InterruptedActionException( 'Interrupted action after a forwardUrl', $context->getModuleName(), $context->getActionName() ); } /** * Forward routing. * * @param string $action the name of the new action * @param string $controller the name of the new controller/module * @param string $extension the name of the new extension * @param array $params additional parameters * @throws InterruptedActionException * @throws \ActionEnforcingException * @throws \common_exception_Error */ public function forward($action, $controller = null, $extension = null, $params = []) { //as we use a route resolver, it's easier to rebuild the URL to resolve it $this->forwardUrl(\tao_helpers_Uri::url($action, $controller, $extension, $params)); } }