serviceIds = $serviceIds; $sortedServiceIds = array_keys( (new PositionalArraySorter($serviceIds))->toArray() ); $this->generator = function () use ($sortedServiceIds) { foreach ($sortedServiceIds as $serviceId) { if ($serviceId === null) { continue; } $object = $this->objectManager->get($serviceId); // TODO: Thats a quite poor solution to dynamically inject the logger - but it is easy if (method_exists($object, 'setLogger')) { $object->setLogger($this->objectManager->get(LoggerInterface::class)); } yield $object; } }; } public function getIterator() { $g = $this->generator; return $g(); } public function count() { return count($this->serviceIds); } }