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

This commit is contained in:
Soufian EZ ZANTAR 2018-11-18 18:32:00 +01:00 committed by Fabien Potencier
parent 737726516e
commit 92bdc9b5f4
12 changed files with 31 additions and 4 deletions

View File

@ -193,7 +193,7 @@ class JsonDescriptor extends Descriptor
*/
protected function getRouteData(Route $route)
{
return array(
$data = array(
'path' => $route->getPath(),
'pathRegex' => $route->compile()->getRegex(),
'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY',
@ -205,6 +205,12 @@ class JsonDescriptor extends Descriptor
'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

View File

@ -60,6 +60,10 @@ class MarkdownDescriptor extends Descriptor
."\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);

View File

@ -92,6 +92,10 @@ class TextDescriptor extends Descriptor
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();

View File

@ -215,6 +215,11 @@ class XmlDescriptor extends Descriptor
}
}
if ('' !== $route->getCondition()) {
$routeXML->appendChild($hostXML = $dom->createElement('condition'));
$hostXML->appendChild(new \DOMText($route->getCondition()));
}
return $dom;
}

View File

@ -53,7 +53,8 @@ class ObjectsProvider
array('opt1' => 'val1', 'opt2' => 'val2'),
'localhost',
array('http', 'https'),
array('put', 'post')
array('put', 'post'),
"context.getMethod() in ['GET', 'HEAD', 'POST']"
),
);
}

View File

@ -12,5 +12,6 @@
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
"opt1": "val1",
"opt2": "val2"
}
},
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
}

View File

@ -11,3 +11,4 @@
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
- `opt1`: val1
- `opt2`: val2
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']

View File

@ -14,4 +14,5 @@
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | opt1: val1 |
| | opt2: val2 |
| Condition | context.getMethod() in ['GET', 'HEAD', 'POST'] |
+--------------+-------------------------------------------------------------------+

View File

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

View File

@ -33,6 +33,7 @@
"compiler_class": "Symfony\\Component\\Routing\\RouteCompiler",
"opt1": "val1",
"opt2": "val2"
}
},
"condition": "context.getMethod() in ['GET', 'HEAD', 'POST']"
}
}

View File

@ -34,4 +34,5 @@ route_2
- `compiler_class`: Symfony\Component\Routing\RouteCompiler
- `opt1`: val1
- `opt2`: val2
- Condition: context.getMethod() in ['GET', 'HEAD', 'POST']

View File

@ -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>