Skip to content

Commit

Permalink
add option for specifying pattern as prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
iwyg committed Feb 21, 2016
1 parent 02ae1fb commit 72d826d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Loader/PhpLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ private function addRoutes(array $routes)
foreach ($routes as $name => $route) {
if ((bool)$gkeys = $this->getGroupKeys($route)) {
$req = isset($route['requirements']) ? $route['requirements'] : [];
if (null === $prefix = isset($route['pattern']) ? $route['pattern'] : $name) {
continue;
}
foreach ($gkeys as $i) {
$this->loadGroup($name, $req, $route[$i]);
$this->loadGroup($prefix, $req, $route[$i]);
}
continue;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Loader/Fixures/route_groups.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Lucid\Mux\RouteCollectionBuilder;

return [
'index' => [
'pattern' => '/',
'method' => 'GET',
'handler' => 'indexAction'
],
'backstage' => [
'pattern' => '/admin/area',
[
'users' => [
'pattern' => '/user/{id}',
'method' => 'GET',
'handler' => 'userAction'
]
]
]
];
6 changes: 6 additions & 0 deletions tests/Loader/PhpLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public function itShouldLoadGroups()

$this->assertNull($routes->get('users')->getHost());
$this->assertSame(['http', 'https'], $routes->get('users')->getSchemes());

$loader = new PhpLoader($this->mockLocator());
$routes = $loader->loadRoutes('route_groups.2.php');

$this->assertNull($routes->get('users')->getHost());
$this->assertSame(['http', 'https'], $routes->get('users')->getSchemes());
}

/** @test */
Expand Down

0 comments on commit 72d826d

Please sign in to comment.