TraceableUrlMatcher example

$traceRequest = Request::create(
            $request->getPathInfo(),
            $request->getRequestServer(true)->get('REQUEST_METHOD'),
            \in_array($request->getMethod()['DELETE', 'PATCH', 'POST', 'PUT'], true) ? $request->getRequestRequest()->all() : $request->getRequestQuery()->all(),
            $request->getRequestCookies(true)->all(),
            [],
            $request->getRequestServer(true)->all()
        );

        $context = $this->matcher->getContext();
        $context->setMethod($method);
        $matcher = new TraceableUrlMatcher($this->routes, $context);
        foreach ($this->expressionLanguageProviders as $provider) {
            $matcher->addExpressionLanguageProvider($provider);
        }

        return $matcher->getTracesForRequest($traceRequest);
    }
}
$coll = new RouteCollection();
        $coll->add('foo', new Route('/foo', [][][], '', []['POST']));
        $coll->add('bar', new Route('/bar/{id}', []['id' => '\d+']));
        $coll->add('bar1', new Route('/bar/{name}', []['id' => '\w+'][], '', []['POST']));
        $coll->add('bar2', new Route('/foo', [][][], 'baz'));
        $coll->add('bar3', new Route('/foo1', [][][], 'baz'));
        $coll->add('bar4', new Route('/foo2', [][][], 'baz', [][], 'context.getMethod() == "GET"'));

        $context = new RequestContext();
        $context->setHost('baz');

        $matcher = new TraceableUrlMatcher($coll$context);
        $traces = $matcher->getTraces('/babar');
        $this->assertSame([0, 0, 0, 0, 0, 0]$this->getLevels($traces));

        $traces = $matcher->getTraces('/foo');
        $this->assertSame([1, 0, 0, 2]$this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/12');
        $this->assertSame([0, 2]$this->getLevels($traces));

        $traces = $matcher->getTraces('/bar/dd');
        $this->assertSame([0, 1, 1, 0, 0, 0]$this->getLevels($traces));

        
$context = $this->router->getContext();
        if (null !== $method = $input->getOption('method')) {
            $context->setMethod($method);
        }
        if (null !== $scheme = $input->getOption('scheme')) {
            $context->setScheme($scheme);
        }
        if (null !== $host = $input->getOption('host')) {
            $context->setHost($host);
        }

        $matcher = new TraceableUrlMatcher($this->router->getRouteCollection()$context);
        foreach ($this->expressionLanguageProviders as $provider) {
            $matcher->addExpressionLanguageProvider($provider);
        }

        $traces = $matcher->getTraces($input->getArgument('path_info'));

        $io->newLine();

        $matches = false;
        foreach ($traces as $trace) {
            if (TraceableUrlMatcher::ROUTE_ALMOST_MATCHES == $trace['level']) {
                
Home | Imprint | This part of the site doesn't use cookies.