/**
  * @see \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface::compileOpeningTag()
  */
 public function compileOpeningTag(TemplateCompiler $templateCompiler)
 {
     // build base URL
     $actionUrl = new Uri(parent::compileOpeningTag($templateCompiler));
     // add URL of current request as action source URL
     $actionUrl->addQueryParameter(ABLERON_PARAM_ACTION_SOURCE_URL, StringUtil::base64UrlEncode(Application::getRequestHandler()->getRequest()->getUri()->toString()));
     // add CSRF token query parameter to URL
     $actionUrl->addQueryParameter(ABLERON_PARAM_CSRF_TOKEN, self::$actionUrlCsrfTokenPlaceholder);
     // return final URL
     return str_replace(self::$actionUrlCsrfTokenPlaceholder, '<?php echo $application::getSecurityHandler()->getCsrfProtector()->getCurrentToken(); ?>', $actionUrl->toString());
 }
 /**
  * Sets the request URI.
  *
  * @param \Ableron\Lib\Net\Uri $requestUri The request URI
  * @return void
  */
 public function setRequestUri(Uri $requestUri)
 {
     $this->requestUri = $requestUri->toString();
 }
Example #3
0
 /**
  * Resolves this relative URI using the given absolute base URI.
  *
  * Does not change this Uri object in case this URI is already absolute.
  *
  * @param \Ableron\Lib\Net\Uri $baseUri The absolute base URI used to resolve this relative URI
  * @throws \Ableron\Core\Exception\SystemException
  * @return \Ableron\Lib\Net\Uri
  */
 public function resolve(Uri $baseUri)
 {
     // check whether base URI is absolute
     if (!$baseUri->isAbsolute()) {
         throw new SystemException(sprintf('Unable to resolve URI using base URI "%s" - Base URI must be absolute!', $baseUri->toString()), 0, E_USER_NOTICE, __FILE__, __LINE__);
     }
     // check whether URI is already absolute
     if ($this->isAbsolute()) {
         $this->setPath(self::removeDotSegments($this->path));
         return $this;
     }
     // resolve scheme specific part
     if ($this->host !== null) {
         $this->setPath(self::removeDotSegments($this->path));
     } else {
         // resolve authority part
         $this->setUserInfo($baseUri->getRawUserInfo());
         $this->setHost($baseUri->getRawHost());
         $this->setPort($baseUri->getPort());
         // resolve path and query
         if ($this->path === '') {
             $this->setPath($baseUri->getRawPath());
             if ($this->query === null) {
                 $this->setQuery($baseUri->getRawQuery());
             }
         } else {
             if (StringUtil::startsWith($this->path, '/')) {
                 $this->setPath(self::removeDotSegments($this->path));
             } else {
                 $this->setPath(self::removeDotSegments($baseUri->getRawHost() !== null && $baseUri->getRawPath() === '' ? '/' : StringUtil::getSubstring($baseUri->getRawPath(), 0, StringUtil::getLastIndexOf($baseUri->getRawPath(), '/') + 1) . $this->path));
             }
         }
     }
     // resolve scheme
     $this->setScheme($baseUri->getScheme());
     // return reference of this object
     return $this;
 }
 /**
  * Sends a redirect to the client.
  *
  * In case a relative URI is given, it will be resolved using the current base URI.
  *
  * @param \Ableron\Lib\Net\Uri $redirectUri The URI to redirect to
  * @param int|null $statusCode Status code of the redirect, e.g. relevant for HTTP redirects
  * @return void
  */
 public function sendRedirect(Uri $redirectUri, $statusCode = HttpResponse::STATUS_SEE_OTHER)
 {
     // because it is not possible to guess an absolute URL from a relative one because of the flexible module paths, relative URLs are not allowed
     if (!$redirectUri->isAbsolute()) {
         // log error
         Application::getLogManager()->error(sprintf('Unable to perform redirect: Redirect URL must be absolute. Relative URL given: %s', $redirectUri->toString()));
         // redirect to base URL
         $redirectUri = EnvironmentUtil::getBaseUrl();
     }
     // set response
     $this->setResponse(new HttpResponse($statusCode, null, '', null, array(new LocationHeaderField($redirectUri))));
 }
Example #5
0
 /**
  * Tests whether setAuthority() works as expected.
  *
  * @dataProvider dataProviderTestSetAuthority
  * @return void
  */
 public function testSetAuthority($baseUri, $newAuthority, $expectedUri)
 {
     $uri = new Uri($baseUri);
     $uri->setAuthority($newAuthority);
     $this->assertSame($expectedUri, $uri->toString());
 }