Skip to content

Commit

Permalink
Merge pull request barryvdh#407 from tjbp/middleware-fix
Browse files Browse the repository at this point in the history
Filters deprecated in favour of middleware
  • Loading branch information
barryvdh committed Dec 21, 2015
2 parents 866806c + 25fdefd commit 7a298d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 83 deletions.
75 changes: 10 additions & 65 deletions src/DataCollector/IlluminateRouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function getRouteInformation($route)
$result = array(
'uri' => $uri ?: '-',
);

$result = array_merge($result, $action);


Expand All @@ -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);
}

/**
Expand Down
18 changes: 0 additions & 18 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
);
}

}
Expand Down
5 changes: 5 additions & 0 deletions src/Middleware/Debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

}
Expand Down

0 comments on commit 7a298d4

Please sign in to comment.