/** * @param HttpRequestInterface $request * * @return bool */ public function matches(HttpRequestInterface $request) { if ($this->method != $request->getMethod()) { return false; } $requestPathSegments = explode('/', $request->getPath()); $routePathSegments = explode('/', $this->path); if (count($requestPathSegments) != count($routePathSegments)) { return false; } $pathParameters = []; foreach ($routePathSegments as $index => $pathSegment) { if (preg_match('/\\{(.*)\\}/', $pathSegment, $matches)) { $pathParameters[$matches[1]] = $requestPathSegments[$index]; continue; } if ($pathSegment != $requestPathSegments[$index]) { return false; } } foreach ($pathParameters as $name => $value) { $request->addPathParameter($name, $value); } return true; }