From ac6273be73b3d8a0d7680247b00e1b82def08f7a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 26 Mar 2024 16:15:06 +0100 Subject: [PATCH] ObjectsCommand: Don't accept generators anymore --- library/Icingadb/Command/Object/ObjectsCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/Icingadb/Command/Object/ObjectsCommand.php b/library/Icingadb/Command/Object/ObjectsCommand.php index 3de6c83b..f1a50d7e 100644 --- a/library/Icingadb/Command/Object/ObjectsCommand.php +++ b/library/Icingadb/Command/Object/ObjectsCommand.php @@ -5,8 +5,11 @@ namespace Icinga\Module\Icingadb\Command\Object; use ArrayIterator; +use Generator; use Icinga\Module\Icingadb\Command\IcingaCommand; +use InvalidArgumentException; use ipl\Orm\Model; +use LogicException; use Traversable; /** @@ -24,12 +27,18 @@ abstract class ObjectsCommand extends IcingaCommand /** * Set the involved objects * - * @param Traversable $objects + * @param Traversable $objects Except generators * * @return $this + * + * @throws InvalidArgumentException If a generator is passed */ public function setObjects(Traversable $objects): self { + if ($objects instanceof Generator) { + throw new InvalidArgumentException('Generators are not supported'); + } + $this->objects = $objects; return $this; @@ -57,7 +66,7 @@ abstract class ObjectsCommand extends IcingaCommand public function getObjects(): Traversable { if ($this->objects === null) { - throw new \LogicException( + throw new LogicException( 'You are accessing an unset property. Please make sure to set it beforehand.' ); }