Skip to content

Commit c97a98d

Browse files
author
Jules Pietri
committed
[Routing] Exposed "compiler_class" and "utf8" options in configuration
1 parent 6fd6b94 commit c97a98d

File tree

14 files changed

+216
-1
lines changed

14 files changed

+216
-1
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

Lines 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

Lines 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 compiled 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

Lines 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

Lines changed: 15 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,13 @@ 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+
}
134+
unset($config['controller'], $config['compiler_class'], $config['utf8']);
128135

129136
if (\is_array($config['path'])) {
130137
$route = new Route('', $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
@@ -166,6 +173,13 @@ protected function parseImport(RouteCollection $collection, array $config, $path
166173
if (isset($config['controller'])) {
167174
$defaults['_controller'] = $config['controller'];
168175
}
176+
if (isset($config['compiler_class'])) {
177+
$options['compiler_class'] = $config['compiler_class'];
178+
}
179+
if (isset($config['utf8'])) {
180+
$options['utf8'] = $config['utf8'];
181+
}
182+
unset($config['controller'], $config['compiler_class'], $config['utf8']);
169183

170184
$this->setCurrentDir(\dirname($path));
171185

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

Lines 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">
Lines 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+
};
Lines 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>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
some_route:
2+
path: /
3+
4+
custom_compiled_route:
5+
path: /custom-compilation
6+
compiler_class: 'Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Loader\Configurator;
4+
5+
return function (RoutingConfigurator $routes) {
6+
$routes
7+
->add('some_route', '/')
8+
->add('some_utf8_route', '/utf8')->utf8()
9+
;
10+
};
Lines 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="some_utf8_route" path="/utf8" utf8="true"/>
8+
</routes>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy