/** * Bootstrap the application events. * * @return void */ public function boot() { $app = $this->app; if ($app->runningInConsole()) { $this->app['config']->set('debugbar.enabled', false); } $routeConfig = ['namespace' => 'Barryvdh\\Debugbar\\Controllers', 'prefix' => $this->app['config']->get('debugbar.route_prefix')]; $this->app->group($routeConfig, function ($router) { $router->get('open', ['uses' => 'OpenHandlerController@handle', 'as' => 'debugbar.openhandler']); $router->get('assets/stylesheets', ['uses' => 'AssetController@css', 'as' => 'debugbar.assets.css']); $router->get('assets/javascript', ['uses' => 'AssetController@js', 'as' => 'debugbar.assets.js']); }); $enabled = $this->app['config']->get('debugbar.enabled'); // If enabled is null, set from the app.debug value if (is_null($enabled)) { $enabled = env('APP_DEBUG'); $this->app['config']->set('debugbar.enabled', $enabled); } if (!$enabled) { return; } $this->app['config']->set('debugbar.options.logs.file', storage_path('logs/lumen.log')); /** @var LaravelDebugbar $debugbar */ $debugbar = $this->app['debugbar']; $debugbar->boot(); $app->middleware(['Barryvdh\\Debugbar\\Middleware\\Debugbar']); }
/** * Register Route from this plugin */ public function registerRoute() { foreach ($this->get('routes', []) as $route) { $this->app->group(['namespace' => 'Plugins\\' . $this->getStudlyName() . '\\Http\\Controllers'], function ($app) use($route) { require $this->path . '/' . $route; }); } }
public function testNamespacedControllerResponse() { $app = new Application(); require_once __DIR__ . '/fixtures/TestController.php'; $app->group(['namespace' => 'Lumen\\Tests'], function ($app) { $app->get('/', 'TestController@action'); }); $response = $app->handle(Request::create('/', 'GET')); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Lumen\\Tests\\TestController', $response->getContent()); }
public function testBasicControllerDispatchingWithGroup() { $app = new Application(); $app->routeMiddleware(['test' => LumenTestMiddleware::class]); $app->group(['middleware' => 'test'], function ($app) { $app->get('/show/{id}', 'LumenTestController@show'); }); $response = $app->handle(Request::create('/show/25', 'GET')); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Middleware', $response->getContent()); }
/** * Register a set of routes with a set of shared attributes. * * @param array $attributes * @param \Closure $callback * @return void * @static */ public static function group($attributes, $callback) { \Laravel\Lumen\Application::group($attributes, $callback); }
public function testBasicControllerDispatchingWithGroupAndSuffixWithPath() { $app = new Application(); $app->routeMiddleware(['test' => LumenTestMiddleware::class]); $app->group(['suffix' => '/{format:json|xml}'], function ($app) { $app->get('/show/{id}', 'LumenTestController@show'); }); $response = $app->handle(Request::create('/show/test/json', 'GET')); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('test', $response->getContent()); }
/** * @param \Laravel\Lumen\Application $app */ public function buildToApp(Application $app) { $prefix = $this->_prefix . '/' . $this->_version; if ($prefix != '/') { $groupOptions = ['prefix' => $prefix, 'middleware' => $this->getMiddleware()]; $app->group($groupOptions, function () use($app) { $this->_buildRouteRules($app); }); } else { $this->_buildRouteRules($app); } }