-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Routing] Allow to set name prefixes from the configuration #25178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,19 @@ public function addPrefix($prefix, array $defaults = array(), array $requirement | |
} | ||
} | ||
|
||
/** | ||
* Add a prefix to the name of all the routes within in the collection. | ||
* | ||
* @param string $prefix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed |
||
*/ | ||
public function addNamePrefix(string $prefix) | ||
{ | ||
foreach ($this->routes as $name => $route) { | ||
$this->routes[$prefix.$name] = $route; | ||
unset($this->routes[$name]); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the host pattern on all routes. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<routes xmlns="http://symfony.com/schema/routing" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/routing | ||
http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
|
||
<import resource="../controller/routing.xml" /> | ||
<import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" /> | ||
|
||
</routes> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
app: | ||
resource: ../controller/routing.yml | ||
|
||
api: | ||
resource: ../controller/routing.yml | ||
name_prefix: api_ | ||
prefix: /api |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
someroute: | ||
resource: path/to/some.yml | ||
name_prefix: test_ | ||
not_valid_key: test_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ public function testAddDefaultsAndRequirementsAndOptions() | |
$collection->add('foo', new Route('/{placeholder}')); | ||
$collection1 = new RouteCollection(); | ||
$collection1->add('bar', new Route('/{placeholder}', | ||
array('_controller' => 'fixed', 'placeholder' => 'default'), array('placeholder' => '.+'), array('option' => 'value')) | ||
array('_controller' => 'fixed', 'placeholder' => 'default'), array('placeholder' => '.+'), array('option' => 'value')) | ||
); | ||
$collection->addCollection($collection1); | ||
|
||
|
@@ -302,4 +302,17 @@ public function testSetMethods() | |
$this->assertEquals(array('PUT'), $routea->getMethods()); | ||
$this->assertEquals(array('PUT'), $routeb->getMethods()); | ||
} | ||
|
||
public function testAddNamePrefix() | ||
{ | ||
$collection = new RouteCollection(); | ||
$collection->add('foo', $foo = new Route('/foo')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also add an existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, added. |
||
$collection->add('bar', $bar = new Route('/bar')); | ||
$collection->addNamePrefix('api_'); | ||
|
||
$this->assertEquals($foo, $collection->get('api_foo')); | ||
$this->assertEquals($bar, $collection->get('api_bar')); | ||
$this->assertNull($collection->get('foo')); | ||
$this->assertNull($collection->get('bar')); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds