Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3cf520a

Browse filesBrowse files
author
Jules Pietri
committed
[Routing] Exposed "compiler_class" and "utf8" options in configuration
1 parent 4619ae4 commit 3cf520a
Copy full SHA for 3cf520a
Expand file treeCollapse file tree

18 files changed

+296
-1
lines changed

‎src/Symfony/Component/Routing/Annotation/Route.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Annotation/Route.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public function __construct(array $data)
5353
unset($data['path']);
5454
}
5555

56+
if (isset($data['compilerClass'])) {
57+
$data['options']['compiler_class'] = $data['compilerClass'];
58+
unset($data['compilerClass']);
59+
}
60+
61+
if (isset($data['utf8'])) {
62+
$data['options']['utf8'] = filter_var($data['utf8'], FILTER_VALIDATE_BOOLEAN) ?: false;
63+
unset($data['utf8']);
64+
}
65+
5666
foreach ($data as $key => $value) {
5767
$method = 'set'.str_replace('_', '', $key);
5868
if (!method_exists($this, $method)) {

‎src/Symfony/Component/Routing/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* deprecated `generator_base_class`, `generator_cache_class`, `matcher_base_class` and `matcher_cache_class` router options
1111
* deprecated implementing `Serializable` for `Route` and `CompiledRoute`; if you serialize them, please
1212
ensure your unserialization logic can recover from a failure related to an updated serialization format
13+
* exposed `compiler_class` and `utf8` Route options in configuration loaders and configurators
1314

1415
4.2.0
1516
-----

‎src/Symfony/Component/Routing/Loader/Configurator/Traits/RouteTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/Configurator/Traits/RouteTrait.php
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ final public function options(array $options)
5757
return $this;
5858
}
5959

60+
/**
61+
* Defines the compiler class used to compile the Route.
62+
*
63+
* @return $this
64+
*/
65+
final public function compilerClass(string $class)
66+
{
67+
$this->route->addOptions(['compiler_class' => $class]);
68+
69+
return $this;
70+
}
71+
72+
/**
73+
* Whether paths should accept utf8 encoding.
74+
*
75+
* @return $this
76+
*/
77+
final public function utf8(bool $utf8 = true)
78+
{
79+
$this->route->addOptions(['utf8' => $utf8]);
80+
81+
return $this;
82+
}
83+
6084
/**
6185
* Sets the condition.
6286
*

‎src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/XmlFileLoader.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ private function parseConfigs(\DOMElement $node, $path)
311311

312312
$defaults['_controller'] = $controller;
313313
}
314+
if ($node->hasAttribute('compiler-class')) {
315+
$options['compiler_class'] = trim($node->getAttribute('compiler-class'));
316+
}
317+
if ($node->hasAttribute('utf8')) {
318+
$options['utf8'] = XmlUtils::phpize($node->getAttribute('utf8'));
319+
}
314320

315321
return [$defaults, $requirements, $options, $condition, $paths, $prefixes];
316322
}

‎src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/YamlFileLoader.php
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class YamlFileLoader extends FileLoader
2929
{
3030
private static $availableKeys = [
31-
'resource', 'type', 'prefix', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition', 'controller', 'name_prefix', 'trailing_slash_on_root',
31+
'resource', 'type', 'prefix', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition', 'controller', 'name_prefix', 'trailing_slash_on_root', 'compiler_class', 'utf8',
3232
];
3333
private $yamlParser;
3434

@@ -125,6 +125,12 @@ protected function parseRoute(RouteCollection $collection, $name, array $config,
125125
if (isset($config['controller'])) {
126126
$defaults['_controller'] = $config['controller'];
127127
}
128+
if (isset($config['compiler_class'])) {
129+
$options['compiler_class'] = $config['compiler_class'];
130+
}
131+
if (isset($config['utf8'])) {
132+
$options['utf8'] = $config['utf8'];
133+
}
128134

129135
if (\is_array($config['path'])) {
130136
$route = new Route('', $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
@@ -166,6 +172,12 @@ protected function parseImport(RouteCollection $collection, array $config, $path
166172
if (isset($config['controller'])) {
167173
$defaults['_controller'] = $config['controller'];
168174
}
175+
if (isset($config['compiler_class'])) {
176+
$options['compiler_class'] = $config['compiler_class'];
177+
}
178+
if (isset($config['utf8'])) {
179+
$options['utf8'] = $config['utf8'];
180+
}
169181

170182
$this->setCurrentDir(\dirname($path));
171183

‎src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
<xsd:attribute name="schemes" type="xsd:string" />
5353
<xsd:attribute name="methods" type="xsd:string" />
5454
<xsd:attribute name="controller" type="xsd:string" />
55+
<xsd:attribute name="compiler-class" type="xsd:string" />
56+
<xsd:attribute name="utf8" type="xsd:boolean" />
5557
</xsd:complexType>
5658

5759
<xsd:complexType name="import">
@@ -68,6 +70,8 @@
6870
<xsd:attribute name="methods" type="xsd:string" />
6971
<xsd:attribute name="controller" type="xsd:string" />
7072
<xsd:attribute name="trailing-slash-on-root" type="xsd:boolean" />
73+
<xsd:attribute name="compiler-class" type="xsd:string" />
74+
<xsd:attribute name="uft8" type="xsd:boolean" />
7175
</xsd:complexType>
7276

7377
<xsd:complexType name="default" mixed="true">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures;
4+
5+
use Symfony\Component\Routing\Annotation\Route;
6+
use Symfony\Component\Routing\RouteCompiler;
7+
use Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler;
8+
9+
/**
10+
* @Route("/test", compilerClass=CustomRouteCompiler::class)
11+
*/
12+
class CustomCompilerClassActionControllers
13+
{
14+
/**
15+
* @Route(name="one")
16+
*/
17+
public function one()
18+
{
19+
}
20+
21+
/**
22+
* @Route(name="two", compilerClass=RouteCompiler::class)
23+
*/
24+
public function two()
25+
{
26+
}
27+
}
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures;
4+
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
/**
8+
* @Route("/test", utf8=true)
9+
*/
10+
class Utf8ActionControllers
11+
{
12+
/**
13+
* @Route(name="one")
14+
*/
15+
public function one()
16+
{
17+
}
18+
19+
/**
20+
* @Route(name="two", utf8=false)
21+
*/
22+
public function two()
23+
{
24+
}
25+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Loader\Configurator;
4+
5+
use Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler;
6+
7+
return function (RoutingConfigurator $routes) {
8+
$routes
9+
->add('some_route', '/')
10+
->add('custom_compiled_route', '/custom-compilation')->compilerClass(CustomRouteCompiler::class)
11+
;
12+
};
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing">
5+
6+
<route id="some_route" path="/" />
7+
<route id="custom_compiled_route" path="/custom-compilation" compiler-class="Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler"/>
8+
</routes>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.