public function testMap() { $routes = new Collection(); $routes->add(new Route('a', function () { return 'A'; })); $routes->add(new Route('b', function () { return 'B'; })); $routes->attach(new Route('c', function () { return 'C'; })); $patterns = $routes->map(function (Route $route) { return $route->getPattern(); }); $this->assertEquals($patterns->all(), ['a', 'b', 'c']); }
/** * Create a new route instance and attach to Collection * * @param array $verbs * @param string $pattern * @param string $action * @param null|string $name * @return \PHPLegends\Routes\Route * */ public function addRoute(array $verbs, $pattern, $action, $name = null) { $pattern = $this->resolvePatternValue($pattern); $action = $this->resolveActionValue($action); $name = $this->resolveNameValue($name); $route = new Route($pattern, $action, $verbs, $name); if ($filters = $this->getDefaultFilters()) { $route->setFilters($filters); } $this->routes->add($route); return $route; }