2017 © Pedro Peláez
 

library composite-matcher

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

image

jnvsor/composite-matcher

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

  • Saturday, May 27, 2017
  • by JnvSor
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

CompositeMatcher

Provides a "Composite matcher" for symfony/routing that takes multiple matchers and runs them in sequence., (*1)

Useful for duplicating overly-complex legacy routing systems., (*2)

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+, (*3)

Depends on symfony/http-foundation and symfony/routing, (*4)

The Versions

27/05 2017

dev-master

9999999-dev

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

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

27/05 2017

1.0

1.0.0.0

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

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires