jnvsor/composite-matcher

This package is abandoned and no longer maintained. No replacement package was suggested.

A composite matcher that runs RequestMatchers in sequence to find a match

1.0 2017-05-27 20:32 UTC

This package is auto-updated.

Last update: 2024-09-04 09:13:54 UTC


README

Provides a "Composite matcher" for symfony/routing that takes multiple matchers and runs them in sequence.

Useful for duplicating overly-complex legacy routing systems.

Example using Silex

<?php

use Silex\Provider\Routing\RedirectableUrlMatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;

include 'vendor/autoload.php';

$app = new Silex\Application();

// Change the request matcher to a CompositeMatcher of
// the Silex matcher and our own CatchLeftoversMatcher
$app['request_matcher'] = function ($app) {
    $ret = new CompositeMatcher\CompositeRequestMatcher($app['request_context']);
    $ret->addMatcher(new RedirectableUrlMatcher($app['routes'], $app['request_context']));
    $ret->addMatcher(new CatchLeftoversMatcher());

    return $ret;
};

$app->get('/', function(){
    return 'woot?';
});

$app->run();

class CatchLeftoversMatcher implements RequestMatcherInterface {
    public function matchRequest(Request $r) {
        if ($r->getPathInfo() != '/test/') {
            throw new ResourceNotFoundException();
        }

        return [
            'test' => 'test',
            'foo' => 'bar',
            '_controller' => function(){
                return 'waat?';
            },
        ];
    }
}

Requirements

Should work down to 5.4, but I'm only running CI on 5.6+

Depends on symfony/http-foundation and symfony/routing