Example #1
0
 /**
  * @dataProvider validUriProvider
  */
 public function testValidUriResolvesToUriComponents($uri, $expectedDomain, $expectedDemand)
 {
     $requestInfo = new RequestInfo(['REQUEST_URI' => $uri]);
     $resolver = new UriResolver();
     $components = $resolver->resolveUri($requestInfo);
     $this->assertEquals($expectedDomain, $components->getDomain());
     $this->assertEquals($expectedDemand, $components->getDemand());
 }
Example #2
0
 /**
  * @param ServesRequestInfo $requestInfo
  *
  * @throws IceHawk\Exceptions\MalformedRequestUri
  * @return IceHawk\Interfaces\ServesUriComponents
  */
 public function resolveUri(ServesRequestInfo $requestInfo)
 {
     $uri = $requestInfo->getUri();
     # home
     if ($uri == '/') {
         return new UriComponents('Posts', 'Abstract', []);
     }
     # imprint
     if ($uri == '/imprint') {
         return new UriComponents('Blog', 'Imprint', []);
     }
     # sitemap
     if ($uri == '/sitemap') {
         return new UriComponents('Blog', 'Sitemap', []);
     }
     # posts
     if (preg_match("#^/posts/[^/]+/?\$#i", $uri)) {
         return new UriComponents('Posts', 'ShowPost', []);
     }
     # about author
     if (preg_match('#^/about/author/([^/]+)#i', $uri, $matches)) {
         $authorName = $matches[1];
         return new UriComponents('Blog', 'Author', ['authorName' => $authorName]);
     }
     return parent::resolveUri($requestInfo);
 }
Example #3
0
 /**
  * @param ServesRequestInfo $requestInfo
  *
  * @throws \Fortuneglobe\IceHawk\Exceptions\MalformedRequestUri
  * @return \Fortuneglobe\IceHawk\Interfaces\ServesUriComponents
  */
 public function resolveUri(ServesRequestInfo $requestInfo)
 {
     $uri = $requestInfo->getUri();
     # Show server selection
     if ($uri == '/') {
         return new UriComponents('server', 'select', []);
     }
     # Show a specific server
     if (preg_match("#^/server/([0-9]+)/?\$#", $uri, $matches)) {
         return new UriComponents('server', 'show', ['serverKey' => $matches[1]]);
     }
     return parent::resolveUri($requestInfo);
 }