From 25fdefd7e18515c27d91f35e78e64112ec5df266 Mon Sep 17 00:00:00 2001 From: tjbp Date: Tue, 20 Oct 2015 22:42:19 +0100 Subject: [PATCH] Filters deprecated in favour of middleware --- .../IlluminateRouteCollector.php | 75 +++---------------- src/LaravelDebugbar.php | 18 ----- src/Middleware/Debugbar.php | 5 ++ 3 files changed, 15 insertions(+), 83 deletions(-) diff --git a/src/DataCollector/IlluminateRouteCollector.php b/src/DataCollector/IlluminateRouteCollector.php index d2d629129..425dfa4de 100644 --- a/src/DataCollector/IlluminateRouteCollector.php +++ b/src/DataCollector/IlluminateRouteCollector.php @@ -54,7 +54,7 @@ protected function getRouteInformation($route) $result = array( 'uri' => $uri ?: '-', ); - + $result = array_merge($result, $action); @@ -73,82 +73,27 @@ protected function getRouteInformation($route) $filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/'); $result['file'] = $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine(); } - - if ($before = $this->getBeforeFilters($route)) { - $result['before'] = $before; - } - - if ($after = $this->getAfterFilters($route)) { - $result['after'] = $after; + + if ($middleware = $this->getMiddleware($route)) { + $result['middleware'] = $middleware; } - - return $result; - } - /** - * Get before filters - * - * @param \Illuminate\Routing\Route $route - * @return string - */ - protected function getBeforeFilters($route) - { - $before = array_keys($route->beforeFilters()); - $before = array_unique(array_merge($before, $this->getPatternFilters($route))); - return implode(', ', $before); + return $result; } - /* - * The following is copied/modified from the RoutesCommand from Laravel, by Taylor Otwell - * https://github.com/laravel/framework/blob/4.1/src/Illuminate/Foundation/Console/RoutesCommand.php - * - */ - /** - * Get all of the pattern filters matching the route. + * Get middleware * * @param \Illuminate\Routing\Route $route - * @return array - */ - protected function getPatternFilters($route) - { - $patterns = array(); - - foreach ($route->methods() as $method) { - // For each method supported by the route we will need to gather up the patterned - // filters for that method. We will then merge these in with the other filters - // we have already gathered up then return them back out to these consumers. - $inner = $this->getMethodPatterns($route->uri(), $method); - - $patterns = array_merge($patterns, array_keys($inner)); - } - - return $patterns; - } - - /** - * Get the pattern filters for a given URI and method. - * - * @param string $uri - * @param string $method - * @return array - */ - protected function getMethodPatterns($uri, $method) - { - return $this->router->findPatternFilters(Request::create($uri, $method)); - } - - /** - * Get after filters - * - * @param Route $route * @return string */ - protected function getAfterFilters($route) + protected function getMiddleware($route) { - return implode(', ', array_keys($route->afterFilters())); + $middleware = array_keys($route->middleware()); + + return implode(', ', $middleware); } /** diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php index 350fc6271..5a1041b44 100644 --- a/src/LaravelDebugbar.php +++ b/src/LaravelDebugbar.php @@ -141,24 +141,6 @@ function () use ($debugbar, $startTime) { } } ); - - //Check if App::before is already called.. - if ($this->app->isBooted()) { - $debugbar->startMeasure('application', 'Application'); - } else { - $this->app['router']->before( - function () use ($debugbar) { - $debugbar->startMeasure('application', 'Application'); - } - ); - } - - $this->app['router']->after( - function () use ($debugbar) { - $debugbar->stopMeasure('application'); - $debugbar->startMeasure('after', 'After application'); - } - ); } } diff --git a/src/Middleware/Debugbar.php b/src/Middleware/Debugbar.php index c0563b7b3..a23402912 100644 --- a/src/Middleware/Debugbar.php +++ b/src/Middleware/Debugbar.php @@ -44,6 +44,8 @@ public function handle($request, Closure $next) /** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */ $debugbar = $this->app['debugbar']; + $debugbar->startMeasure('application', 'Application'); + try { /** @var \Illuminate\Http\Response $response */ $response = $next($request); @@ -54,6 +56,9 @@ public function handle($request, Closure $next) $response = $this->exceptionHandler->render($request, $e); } + $debugbar->stopMeasure('application'); + $debugbar->startMeasure('after', 'After application'); + return $debugbar->modifyResponse($request, $response); }