Skip to content

Commit

Permalink
[DependencyInjection] removed Iterator interface support from Contain…
Browse files Browse the repository at this point in the history
…er as there is no real-world use case
  • Loading branch information
fabpot committed Feb 8, 2010
1 parent bc57d7c commit 661a1cf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 72 deletions.
54 changes: 1 addition & 53 deletions src/Symfony/Components/DependencyInjection/Container.php
Expand Up @@ -50,12 +50,10 @@
* @subpackage dependency_injection
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
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;
Expand Down Expand Up @@ -325,56 +323,6 @@ public function __unset($id)
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.
*
Expand Down
Expand Up @@ -158,8 +158,10 @@ protected function findNodes()
$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;
Expand Down
Expand Up @@ -14,7 +14,7 @@

$fixturesPath = __DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/';

$t = new LimeTest(43);
$t = new LimeTest(42);

// __construct()
$t->diag('__construct()');
Expand Down Expand Up @@ -190,23 +190,6 @@ protected function getFoo_BazService()
$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();
Expand Down

0 comments on commit 661a1cf

Please sign in to comment.