From ba129041ba19b6d5a62cfa34789d3b05e6efbacf Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Thu, 16 Jul 2015 09:25:41 +0100 Subject: [PATCH] [DependencyInjection] Forbid container cloning --- .../Component/DependencyInjection/Container.php | 4 ++++ .../DependencyInjection/Tests/ContainerTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 2b9fc5f487..0222d7063b 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -604,4 +604,8 @@ class Container implements IntrospectableContainerInterface { return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.'))); } + + private function __clone() + { + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index 603269ccc6..09b4a12e2f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -662,6 +662,16 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($c->has('alias')); $this->assertSame($c->get('alias'), $c->get('bar')); } + + public function testThatCloningIsNotSupported() + { + $class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container'); + $clone = $class->getMethod('__clone'); + if (PHP_VERSION_ID >= 540000) { + $this->assertFalse($class->isCloneable()); + } + $this->assertTrue($clone->isPrivate()); + } } class ProjectServiceContainer extends Container