Skip to content

Commit e7da424

Browse files
committed
Added a patterns method to the router
1 parent 262c16e commit e7da424

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Illuminate/Routing/Router.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,20 @@ public function pattern($key, $pattern)
12151215
$this->patterns[$key] = $pattern;
12161216
}
12171217

1218+
/**
1219+
* Set a group of global where patterns on all routes
1220+
*
1221+
* @param array $patterns
1222+
* @return void
1223+
*/
1224+
public function patterns($patterns)
1225+
{
1226+
foreach ($patterns as $key => $pattern)
1227+
{
1228+
$this->pattern($key, $pattern);
1229+
}
1230+
}
1231+
12181232
/**
12191233
* Call the given filter with the request and response.
12201234
*
@@ -1642,4 +1656,11 @@ public function handle(SymfonyRequest $request, $type = HttpKernelInterface::MAS
16421656
return $this->dispatch(Request::createFromBase($request));
16431657
}
16441658

1659+
/**
1660+
* Get the global where patterns associated with this Router
1661+
* @return array
1662+
*/
1663+
public function getPatterns() {
1664+
return $this->patterns;
1665+
}
16451666
}

tests/Routing/RoutingRouteTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,18 @@ public function testRouterFiresRoutedEvent()
722722
}
723723

724724

725+
public function testRouterPatternSetting()
726+
{
727+
$router = $this->getRouter();
728+
$router->pattern('test', 'pattern');
729+
$this->assertEquals(array('test' => 'pattern'), $router->getPatterns());
730+
731+
$router = $this->getRouter();
732+
$router->patterns(array('test' => 'pattern', 'test2' => 'pattern2'));
733+
$this->assertEquals(array('test' => 'pattern', 'test2' => 'pattern2'), $router->getPatterns());
734+
}
735+
736+
725737
protected function getRouter()
726738
{
727739
return new Router(new Illuminate\Events\Dispatcher);

0 commit comments

Comments
 (0)