[HttpKernel] Dont register env parameter resource

This commit is contained in:
Roland Franssen 2017-09-01 18:34:37 +02:00
parent 1cad4696da
commit 36d2a45d1d
4 changed files with 0 additions and 246 deletions

View File

@ -1,97 +0,0 @@
<?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\HttpKernel\Config;
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
/**
* EnvParametersResource represents resources stored in prefixed environment variables.
*
* @author Chris Wilkinson <chriswilkinson84@gmail.com>
*
* @deprecated since version 3.4, to be removed in 4.0
*/
class EnvParametersResource implements SelfCheckingResourceInterface, \Serializable
{
/**
* @var string
*/
private $prefix;
/**
* @var string
*/
private $variables;
/**
* Constructor.
*
* @param string $prefix
*/
public function __construct($prefix)
{
$this->prefix = $prefix;
$this->variables = $this->findVariables();
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return serialize($this->getResource());
}
/**
* @return array An array with two keys: 'prefix' for the prefix used and 'variables' containing all the variables watched by this resource
*/
public function getResource()
{
return array('prefix' => $this->prefix, 'variables' => $this->variables);
}
/**
* {@inheritdoc}
*/
public function isFresh($timestamp)
{
return $this->findVariables() === $this->variables;
}
public function serialize()
{
return serialize(array('prefix' => $this->prefix, 'variables' => $this->variables));
}
public function unserialize($serialized)
{
$unserialized = unserialize($serialized, array('allowed_classes' => false));
$this->prefix = $unserialized['prefix'];
$this->variables = $unserialized['variables'];
}
private function findVariables()
{
$variables = array();
foreach ($_SERVER as $key => $value) {
if (0 === strpos($key, $this->prefix)) {
$variables[$key] = $value;
}
}
ksort($variables);
return $variables;
}
}

View File

@ -26,7 +26,6 @@ use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
@ -625,7 +624,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
}
$container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));
$container->addResource(new EnvParametersResource('SYMFONY__'));
return $container;
}

View File

@ -1,110 +0,0 @@
<?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\HttpKernel\Tests\Config;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
/**
* @group legacy
*/
class EnvParametersResourceTest extends TestCase
{
protected $prefix = '__DUMMY_';
protected $initialEnv;
protected $resource;
protected function setUp()
{
$this->initialEnv = array(
$this->prefix.'1' => 'foo',
$this->prefix.'2' => 'bar',
);
foreach ($this->initialEnv as $key => $value) {
$_SERVER[$key] = $value;
}
$this->resource = new EnvParametersResource($this->prefix);
}
protected function tearDown()
{
foreach ($_SERVER as $key => $value) {
if (0 === strpos($key, $this->prefix)) {
unset($_SERVER[$key]);
}
}
}
public function testGetResource()
{
$this->assertSame(
array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
$this->resource->getResource(),
'->getResource() returns the resource'
);
}
public function testToString()
{
$this->assertSame(
serialize(array('prefix' => $this->prefix, 'variables' => $this->initialEnv)),
(string) $this->resource
);
}
public function testIsFreshNotChanged()
{
$this->assertTrue(
$this->resource->isFresh(time()),
'->isFresh() returns true if the variables have not changed'
);
}
public function testIsFreshValueChanged()
{
reset($this->initialEnv);
$_SERVER[key($this->initialEnv)] = 'baz';
$this->assertFalse(
$this->resource->isFresh(time()),
'->isFresh() returns false if a variable has been changed'
);
}
public function testIsFreshValueRemoved()
{
reset($this->initialEnv);
unset($_SERVER[key($this->initialEnv)]);
$this->assertFalse(
$this->resource->isFresh(time()),
'->isFresh() returns false if a variable has been removed'
);
}
public function testIsFreshValueAdded()
{
$_SERVER[$this->prefix.'3'] = 'foo';
$this->assertFalse(
$this->resource->isFresh(time()),
'->isFresh() returns false if a variable has been added'
);
}
public function testSerializeUnserialize()
{
$this->assertEquals($this->resource, unserialize(serialize($this->resource)));
}
}

View File

@ -16,7 +16,6 @@ use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
@ -104,42 +103,6 @@ class KernelTest extends TestCase
$kernel->boot();
}
public function testEnvParametersResourceIsAdded()
{
$container = new ContainerBuilder();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->disableOriginalConstructor()
->setMethods(array('getContainerBuilder', 'prepareContainer', 'getCacheDir', 'getLogDir'))
->getMock();
$kernel->expects($this->any())
->method('getContainerBuilder')
->will($this->returnValue($container));
$kernel->expects($this->any())
->method('prepareContainer')
->will($this->returnValue(null));
$kernel->expects($this->any())
->method('getCacheDir')
->will($this->returnValue(sys_get_temp_dir()));
$kernel->expects($this->any())
->method('getLogDir')
->will($this->returnValue(sys_get_temp_dir()));
$reflection = new \ReflectionClass(get_class($kernel));
$method = $reflection->getMethod('buildContainer');
$method->setAccessible(true);
$method->invoke($kernel);
$found = false;
foreach ($container->getResources() as $resource) {
if ($resource instanceof EnvParametersResource) {
$found = true;
break;
}
}
$this->assertTrue($found);
}
public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));