Skip to content
Permalink
Browse files

feature #29254 [FrameworkBundle] Added the condition routing option t…

…o 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
  • Loading branch information...
fabpot committed Mar 4, 2019
2 parents 6c4ab89 + 92bdc9b commit 90b68826e94e65b1410215ba1badf09f9b45b682
@@ -193,7 +193,7 @@ private function writeData(array $data, array $options)
*/
protected function getRouteData(Route $route)
{
return [
$data = [
'path' => $route->getPath(),
'pathRegex' => $route->compile()->getRegex(),
'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY',
@@ -60,6 +60,10 @@ protected function describeRoute(Route $route, array $options = [])
."\n".'- Requirements: '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')
."\n".'- Options: '.$this->formatRouterConfig($route->getOptions());
if ('' !== $route->getCondition()) {
$output .= "\n".'- Condition: '.$route->getCondition();
}
$this->write(isset($options['name'])
? $options['name']."\n".str_repeat('-', \strlen($options['name']))."\n\n".$output
: $output);
@@ -92,6 +92,10 @@ protected function describeRoute(Route $route, array $options = [])
['Options', $this->formatRouterConfig($route->getOptions())],
];
if ('' !== $route->getCondition()) {
$tableRows[] = array('Condition', $route->getCondition());
}
$table = new Table($this->getOutput());
$table->setHeaders($tableHeaders)->setRows($tableRows);
$table->render();
@@ -215,6 +215,11 @@ private function getRouteDocument(Route $route, string $name = null): \DOMDocume
}
}
if ('' !== $route->getCondition()) {
$routeXML->appendChild($hostXML = $dom->createElement('condition'));
$hostXML->appendChild(new \DOMText($route->getCondition()));
}
return $dom;
}
@@ -53,7 +53,8 @@ public static function getRoutes()
['opt1' => 'val1', 'opt2' => 'val2'],
'localhost',
['http', 'https'],
['put', 'post']
['put', 'post'],
"context.getMethod() in ['GET', 'HEAD', 'POST']"
),
];
}
@@ -12,5 +12,6 @@
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
"opt1": "val1",
"opt2": "val2"
}
},
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
}
@@ -11,3 +11,4 @@
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
- `opt1`: val1
- `opt2`: val2
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']
@@ -14,4 +14,5 @@
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | opt1: val1 |
| | opt2: val2 |
| Condition | context.getMethod() in ['GET', 'HEAD', 'POST'] |
+--------------+-------------------------------------------------------------------+
@@ -11,4 +11,5 @@
<option key="opt1">val1</option>
<option key="opt2">val2</option>
</options>
<condition>context.getMethod() in ['GET', 'HEAD', 'POST']</condition>
</route>
@@ -33,6 +33,7 @@
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
"opt1": "val1",
"opt2": "val2"
}
},
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
}
}
@@ -34,4 +34,5 @@ route_2
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
- `opt1`: val1
- `opt2`: val2
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']

@@ -31,5 +31,6 @@
<option key="opt1">val1</option>
<option key="opt2">val2</option>
</options>
<condition>context.getMethod() in ['GET', 'HEAD', 'POST']</condition>
</route>
</routes>

0 comments on commit 90b6882

Please sign in to comment.
You can’t perform that action at this time.