public function connectControllers(ControllerCollection $controllers, $prefix = null) { if ($prefix === null) { $prefix = static::SEPARATOR . $this->getPath(); } foreach ($this->controllerCollections as $collection) { $controllers->mount($prefix, $collection); } foreach ($this->getChildren() as $childNode) { $childNode->connectControllers($controllers); } $this->getBaseNode()->connectControllers($controllers, $prefix); }
/** * Mounts controllers under the given route prefix. * * @param string $prefix The route prefix * @param ControllerCollection|ControllerProviderInterface $controllers A ControllerCollection or a ControllerProviderInterface instance */ public function mount($prefix, $controllers) { $controllers = $this->verifyCollection($controllers); $this->collection->mount($prefix, $controllers); }
public function testNestedCollectionRouteCallbacks() { $cl1 = new ControllerCollection(new MyRoute1()); $cl2 = new ControllerCollection(new MyRoute1()); $c1 = $cl2->match('/c1', function () { }); $cl1->mount('/foo', $cl2); $c2 = $cl2->match('/c2', function () { }); $cl1->before('before'); $c3 = $cl2->match('/c3', function () { }); $cl1->flush(); $this->assertEquals(array('before'), $c1->getRoute()->getOption('_before_middlewares')); $this->assertEquals(array('before'), $c2->getRoute()->getOption('_before_middlewares')); $this->assertEquals(array('before'), $c3->getRoute()->getOption('_before_middlewares')); }
public function testUniqueGeneratedRouteNamesAmongNestedMounts() { $controllers = new ControllerCollection(new Route()); $controllers->mount('/root-a', $rootA = new ControllerCollection(new Route())); $controllers->mount('/root_a', $rootB = new ControllerCollection(new Route())); $rootA->mount('/tree', $treeA = new ControllerCollection(new Route())); $rootB->mount('/tree', $treeB = new ControllerCollection(new Route())); $treeA->match('/leaf', function () { }); $treeB->match('/leaf', function () { }); $routes = $controllers->flush(); $this->assertCount(2, $routes->all()); $this->assertEquals(array('_root_a_tree_leaf', '_root_a_tree_leaf_'), array_keys($routes->all())); }