Example #1
0
 /**
  * @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;
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * Tests whether parser and getter are working correctly.
  *
  * @dataProvider dataProviderTestParserAndGetter
  * @return void
  */
 public function testParserAndGetter($uriString, $expectedResult)
 {
     $uri = new Uri($uriString);
     $this->assertSame($expectedResult['scheme'], $uri->getScheme(), 'getScheme()');
     $this->assertSame($expectedResult['authority'], $uri->getAuthority(), 'getAuthority()');
     $this->assertSame($expectedResult['rawAuthority'], $uri->getRawAuthority(), 'getRawAuthority()');
     $this->assertSame($expectedResult['userInfo'], $uri->getUserInfo(), 'getUserInfo()');
     $this->assertSame($expectedResult['rawUserInfo'], $uri->getRawUserInfo(), 'getRawUserInfo()');
     $this->assertSame($expectedResult['host'], $uri->getHost(), 'getHost()');
     $this->assertSame($expectedResult['rawHost'], $uri->getRawHost(), 'getRawHost()');
     $this->assertSame($expectedResult['port'], $uri->getPort(), 'getPort()');
     $this->assertSame($expectedResult['path'], $uri->getPath(), 'getPath()');
     $this->assertSame($expectedResult['rawPath'], $uri->getRawPath(), 'getRawPath()');
     $this->assertSame($expectedResult['query'], $uri->getQuery(), 'getQuery()');
     $this->assertSame($expectedResult['rawQuery'], $uri->getRawQuery(), 'getRawQuery()');
     $this->assertSame($expectedResult['queryParameters'], $uri->getQueryParameters(), 'getQueryParameters()');
     $this->assertSame($expectedResult['fragment'], $uri->getFragment(), 'getFragment()');
     $this->assertSame($expectedResult['rawFragment'], $uri->getRawFragment(), 'getRawFragment()');
     $this->assertSame($expectedResult['isAbsolute'], $uri->isAbsolute(), 'isAbsolute()');
     $this->assertSame($expectedResult['externalForm'], $uri->toString(), 'toString()');
     $this->assertSame($expectedResult['normalized'], $uri->normalize()->toString(), 'normalize()');
 }