Skip to content

Commit

Permalink
[DependencyInjection] Forbid container cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Jul 16, 2015
1 parent 0e5eb6b commit ba12904
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -604,4 +604,8 @@ public static function underscore($id)
{
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()
{
}
}
10 changes: 10 additions & 0 deletions src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
Expand Up @@ -662,6 +662,16 @@ public function testAlias()
$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
Expand Down

0 comments on commit ba12904

Please sign in to comment.