Skip to content

Commit

Permalink
imported more changes from #11
Browse files Browse the repository at this point in the history
  • Loading branch information
akhumphrey committed Jul 2, 2024
1 parent 99124e8 commit 6edca7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/config/sfRoutingConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public function execute($configFiles)
$routes = $route instanceof sfRouteCollection ? $route : [$name => $route];
foreach (sfPatternRouting::flattenRoutes($routes) as $name => $route) {
$route->setDefaultOptions($options);
$data[] = sprintf('$this->routes[\'%s\'] = %s;', $name, var_export(serialize($route), true));
$data[] = sprintf('$this->routes[\'%s\'] = %s;', $name, var_export(json_encode($route), true));
}
}

return sprintf(
"<?php\n".
"// auto-generated by sfRoutingConfigHandler\n".
"// date: %s\n%s\n",
"// auto-generated by sfRoutingConfigHandler\n".
"// date: %s\n%s\n",
date('Y/m/d H:i:s'),
implode("\n", $data)
);
Expand Down
10 changes: 8 additions & 2 deletions lib/routing/sfPatternRouting.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@ public function getRoute($name)
$route = $this->routes[$name];

if (is_string($route)) {
$this->routes[$name] = $route = unserialize($route);
$route->setDefaultParameters($this->defaultParameters);
$decoded = json_decode($route, true);
$route = is_array($decoded) ? sfRoute::jsonUnserialize($decoded) : unserialize($route);

if (is_object($route) && method_exists($route, 'setDefaultParameters')) {
$route->setDefaultParameters($this->defaultParameters);
}

$this->routes[$name] = $route;
}

return $route;
Expand Down
22 changes: 12 additions & 10 deletions lib/routing/sfRoute.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,17 @@ public function unserialize($serialized)
public function jsonSerialize(): array
{
return [
'tokens' => $this->tokens,
'tokens' => $this->tokens,
'defaultOptions' => $this->defaultOptions,
'options' => $this->options,
'pattern' => $this->pattern,
'staticPrefix' => $this->staticPrefix,
'regex' => $this->regex,
'variables' => $this->variables,
'defaults' => $this->defaults,
'requirements' => $this->requirements,
'suffix' => $this->suffix,
'customToken' => $this->customToken,
'options' => $this->options,
'pattern' => $this->pattern,
'staticPrefix' => $this->staticPrefix,
'regex' => $this->regex,
'variables' => $this->variables,
'defaults' => $this->defaults,
'requirements' => $this->requirements,
'suffix' => $this->suffix,
'customToken' => $this->customToken,
];
}

Expand All @@ -474,6 +474,8 @@ public static function jsonUnserialize(array $raw): self

$rebuilt->compile();

$rebuilt->setDefaultOptions($raw['defaultOptions']);

return $rebuilt;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/storage/sfCacheSessionStorage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ public function initialize($options = [])
* If any are found, then also rebuilds the sfRoute object from the cached
* values and injects it back into the array.
*
* @param array $raw A dictionary of key => value pairs
* @param array $raw A dictionary of key => value pairs
*/
protected function upgradeNestedRouteObjects(array $raw): array
{
foreach ($raw as $key => $value) {
if (is_array($value)) {
if (
$key == 'route'
'route' == $key
&& isset(
$value['pattern'],
$value['defaults'],
Expand Down

0 comments on commit 6edca7e

Please sign in to comment.