コード例 #1
0
 /**
  * @param RequestInterface $request
  * @param Route $route
  * @return mixed
  */
 public function __invoke(RequestInterface $request, Route $route)
 {
     $args = array_filter($route->getMatches(), function ($name) {
         return strpos($name, '_') !== 0;
     }, \ARRAY_FILTER_USE_KEY);
     $route->getEndPoint()->setArgs($args);
     return $route($request);
 }
コード例 #2
0
 public function testRegexpWithResriction()
 {
     $route = new Route('/controller/{action}/', function () {
     });
     $route->setRestrictions(['action' => '\\w+']);
     $regexp = $this->service->makeRegExp($route);
     self::assertEquals('/controller/(?<action>\\w+)/', $regexp);
 }
コード例 #3
0
ファイル: RouteTest.php プロジェクト: alexpts/php-routing
 public function testMiddleware()
 {
     $this->route->pushMiddleware(function (RequestInterface $request, callable $next) {
         $response = $next($request);
         return $response . '2';
     });
     $request = new \Zend\Diactoros\Request('/');
     $route = $this->route;
     self::assertEquals('response2', $route($request));
 }
コード例 #4
0
 public function testMiddleware()
 {
     $route = new Route('/profile/{name}/', function ($name) {
         return $name;
     });
     $route->pushMiddleware(new CallWithMatchParams());
     $coll = new CollectionRoute();
     $coll->add('profile', $route);
     $path = '/profile/alex/';
     $matcher = new Matcher(new RouteService());
     $activeRoute = $matcher->match($coll, $path)->current();
     self::assertEquals('alex', $activeRoute(new Request($path)));
 }