Skip to content

Commit 7a298d4

Browse files
committed
Merge pull request barryvdh#407 from tjbp/middleware-fix
Filters deprecated in favour of middleware
2 parents 866806c + 25fdefd commit 7a298d4

File tree

3 files changed

+15
-83
lines changed

3 files changed

+15
-83
lines changed

src/DataCollector/IlluminateRouteCollector.php

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function getRouteInformation($route)
5454
$result = array(
5555
'uri' => $uri ?: '-',
5656
);
57-
57+
5858
$result = array_merge($result, $action);
5959

6060

@@ -73,82 +73,27 @@ protected function getRouteInformation($route)
7373
$filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
7474
$result['file'] = $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine();
7575
}
76-
77-
if ($before = $this->getBeforeFilters($route)) {
78-
$result['before'] = $before;
79-
}
80-
81-
if ($after = $this->getAfterFilters($route)) {
82-
$result['after'] = $after;
76+
77+
if ($middleware = $this->getMiddleware($route)) {
78+
$result['middleware'] = $middleware;
8379
}
84-
85-
return $result;
86-
}
8780

88-
/**
89-
* Get before filters
90-
*
91-
* @param \Illuminate\Routing\Route $route
92-
* @return string
93-
*/
94-
protected function getBeforeFilters($route)
95-
{
96-
$before = array_keys($route->beforeFilters());
9781

98-
$before = array_unique(array_merge($before, $this->getPatternFilters($route)));
9982

100-
return implode(', ', $before);
83+
return $result;
10184
}
10285

103-
/*
104-
* The following is copied/modified from the RoutesCommand from Laravel, by Taylor Otwell
105-
* https://github.com/laravel/framework/blob/4.1/src/Illuminate/Foundation/Console/RoutesCommand.php
106-
*
107-
*/
108-
10986
/**
110-
* Get all of the pattern filters matching the route.
87+
* Get middleware
11188
*
11289
* @param \Illuminate\Routing\Route $route
113-
* @return array
114-
*/
115-
protected function getPatternFilters($route)
116-
{
117-
$patterns = array();
118-
119-
foreach ($route->methods() as $method) {
120-
// For each method supported by the route we will need to gather up the patterned
121-
// filters for that method. We will then merge these in with the other filters
122-
// we have already gathered up then return them back out to these consumers.
123-
$inner = $this->getMethodPatterns($route->uri(), $method);
124-
125-
$patterns = array_merge($patterns, array_keys($inner));
126-
}
127-
128-
return $patterns;
129-
}
130-
131-
/**
132-
* Get the pattern filters for a given URI and method.
133-
*
134-
* @param string $uri
135-
* @param string $method
136-
* @return array
137-
*/
138-
protected function getMethodPatterns($uri, $method)
139-
{
140-
return $this->router->findPatternFilters(Request::create($uri, $method));
141-
}
142-
143-
/**
144-
* Get after filters
145-
*
146-
* @param Route $route
14790
* @return string
14891
*/
149-
protected function getAfterFilters($route)
92+
protected function getMiddleware($route)
15093
{
151-
return implode(', ', array_keys($route->afterFilters()));
94+
$middleware = array_keys($route->middleware());
95+
96+
return implode(', ', $middleware);
15297
}
15398

15499
/**

src/LaravelDebugbar.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,6 @@ function () use ($debugbar, $startTime) {
141141
}
142142
}
143143
);
144-
145-
//Check if App::before is already called..
146-
if ($this->app->isBooted()) {
147-
$debugbar->startMeasure('application', 'Application');
148-
} else {
149-
$this->app['router']->before(
150-
function () use ($debugbar) {
151-
$debugbar->startMeasure('application', 'Application');
152-
}
153-
);
154-
}
155-
156-
$this->app['router']->after(
157-
function () use ($debugbar) {
158-
$debugbar->stopMeasure('application');
159-
$debugbar->startMeasure('after', 'After application');
160-
}
161-
);
162144
}
163145

164146
}

src/Middleware/Debugbar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function handle($request, Closure $next)
4444
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
4545
$debugbar = $this->app['debugbar'];
4646

47+
$debugbar->startMeasure('application', 'Application');
48+
4749
try {
4850
/** @var \Illuminate\Http\Response $response */
4951
$response = $next($request);
@@ -54,6 +56,9 @@ public function handle($request, Closure $next)
5456
$response = $this->exceptionHandler->render($request, $e);
5557
}
5658

59+
$debugbar->stopMeasure('application');
60+
$debugbar->startMeasure('after', 'After application');
61+
5762
return $debugbar->modifyResponse($request, $response);
5863

5964
}

0 commit comments

Comments
 (0)