Ejemplo n.º 1
0
 /**
  * Matches a request against a route collection.
  *
  * @param  RouteCollectionInterface $routeCollection
  * @param  ServerRequestInterface   $request
  * @param  int                      $pathOffset
  * @param  array                    $parentParams
  * @return MatchResult|null
  * @throws UnexpectedValueException
  */
 public static function matchRouteCollection(RouteCollectionInterface $routeCollection, ServerRequestInterface $request, $pathOffset, array $parentParams)
 {
     $methodFailureResult = null;
     $schemeFailureResult = null;
     foreach ($routeCollection as $name => $route) {
         if (null === ($matchResult = $route->match($request, $pathOffset))) {
             continue;
         }
         if ($matchResult->isSuccess()) {
             return MatchResult::fromChildMatch($matchResult, $parentParams, $name);
         }
         if ($matchResult->isMethodFailure()) {
             if (null === $methodFailureResult) {
                 $methodFailureResult = $matchResult;
             } else {
                 $methodFailureResult = MatchResult::mergeMethodFailures($methodFailureResult, $matchResult);
             }
             continue;
         }
         if ($matchResult->isSchemeFailure()) {
             $schemeFailureResult = $schemeFailureResult ?: $matchResult;
             continue;
         }
         return $matchResult;
     }
     if (null !== $schemeFailureResult) {
         return $schemeFailureResult;
     }
     if (null !== $methodFailureResult) {
         return $methodFailureResult;
     }
     return null;
 }
Ejemplo n.º 2
0
 public function testMergeMethodFailuresWithIncompatibleMatchResults()
 {
     $this->setExpectedException(DomainException::class, 'Both match results must be method failures');
     MatchResult::mergeMethodFailures(MatchResult::fromMatchFailure(), MatchResult::fromMatchFailure());
 }