Skip to content

[FrameworkBundle] Added the condition routing option to the debug router command #29254

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private function writeData(array $data, array $options)
*/
protected function getRouteData(Route $route)
{
return array(
$data = array(
'path' => $route->getPath(),
'pathRegex' => $route->compile()->getRegex(),
'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY',
Expand All @@ -205,6 +205,12 @@ protected function getRouteData(Route $route)
'requirements' => $route->getRequirements() ?: 'NO CUSTOM',
'options' => $route->getOptions(),
);

if ('' !== $route->getCondition()) {
$data['condition'] = $route->getCondition();
}

return $data;
}

private function getContainerDefinitionData(Definition $definition, bool $omitTags = false, bool $showArguments = false): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ protected function describeRoute(Route $route, array $options = array())
."\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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ protected function describeRoute(Route $route, array $options = array())
array('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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static function getRoutes()
array('opt1' => 'val1', 'opt2' => 'val2'),
'localhost',
array('http', 'https'),
array('put', 'post')
array('put', 'post'),
"context.getMethod() in ['GET', 'HEAD', 'POST']"
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
"opt1": "val1",
"opt2": "val2"
}
},
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
- `opt1`: val1
- `opt2`: val2
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | opt1: val1 |
| | opt2: val2 |
| Condition | context.getMethod() in ['GET', 'HEAD', 'POST'] |
+--------------+-------------------------------------------------------------------+
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<option key="opt1">val1</option>
<option key="opt2">val2</option>
</options>
<condition>context.getMethod() in ['GET', 'HEAD', 'POST']</condition>
</route>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
"opt1": "val1",
"opt2": "val2"
}
},
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ route_2
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
- `opt1`: val1
- `opt2`: val2
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']

Original file line number Diff line number Diff line change
Expand Up @@ -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>