From 661a1cfb5f2d8abb9dceca64ded443a00922febc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 8 Feb 2010 18:39:11 +0100 Subject: [PATCH] [DependencyInjection] removed Iterator interface support from Container as there is no real-world use case --- .../DependencyInjection/Container.php | 54 +------------------ .../Dumper/GraphvizDumper.php | 4 +- .../DependencyInjection/ContainerTest.php | 19 +------ 3 files changed, 5 insertions(+), 72 deletions(-) diff --git a/src/Symfony/Components/DependencyInjection/Container.php b/src/Symfony/Components/DependencyInjection/Container.php index 7a1fce2d30..95ec411821 100644 --- a/src/Symfony/Components/DependencyInjection/Container.php +++ b/src/Symfony/Components/DependencyInjection/Container.php @@ -50,12 +50,10 @@ namespace Symfony\Components\DependencyInjection; * @subpackage dependency_injection * @author Fabien Potencier */ -class Container implements ContainerInterface, \ArrayAccess, \Iterator +class Container implements ContainerInterface, \ArrayAccess { - protected $serviceIds = array(); protected $parameters = array(); protected $services = array(); - protected $count = 0; const EXCEPTION_ON_INVALID_REFERENCE = 1; const NULL_ON_INVALID_REFERENCE = 2; @@ -325,56 +323,6 @@ class Container implements ContainerInterface, \ArrayAccess, \Iterator throw new \LogicException('You can\'t unset a service.'); } - /** - * Resets the service identifiers array to the beginning (implements the Iterator interface). - */ - public function rewind() - { - $this->serviceIds = $this->getServiceIds(); - - $this->count = count($this->serviceIds); - } - - /** - * Gets the key associated with the current service (implements the Iterator interface). - * - * @return string The service identifier - */ - public function key() - { - return current($this->serviceIds); - } - - /** - * Returns the current service (implements the Iterator interface). - * - * @return mixed The service - */ - public function current() - { - return $this->getService(current($this->serviceIds)); - } - - /** - * Moves to the next service (implements the Iterator interface). - */ - public function next() - { - next($this->serviceIds); - - --$this->count; - } - - /** - * Returns true if the current service is valid (implements the Iterator interface). - * - * @return boolean The validity of the current service; true if it is valid - */ - public function valid() - { - return $this->count > 0; - } - /** * Catches unknown methods. * diff --git a/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php b/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php index ad2a60030c..37db58750e 100644 --- a/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php +++ b/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php @@ -158,8 +158,10 @@ class GraphvizDumper extends Dumper $container->setDefinition($id, new Definition('stdClass')); } - foreach ($container as $id => $service) + foreach ($container->getServiceIds() as $id) { + $service = $container->getService($id); + if (in_array($id, array_keys($container->getAliases()))) { continue; diff --git a/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php b/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php index 921d93cada..6cd5bb3373 100644 --- a/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php +++ b/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php @@ -14,7 +14,7 @@ use Symfony\Components\DependencyInjection\Container; $fixturesPath = __DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/'; -$t = new LimeTest(43); +$t = new LimeTest(42); // __construct() $t->diag('__construct()'); @@ -190,23 +190,6 @@ catch (LogicException $e) $t->is(spl_object_hash($sc->getService('foo_bar')), spl_object_hash($sc->__foo_bar), '->getService() camelizes the service id when looking for a method'); $t->is(spl_object_hash($sc->getService('foo.baz')), spl_object_hash($sc->__foo_baz), '->getService() camelizes the service id when looking for a method'); -// Iterator -$t->diag('implements Iterator'); -$sc = new ProjectServiceContainer(); -$sc->setService('foo', $foo = new stdClass()); -$services = array(); -foreach ($sc as $id => $service) -{ - $services[$id] = spl_object_hash($service); -} -$t->is($services, array( - 'service_container' => spl_object_hash($sc), - 'bar' => spl_object_hash($sc->__bar), - 'foo_bar' => spl_object_hash($sc->__foo_bar), - 'foo.baz' => spl_object_hash($sc->__foo_baz), - 'foo' => spl_object_hash($foo)), -'Container implements the Iterator interface'); - // __call() $t->diag('__call()'); $sc = new Container();