コード例 #1
0
 public function testMethodNotAllowedResultsAreMerged()
 {
     $firstMatchResult = MatchResult::fromMethodFailure(['GET']);
     $secondMatchResult = MatchResult::fromMethodFailure(['POST']);
     $matchResult = RouteCollectionMatcher::matchRouteCollection($this->buildRouteCollection([$firstMatchResult, $secondMatchResult]), $this->prophesize(ServerRequestInterface::class)->reveal(), 0, []);
     $this->assertInstanceOf(MatchResult::class, $matchResult);
     $this->assertTrue($matchResult->isMethodFailure());
     $this->assertEquals(['GET', 'POST'], $matchResult->getAllowedMethods());
 }
コード例 #2
0
ファイル: Router.php プロジェクト: dasprid/dash
 /**
  * {@inheritdoc}
  *
  * @throws UnexpectedValueException
  */
 public function match(ServerRequestInterface $request)
 {
     $basePathLength = strlen($this->baseUri['path']);
     return RouteCollectionMatcher::matchRouteCollection($this->routeCollection, $request, $basePathLength, []) ?: MatchResult::fromMatchFailure();
 }
コード例 #3
0
ファイル: Generic.php プロジェクト: dasprid/dash
 /**
  * {@inheritdoc}
  *
  * @throws Exception\UnexpectedValueException
  */
 public function match(ServerRequestInterface $request, $pathOffset)
 {
     $uri = $request->getUri();
     $params = $this->defaults;
     // Verify scheme first, if set.
     if (true === $this->secure && 'https' !== $uri->getScheme()) {
         return MatchResult::fromSchemeFailure($uri->withScheme('https'));
     } elseif (false === $this->secure && 'http' !== $uri->getScheme()) {
         return MatchResult::fromSchemeFailure($uri->withScheme('http'));
     }
     // Then match hostname, if parser is set.
     if (null !== $this->hostnameParser) {
         $hostnameResult = $this->hostnameParser->parse($uri->getHost(), 0);
         if (null === $hostnameResult || strlen($uri->getHost()) !== $hostnameResult->getMatchLength()) {
             return null;
         }
         $params = $hostnameResult->getParams() + $params;
     }
     // Then match port, if set.
     if (null !== $this->port) {
         $port = $uri->getPort() ?: ('http' === $uri->getScheme() ? 80 : 443);
         if ($port !== $this->port) {
             return null;
         }
     }
     // Next match the path.
     $completePathMatched = false;
     if (null !== $this->pathParser) {
         if (null === ($pathResult = $this->pathParser->parse($uri->getPath(), $pathOffset))) {
             return null;
         }
         $pathOffset += $pathResult->getMatchLength();
         $completePathMatched = $pathOffset === strlen($uri->getPath());
         $params = $pathResult->getParams() + $params;
     }
     if ($completePathMatched) {
         if (null === $this->methods || in_array($request->getMethod(), $this->methods)) {
             return MatchResult::fromSuccess($params);
         }
         if (empty($this->methods)) {
             // Special case: when no methods are defined at all, this route may simply not terminate.
             return null;
         }
         return MatchResult::fromMethodFailure($this->methods);
     }
     // The path was not completely matched yet, so we check the children.
     if (null === $this->children) {
         return null;
     }
     return RouteCollectionMatcher::matchRouteCollection($this->children, $request, $pathOffset, $params);
 }