8000 merged branch vicb/fmwkrouter (PR #5971) · symfony/symfony@262049b · GitHub
[go: up one dir, main page]

Skip to content

Commit 262049b

Browse files
committed
merged branch vicb/fmwkrouter (PR #5971)
This PR was merged into the master branch. Commits ------- fc300ec [FrameworkBundle] Router class tweak Discussion ---------- [FrameworkBundle] Router class tweak
2 parents 228c9e6 + fc300ec commit 262049b

File tree

1 file changed

+12
-11
lines changed
  • src/Symfony/Bundle/FrameworkBundle/Routing

1 file changed

+12
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,45 @@ private function resolveParameters(RouteCollection $collection)
8888
$this->resolveParameters($route);
8989
} else {
9090
foreach ($route->getDefaults() as $name => $value) {
91-
$route->setDefault($name, $this->resolveString($value));
91+
$route->setDefault($name, $this->resolve($value));
9292
}
9393

9494
foreach ($route->getRequirements() as $name => $value) {
95-
$route->setRequirement($name, $this->resolveString($value));
95+
$route->setRequirement($name, $this->resolve($value));
9696
}
9797

98-
$route->setPattern($this->resolveString($route->getPattern()));
98+
$route->setPattern($this->resolve($route->getPattern()));
9999
}
100100
}
101101
}
102102

103103
/**
104-
* Replaces placeholders with the service container parameters in the given string.
104+
* Recursively replaces placeholders with the service container parameters.
105105
*
106-
* @param mixed $value The source string which might contain %placeholders%
106+
* @param mixed $value The source which might contain "%placeholders%"
107107
*
108-
* @return mixed A string where the placeholders have been replaced, or the original value if not a string.
108+
* @return mixed The source with the placeholders replaced by the container
109+
* parameters. Array are resolved recursively.
109110
*
110111
* @throws ParameterNotFoundException When a placeholder does not exist as a container parameter
111112
* @throws RuntimeException When a container value is not a string or a numeric value
112113
*/
113-
private function resolveString($value)
114+
private function resolve($value)
114115
{
115-
$container = $this->container;
116-
117116
if (is_array($value)) {
118117
foreach ($value as $key => $val) {
119-
$value[$key] = $this->resolveString($val);
118+
$value[$key] = $this->resolve($val);
120119
}
121120

122121
return $value;
123122
}
124123

125-
if (null === $value || false === $value || true === $value || is_object($value)) {
124+
if (!is_string($value)) {
126125
return $value;
127126
}
128127

128+
$container = $this->container;
129+
129130
$escapedValue = preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($container, $value) {
130131
// skip %%
131132
if (!isset($match[1])) {

0 commit comments

Comments
 (0)
0