jnvsor / composite-matcher
此包已被废弃,不再维护。未建议替代包。
一个按顺序运行 RequestMatchers 以找到匹配项的复合匹配器
1.0
2017-05-27 20:32 UTC
Requires
- php: >= 5.4
- symfony/http-foundation: ^2.0 || ^3.0
- symfony/routing: ^2.1 || ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2024-09-04 09:13:54 UTC
README
为 symfony/routing
提供“复合匹配器”,该匹配器接受多个匹配器并按顺序运行。
适用于复制过于复杂的旧版路由系统。
使用 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?'; }, ]; } }
要求
应支持到 5.4,但我只在 5.6+ 上运行 CI
依赖于 symfony/http-foundation
和 symfony/routing