ApiPlatform\Core\Bridge\Symfony\Routing\Router::match PHP Метод

match() публичный метод

public match ( $pathInfo )
    public function match($pathInfo)
    {
        $baseContext = $this->router->getContext();
        $pathInfo = str_replace($baseContext->getBaseUrl(), '', $pathInfo);
        $request = Request::create($pathInfo);
        $context = (new RequestContext())->fromRequest($request);
        $context->setPathInfo($pathInfo);
        $context->setScheme($baseContext->getScheme());
        try {
            $this->router->setContext($context);
            return $this->router->match($request->getPathInfo());
        } finally {
            $this->router->setContext($baseContext);
        }
    }

Usage Example

Пример #1
0
 public function testMatch()
 {
     $context = new RequestContext('/app_dev.php', 'GET', 'localhost', 'https');
     $mockedRouter = $this->prophesize('Symfony\\Component\\Routing\\RouterInterface');
     $mockedRouter->getContext()->willReturn($context)->shouldBeCalled();
     $mockedRouter->setContext(Argument::type('Symfony\\Component\\Routing\\RequestContext'))->shouldBeCalled();
     $mockedRouter->setContext($context)->shouldBeCalled();
     $mockedRouter->match('/foo')->willReturn(['bar'])->shouldBeCalled();
     $router = new Router($mockedRouter->reveal());
     $this->assertEquals(['bar'], $router->match('/app_dev.php/foo'));
 }