If set, the URI is prepended with the current base URI. Defaults to FALSE.
public setCreateAbsoluteUri ( boolean $createAbsoluteUri ) : |
||
$createAbsoluteUri | boolean | |
return | the current UriBuilder to allow method chaining |
/** * @test */ public function buildDoesNotPrependsScriptRequestPathIfCreateRelativePathsCompatibilityFlagIsTrue() { $this->mockHttpRequest->expects($this->never())->method('getScriptRequestPath'); $this->mockRouter->expects($this->once())->method('resolve')->will($this->returnValue('resolvedUri')); $this->uriBuilder->setCreateAbsoluteUri(false); $this->uriBuilder->setCreateRelativePaths(true); $expectedResult = 'resolvedUri'; $actualResult = $this->uriBuilder->build(); $this->assertEquals($expectedResult, $actualResult); }
/** * Starts the authentication: Redirect to login page * * @param Request $request The current request * @param Response $response The current response * @return void * @throws MissingConfigurationException */ public function startAuthentication(Request $request, Response $response) { if (isset($this->options['routeValues'])) { $routeValues = $this->options['routeValues']; if (!is_array($routeValues)) { throw new MissingConfigurationException(sprintf('The configuration for the WebRedirect authentication entry point is incorrect. "routeValues" must be an array, got "%s".', gettype($routeValues)), 1345040415); } $actionRequest = new ActionRequest($request); $this->uriBuilder->setRequest($actionRequest); $actionName = $this->extractRouteValue($routeValues, '@action'); $controllerName = $this->extractRouteValue($routeValues, '@controller'); $packageKey = $this->extractRouteValue($routeValues, '@package'); $subPackageKey = $this->extractRouteValue($routeValues, '@subpackage'); $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $routeValues, $controllerName, $packageKey, $subPackageKey); } elseif (isset($this->options['uri'])) { $uri = strpos($this->options['uri'], '://') !== false ? $this->options['uri'] : $request->getBaseUri() . $this->options['uri']; } else { throw new MissingConfigurationException('The configuration for the WebRedirect authentication entry point is incorrect or missing. You need to specify either the target "uri" or "routeValues".', 1237282583); } $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities($uri, ENT_QUOTES, 'utf-8'))); $response->setStatus(303); $response->setHeader('Location', $uri); }
/** * Redirects the request to another action and / or controller. * * Redirect will be sent to the client which then performs another request to the new URI. * * NOTE: This method only supports web requests and will throw an exception * if used with other request types. * * @param string $actionName Name of the action to forward to * @param string $controllerName Unqualified object name of the controller to forward to. If not specified, the current controller is used. * @param string $packageKey Key of the package containing the controller to forward to. If not specified, the current package is assumed. * @param array $arguments Array of arguments for the target action * @param integer $delay (optional) The delay in seconds. Default is no delay. * @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other" * @param string $format The format to use for the redirect URI * @return void * @throws StopActionException * @see forward() * @api */ protected function redirect($actionName, $controllerName = null, $packageKey = null, array $arguments = null, $delay = 0, $statusCode = 303, $format = null) { if ($packageKey !== null && strpos($packageKey, '\\') !== false) { list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2); } else { $subpackageKey = null; } $this->uriBuilder->reset(); if ($format === null) { $this->uriBuilder->setFormat($this->request->getFormat()); } else { $this->uriBuilder->setFormat($format); } $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey); $this->redirectToUri($uri, $delay, $statusCode); }
/** * For the given $token an activation link is returned. * * @param Token $token * @return string * @throws InvalidTokenException */ public function getActivationLink(Token $token) { $activationConfiguration = $token->getPreset()['activation']; $tokenHash = $token->getHash(); if ($activationConfiguration['uri'] === NULL) { throw new \RuntimeException('Building activation link failed, no uri configuration is set', 1434728943); } elseif (is_array($activationConfiguration['uri'])) { $routerConfiguration = $activationConfiguration['uri']; $this->uriBuilder->setRequest($this->request); $uri = $this->uriBuilder->setCreateAbsoluteUri(TRUE)->setFormat($routerConfiguration['@format'])->uriFor($routerConfiguration['@action'], $routerConfiguration['arguments'], $routerConfiguration['@controller'], $routerConfiguration['@package'], $routerConfiguration['@subpackage']); } elseif (is_string($activationConfiguration['uri'])) { $uri = $activationConfiguration['uri']; } else { throw new \RuntimeException('Building activation link failed, uri configuration is invalid (neither array nor string)', 1434732898); } $this->logger->log(sprintf('Activation link built for token with hash %s', $tokenHash, $token->getIdentifier()), LOG_INFO); return str_replace('-tokenhash-', $tokenHash, $uri); }
/** * Returns a specific URI string to redirect to after the logout; or NULL if there is none. * In case of NULL, it's the responsibility of the AuthenticationController where to redirect, * most likely to the LoginController's index action. * * @param ActionRequest $actionRequest * @return string A possible redirection URI, if any */ public function getAfterLogoutRedirectionUri(ActionRequest $actionRequest) { $lastVisitedNode = $this->getLastVisitedNode('live'); if ($lastVisitedNode === null) { return null; } $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($actionRequest); $uriBuilder->setFormat('html'); $uriBuilder->setCreateAbsoluteUri(true); return $uriBuilder->uriFor('show', array('node' => $lastVisitedNode), 'Frontend\\Node', 'Neos.Neos'); }