/** * Define environment setup. * * @param Illuminate\Foundation\Application $app * @return void */ protected function getEnvironmentSetUp($app) { $app['router']->get('hello', function () { return 'hello world'; }); $app['router']->group(array('prefix' => 'test'), function () { $routes = array('foo' => 'Gxela\\Lararoute\\Tests\\FooController'); Lara::route(array('get', 'post', 'put', 'delete'), $routes, null, 'test', function () { return 'gaps filled'; }, true); }); Lara::route(array('get', 'post', 'put', 'delete'), array('bar' => 'Gxela\\Lararoute\\Tests\\BarController'), array('getDrunk'), null, function () { return 'gaps not filled'; //this wont happen for / }, false); $valid_route_names = array('test.foo', 'test.foo.get_index', 'test.foo.get_bar', 'test.foo.post_foo', 'bar.post_pwn', 'bar.put_buzz', 'bar.delete_some', 'test', 'test.get_index'); foreach ($app['router']->getRoutes() as $route) { $name = $route->getName(); //echo "$name\n"; if (!empty($name)) { $this->assertTrue(in_array($route->getName(), $valid_route_names)); } } }
/** * Auto Bind Laravel Controllers to Routes * * @param array $request_methods array of request methods array('get', 'post', 'put', 'delete'), that public functions start with * @param array $routes * @param array $disallowed disallowed actions, to not bind * @param string $prefix * @param Closure|string $gap_action function or Controller@method that will fill the route gap * @param bool $bind_root to bind prefix root and/or /; fill route gaps */ public static function route(array $request_methods, array $routes, $disallowed = array(), $prefix = null, $gap_action = null, $bind_root = false) { foreach ($routes as $prefix_route => $controller) { Route::group(array('prefix' => $prefix_route), Lara::autoRoute($controller, $request_methods, $disallowed, ($prefix ? $prefix . '.' : '') . $prefix_route)); } if ($bind_root && !empty($gap_action)) { Lara::fillRouteGaps($prefix, $gap_action); } }