Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba12904

Browse files
committed
[DependencyInjection] Forbid container cloning
1 parent 0e5eb6b commit ba12904

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,8 @@ public static function underscore($id)
604604
{
605605
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
606606
}
607+
608+
private function __clone()
609+
{
610+
}
607611
}

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,16 @@ public function testAlias()
662662
$this->assertTrue($c->has('alias'));
663663
$this->assertSame($c->get('alias'), $c->get('bar'));
664664
}
665+
666+
public function testThatCloningIsNotSupported()
667+
{
668+
$class = new \ReflectionClass('Symfony\Component\DependencyInjection\Container');
669+
$clone = $class->getMethod('__clone');
670+
if (PHP_VERSION_ID >= 540000) {
671+
$this->assertFalse($class->isCloneable());
672+
}
673+
$this->assertTrue($clone->isPrivate());
674+
}
665675
}
666676

667677
class ProjectServiceContainer extends Container

0 commit comments

Comments
 (0)