[DependencyInjection] removed Iterator interface support from Container as there is no real-world use case
This commit is contained in:
parent
bc57d7c157
commit
661a1cfb5f
@ -50,12 +50,10 @@ namespace Symfony\Components\DependencyInjection;
|
||||
* @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;
|
||||
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user