Skip to content

Commit f09893b

Browse files
Dan Wilgafabpot
authored andcommitted
[Routing] Revert the change in [#b42018] with respect to Routing/Route.php
1 parent 7fc2552 commit f09893b

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

src/Symfony/Component/Routing/Route.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ public function serialize()
116116
*/
117117
public function unserialize($serialized)
118118
{
119-
if (\PHP_VERSION_ID >= 70000) {
120-
$data = unserialize($serialized, array('allowed_classes' => array(CompiledRoute::class)));
121-
} else {
122-
$data = unserialize($serialized);
123-
}
119+
$data = unserialize($serialized);
124120
$this->path = $data['path'];
125121
$this->host = $data['host'];
126122
$this->defaults = $data['defaults'];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\Fixtures;
13+
14+
use Symfony\Component\Routing\CompiledRoute;
15+
16+
class CustomCompiledRoute extends CompiledRoute
17+
{
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\Fixtures;
13+
14+
use Symfony\Component\Routing\Route;
15+
use Symfony\Component\Routing\RouteCompiler;
16+
17+
class CustomRouteCompiler extends RouteCompiler
18+
{
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
public static function compile(Route $route)
23+
{
24+
return new CustomCompiledRoute('', '', array(), array());
25+
}
26+
}

src/Symfony/Component/Routing/Tests/RouteTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ public function testSerializeWhenCompiled()
220220
$this->assertNotSame($route, $unserialized);
221221
}
222222

223+
/**
224+
* Tests that unserialization does not fail when the compiled Route is of a
225+
* class other than CompiledRoute, such as a subclass of it.
226+
*/
227+
public function testSerializeWhenCompiledWithClass()
228+
{
229+
$route = new Route('/', array(), array(), array('compiler_class' => '\Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler'));
230+
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $route->compile(), '->compile() returned a proper route');
231+
232+
$serialized = serialize($route);
233+
try {
234+
$unserialized = unserialize($serialized);
235+
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully');
236+
} catch (\Exception $e) {
237+
$this->fail('unserializing a route which uses a custom compiled route class');
238+
}
239+
}
240+
223241
/**
224242
* Tests that the serialized representation of a route in one symfony version
225243
* also works in later symfony versions, i.e. the unserialized route is in the

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