8000 feature #29254 [FrameworkBundle] Added the condition routing option t… · symfony/symfony@90b6882 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90b6882

Browse files
committed
feature #29254 [FrameworkBundle] Added the condition routing option to the debug router command (soufianZantar)
This PR was squashed before being merged into the 4.3-dev branch (closes #29254). Discussion ---------- [FrameworkBundle] Added the condition routing option to the debug router command | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- required for new features --> <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> This PR will add the condition routing option to debug:router command, to show if a route have conditions or not and showing this conditions. Commits ------- 92bdc9b [FrameworkBundle] Added the condition routing option to the debug router command
2 parents 6c4ab89 + 92bdc9b commit 90b6882

File tree

12 files changed

+25
-4
lines changed

12 files changed

+25
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private function writeData(array $data, array $options)
193193
*/
194194
protected function getRouteData(Route $route)
195195
{
196-
return [
196+
$data = [
197197
'path' => $route->getPath(),
198198
'pathRegex' => $route->compile()->getRegex(),
199199
'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY',

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ protected function describeRoute(Route $route, array $options = [])
6060
."\n".'- Requirements: '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')
6161
."\n".'- Options: '.$this->formatRouterConfig($route->getOptions());
6262

63+
if ('' !== $route->getCondition()) {
64+
$output .= "\n".'- Condition: '.$route->getCondition();
65+
}
66+
6367
$this->write(isset($options['name'])
6468
? $options['name']."\n".str_repeat('-', \strlen($options['name']))."\n\n".$output
6569
: $output);

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ protected function describeRoute(Route $route, array $options = [])
9292
['Options', $this->formatRouterConfig($route->getOptions())],
9393
];
9494

95+
if ('' !== $route->getCondition()) {
96+
$tableRows[] = array('Condition', $route->getCondition());
97+
}
98+
9599
$table = new Table($this->getOutput());
96100
$table->setHeaders($tableHeaders)->setRows($tableRows);
97101
$table->render();

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ private function getRouteDocument(Route $route, string $name = null): \DOMDocume
215215
}
216216
}
217217

218+
if ('' !== $route->getCondition()) {
219+
$routeXML->appendChild($hostXML = $dom->createElement('condition'));
220+
$hostXML->appendChild(new \DOMText($route->getCondition()));
221+
}
222+
218223
return $dom;
219224
}
220225

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public static function getRoutes()
5353
['opt1' => 'val1', 'opt2' => 'val2'],
5454
'localhost',
5555
['http', 'https'],
56-
['put', 'post']
56+
['put', 'post'],
57+
"context.getMethod() in ['GET', 'HEAD', 'POST']"
5758
),
5859
];
5960
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
1313
"opt1": "val1",
1414
"opt2": "val2"
15-
}
15+
},
16+
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
1617
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
1212
- `opt1`: val1
1313
- `opt2`: val2
14+
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
1515
| | opt1: val1 |
1616
| | opt2: val2 |
17+
| Condition | context.getMethod() in ['GET', 'HEAD', 'POST'] |
1718
+--------------+-------------------------------------------------------------------+

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
<option key="opt1">val1</option>
1212
<option key="opt2">val2</option>
1313
</options>
14+
<condition>context.getMethod() in ['GET', 'HEAD', 'POST']</condition>
1415
</route>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
3434
"opt1": "val1",
3535
"opt2": "val2"
36-
}
36+
},
37+
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
3738
}
3839
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ route_2
3434
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
3535
- `opt1`: val1
3636
- `opt2`: val2
37+
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']
3738

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<option key="opt1">val1</option>
3232
<option key="opt2">val2</option>
3333
</options>
34+
<condition>context.getMethod() in ['GET', 'HEAD', 'POST']</condition>
3435
</route>
3536
</routes>

0 commit comments

Comments
 (0)
0