Merge branch '3.3' into 3.4
* 3.3: [Config] Fix dumped files invalidation by OPCache [DI] Allow setting any public non-initialized services
This commit is contained in:
commit
d6b68e19e5
@ -132,6 +132,10 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
|||||||
// discard chmod failure (some filesystem may not support it)
|
// discard chmod failure (some filesystem may not support it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\function_exists('opcache_invalidate') && ini_get('opcache.enable')) {
|
||||||
|
@opcache_invalidate($this->file, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,6 +183,7 @@ class Container implements ResettableContainerInterface
|
|||||||
unset($this->aliases[$id]);
|
unset($this->aliases[$id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$wasSet = isset($this->services[$id]);
|
||||||
$this->services[$id] = $service;
|
$this->services[$id] = $service;
|
||||||
|
|
||||||
if (null === $service) {
|
if (null === $service) {
|
||||||
@ -196,11 +197,11 @@ class Container implements ResettableContainerInterface
|
|||||||
} else {
|
} else {
|
||||||
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
} elseif (isset($this->fileMap[$id]) || isset($this->methodMap[$id])) {
|
} elseif ($wasSet && (isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
|
||||||
if (null === $service) {
|
if (null === $service) {
|
||||||
@trigger_error(sprintf('Unsetting the "%s" pre-defined service is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Unsetting the "%s" service after it\'s been initialized is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
|
||||||
} else {
|
} else {
|
||||||
@trigger_error(sprintf('Setting the "%s" pre-defined service is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Setting the "%s" service after it\'s been initialized is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,15 +196,29 @@ class ContainerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Unsetting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
* @expectedDeprecation Unsetting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
||||||
*/
|
*/
|
||||||
public function testSetWithNullResetPredefinedService()
|
public function testSetWithNullOnInitializedPredefinedService()
|
||||||
{
|
{
|
||||||
$sc = new Container();
|
$sc = new Container();
|
||||||
$sc->set('foo', new \stdClass());
|
$sc->set('foo', new \stdClass());
|
||||||
$sc->set('foo', null);
|
$sc->set('foo', null);
|
||||||
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
||||||
|
|
||||||
|
$sc = new ProjectServiceContainer();
|
||||||
|
$sc->get('bar');
|
||||||
|
$sc->set('bar', null);
|
||||||
|
$this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetWithNullOnUninitializedPredefinedService()
|
||||||
|
{
|
||||||
|
$sc = new Container();
|
||||||
|
$sc->set('foo', new \stdClass());
|
||||||
|
$sc->get('foo', null);
|
||||||
|
$sc->set('foo', null);
|
||||||
|
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
||||||
|
|
||||||
$sc = new ProjectServiceContainer();
|
$sc = new ProjectServiceContainer();
|
||||||
$sc->set('bar', null);
|
$sc->set('bar', null);
|
||||||
$this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service');
|
$this->assertTrue($sc->has('bar'), '->set() with null service resets the pre-defined service');
|
||||||
@ -502,7 +516,7 @@ class ContainerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Setting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
* @expectedDeprecation Setting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
||||||
*/
|
*/
|
||||||
public function testReplacingAPreDefinedServiceIsDeprecated()
|
public function testReplacingAPreDefinedServiceIsDeprecated()
|
||||||
{
|
{
|
||||||
|
@ -287,7 +287,7 @@ class PhpDumperTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Setting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
* @expectedDeprecation Setting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
||||||
*/
|
*/
|
||||||
public function testOverrideServiceWhenUsingADumpedContainer()
|
public function testOverrideServiceWhenUsingADumpedContainer()
|
||||||
{
|
{
|
||||||
@ -295,15 +295,16 @@ class PhpDumperTest extends TestCase
|
|||||||
require_once self::$fixturesPath.'/includes/foo.php';
|
require_once self::$fixturesPath.'/includes/foo.php';
|
||||||
|
|
||||||
$container = new \ProjectServiceContainer();
|
$container = new \ProjectServiceContainer();
|
||||||
$container->set('bar', $bar = new \stdClass());
|
|
||||||
$container->setParameter('foo_bar', 'foo_bar');
|
$container->setParameter('foo_bar', 'foo_bar');
|
||||||
|
$container->get('bar');
|
||||||
|
$container->set('bar', $bar = new \stdClass());
|
||||||
|
|
||||||
$this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service');
|
$this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Setting the "bar" pre-defined service is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
* @expectedDeprecation Setting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
|
||||||
*/
|
*/
|
||||||
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
|
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
|
||||||
{
|
{
|
||||||
@ -312,6 +313,8 @@ class PhpDumperTest extends TestCase
|
|||||||
require_once self::$fixturesPath.'/includes/classes.php';
|
require_once self::$fixturesPath.'/includes/classes.php';
|
||||||
|
|
||||||
$container = new \ProjectServiceContainer();
|
$container = new \ProjectServiceContainer();
|
||||||
|
$container->setParameter('foo_bar', 'foo_bar');
|
||||||
|
$container->get('bar');
|
||||||
$container->set('bar', $bar = new \stdClass());
|
$container->set('bar', $bar = new \stdClass());
|
||||||
|
|
||||||
$this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service');
|
$this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service');
|
||||||
|
Reference in New Issue
Block a user