[Routing] Revert the change in [#b42018] with respect to Routing/Route.php

This commit is contained in:
Dan Wilga 2017-06-09 15:14:01 -04:00 committed by Fabien Potencier
parent 7fc255218e
commit f09893bed4
4 changed files with 63 additions and 5 deletions

View File

@ -116,11 +116,7 @@ class Route implements \Serializable
*/
public function unserialize($serialized)
{
if (\PHP_VERSION_ID >= 70000) {
$data = unserialize($serialized, array('allowed_classes' => array(CompiledRoute::class)));
} else {
$data = unserialize($serialized);
}
$data = unserialize($serialized);
$this->path = $data['path'];
$this->host = $data['host'];
$this->defaults = $data['defaults'];

View File

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures;
use Symfony\Component\Routing\CompiledRoute;
class CustomCompiledRoute extends CompiledRoute
{
}

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCompiler;
class CustomRouteCompiler extends RouteCompiler
{
/**
* {@inheritdoc}
*/
public static function compile(Route $route)
{
return new CustomCompiledRoute('', '', array(), array());
}
}

View File

@ -220,6 +220,24 @@ class RouteTest extends TestCase
$this->assertNotSame($route, $unserialized);
}
/**
* Tests that unserialization does not fail when the compiled Route is of a
* class other than CompiledRoute, such as a subclass of it.
*/
public function testSerializeWhenCompiledWithClass()
{
$route = new Route('/', array(), array(), array('compiler_class' => '\Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler'));
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $route->compile(), '->compile() returned a proper route');
$serialized = serialize($route);
try {
$unserialized = unserialize($serialized);
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully');
} catch (\Exception $e) {
$this->fail('unserializing a route which uses a custom compiled route class');
}
}
/**
* Tests that the serialized representation of a route in one symfony version
* also works in later symfony versions, i.e. the unserialized route is in the