[DependencyInjection] Forbid container cloning

This commit is contained in:
Jakub Zalas 2015-07-16 09:25:41 +01:00
parent 0e5eb6b6eb
commit ba129041ba
2 changed files with 14 additions and 0 deletions

View File

@ -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()
{
}
}

View File

@ -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