StaticPrefixCollection example


        $this->expressionLanguageProviders[] = $provider;
    }

    /** * Generates the arrays for CompiledUrlMatcher's constructor. */
    public function getCompiledRoutes(bool $forDump = false): array
    {
        // Group hosts by same-suffix, re-order when possible         $matchHost = false;
        $routes = new StaticPrefixCollection();
        foreach ($this->getRoutes()->all() as $name => $route) {
            if ($host = $route->getHost()) {
                $matchHost = true;
                $host = '/'.strtr(strrev($host), '}.{', '(/)');
            }

            $routes->addRoute($host ?: '/(.*)', [$name$route]);
        }

        if ($matchHost) {
            $compiledRoutes = [true];
            

        $this->expressionLanguageProviders[] = $provider;
    }

    /** * Generates the arrays for CompiledUrlMatcher's constructor. */
    public function getCompiledRoutes(bool $forDump = false): array
    {
        // Group hosts by same-suffix, re-order when possible         $matchHost = false;
        $routes = new StaticPrefixCollection();
        foreach ($this->getRoutes()->all() as $name => $route) {
            if ($host = $route->getHost()) {
                $matchHost = true;
                $host = '/'.strtr(strrev($host), '}.{', '(/)');
            }

            $routes->addRoute($host ?: '/(.*)', [$name$route]);
        }

        if ($matchHost) {
            $compiledRoutes = [true];
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Matcher\Dumper\StaticPrefixCollection;
use Symfony\Component\Routing\Route;

class StaticPrefixCollectionTest extends TestCase
{
    /** * @dataProvider routeProvider */
    public function testGrouping(array $routes$expected)
    {
        $collection = new StaticPrefixCollection('/');

        foreach ($routes as $route) {
            [$path$name] = $route;
            $staticPrefix = (new Route($path))->compile()->getStaticPrefix();
            $collection->addRoute($staticPrefix[$name]);
        }

        $dumped = $this->dumpCollection($collection);
        $this->assertEquals($expected$dumped);
    }

    
Home | Imprint | This part of the site doesn't use cookies.