コード例 #1
0
 /**
  * @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());
 }
コード例 #2
0
ファイル: StaticRoute.php プロジェクト: ableron/ableron-core
 /**
  * @see \Ableron\Core\Router\Route\RouteInterface::match()
  */
 public function match(Uri $moduleRequestUri, HttpRequest $request)
 {
     // prepare module request URI
     $moduleRequestUriNormalized = $this->routeParameters['isCaseSensitive'] ? $moduleRequestUri->getPath() : StringUtil::toLowerCase($moduleRequestUri->getPath());
     // handle "exactMath"
     if ($this->routeParameters['exactMatch'] !== null) {
         $exactMatchPattern = $this->routeParameters['isCaseSensitive'] ? $this->routeParameters['exactMatch'] : StringUtil::toLowerCase($this->routeParameters['exactMatch']);
         return $exactMatchPattern === $moduleRequestUriNormalized ? $this : null;
     }
     // handle "startsWith"
     if ($this->routeParameters['startsWith'] !== null) {
         $startsWithPattern = $this->routeParameters['isCaseSensitive'] ? $this->routeParameters['startsWith'] : StringUtil::toLowerCase($this->routeParameters['startsWith']);
         return StringUtil::startsWith($moduleRequestUriNormalized, $startsWithPattern) ? $this : null;
     }
     // no match
     return null;
 }
コード例 #3
0
 /**
  * Returns the site URL, i.e. the URL to the directory where the front
  * controller is located.
  *
  * @return \Ableron\Lib\Net\Uri
  */
 public static function getSiteUrl()
 {
     return clone CacheUtil::getFromCache(self::getCache(), __FUNCTION__, function () {
         return Uri::createFromComponents(self::getRequestProtocol(), self::getEnvironmentVariable('HTTP_HOST'), null, null, null, self::getSitePath())->normalize();
     });
 }
コード例 #4
0
 /**
  * Sets the request URI.
  *
  * @param \Ableron\Lib\Net\Uri $requestUri The request URI
  * @return void
  */
 public function setRequestUri(Uri $requestUri)
 {
     $this->requestUri = $requestUri->toString();
 }
コード例 #5
0
ファイル: Uri.php プロジェクト: ableron/ableron-core
 /**
  * Creates an Uri object using the given URI components.
  *
  * Authority part will be overwritten by provided user info, host and port.
  *
  * @param string|null $scheme The URI scheme
  * @param string|null $authority The authority part
  * @param string|null $userInfo The user info part
  * @param string|null $host The host name
  * @param int|null $port The protocol port
  * @param string|null $path The path part
  * @param string|null $query The query part
  * @param string|null $fragment The fragment
  * @throws \Ableron\Core\Exception\SystemException
  * @return \Ableron\Lib\Net\Uri
  */
 public static function createFromComponents($scheme = null, $authority = null, $userInfo = null, $host = null, $port = null, $path = null, $query = null, $fragment = null)
 {
     try {
         $uri = new Uri();
         $uri->setScheme($scheme);
         $uri->setAuthority($authority);
         if ($userInfo !== null) {
             $uri->setUserInfo($userInfo);
         }
         if ($host !== null) {
             $uri->setHost($host);
         }
         if ($port !== null) {
             $uri->setPort($port);
         }
         $uri->setPath($path);
         $uri->setQuery($query);
         $uri->setFragment($fragment);
         return $uri;
     } catch (SystemException $e) {
         throw new SystemException('Unable to create Uri object', 0, E_USER_NOTICE, __FILE__, __LINE__, $e);
     }
 }
コード例 #6
0
 /**
  * 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))));
 }
コード例 #7
0
 /**
  * Checks whether the given request is a frontend request.
  *
  * Returns TRUE in case the given request is a frontend request.
  * Otherwise returns FALSE.
  *
  * @param \Ableron\Lib\Net\Uri $frontendBaseUrl The frontend base URL
  * @param \Ableron\Lib\Net\Uri $backendBaseUrl The backend base URL
  * @param string $requestHost Host name of the request to check
  * @param string $requestPath Path of the request to check
  * @return bool
  */
 private function checkIsFrontendRequest(Uri $frontendBaseUrl, Uri $backendBaseUrl, $requestHost, $requestPath)
 {
     // check whether frontend base path is more or less specific than backend base path
     $matchFrontendFirst = StringUtil::getLength($frontendBaseUrl->getPath(), true) > StringUtil::getLength($backendBaseUrl->getPath(), true) || StringUtil::getLength($frontendBaseUrl->getHost(), true) > StringUtil::getLength($backendBaseUrl->getHost(), true);
     // check whether this is a frontend request based on frontend base path
     if ($matchFrontendFirst) {
         return $this->requestMatchesBaseUrl($frontendBaseUrl->getHost(), $frontendBaseUrl->getPath(), $requestHost, $requestPath);
     }
     // check whether this is a frontend request based on backend base path
     return !$this->requestMatchesBaseUrl($backendBaseUrl->getHost(), $backendBaseUrl->getPath(), $requestHost, $requestPath);
 }
コード例 #8
0
ファイル: UriTest.php プロジェクト: ableron/ableron-core
 /**
  * Tests whether createFromComponents() works as expected.
  *
  * @dataProvider dataProviderTestCreateFromComponents
  * @return void
  */
 public function testCreateFromComponents($scheme, $authority, $userInfo, $host, $port, $path, $query, $fragment, $expectedUri)
 {
     $this->assertSame($expectedUri, Uri::createFromComponents($scheme, $authority, $userInfo, $host, $port, $path, $query, $fragment)->toString());
 }