Skip to content

Commit 48b882a

Browse files
committed
Add _middleware to parse results.
1 parent 9d9e566 commit 48b882a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Routing/Route/Route.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ public function parse($url, $method = '')
486486
}
487487
}
488488
$route['_matchedRoute'] = $this->template;
489+
if (count($this->middleware) > 0) {
490+
$route['_middleware'] = $this->middleware;
491+
}
489492

490493
return $route;
491494
}

tests/TestCase/Routing/Route/RouteTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,26 @@ public function testParseWithPassDefaults()
10951095
$this->assertEquals($expected, $result);
10961096
}
10971097

1098+
/**
1099+
* Test that middleware is returned from parse()
1100+
*
1101+
* @return void
1102+
*/
1103+
public function testParseWithMiddleware()
1104+
{
1105+
$route = new Route('/:controller', ['action' => 'display', 'home']);
1106+
$route->setMiddleware(['auth', 'cookie']);
1107+
$result = $route->parse('/posts', 'GET');
1108+
$expected = [
1109+
'controller' => 'posts',
1110+
'action' => 'display',
1111+
'pass' => ['home'],
1112+
'_matchedRoute' => '/:controller',
1113+
'_middleware' => ['auth', 'cookie'],
1114+
];
1115+
$this->assertEquals($expected, $result);
1116+
}
1117+
10981118
/**
10991119
* Test that http header conditions can cause route failures.
11001120
*

0 commit comments

Comments
 (0)