From be4626482ba8761da39746a6ac60d133d3852a0f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:45:00 +0200 Subject: Merging upstream version 1.1.2. Signed-off-by: Daniel Baumann --- application/forms/Command/CommandForm.php | 40 ++++++++++++------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'application/forms/Command/CommandForm.php') diff --git a/application/forms/Command/CommandForm.php b/application/forms/Command/CommandForm.php index a535c6d..49a0565 100644 --- a/application/forms/Command/CommandForm.php +++ b/application/forms/Command/CommandForm.php @@ -5,8 +5,8 @@ namespace Icinga\Module\Icingadb\Forms\Command; use ArrayIterator; +use Countable; use Exception; -use Generator; use Icinga\Application\Logger; use Icinga\Module\Icingadb\Command\IcingaCommand; use Icinga\Module\Icingadb\Command\Transport\CommandTransport; @@ -16,6 +16,8 @@ use Icinga\Web\Session; use ipl\Html\Form; use ipl\Orm\Model; use ipl\Web\Common\CsrfCounterMeasure; +use Iterator; +use IteratorIterator; use Traversable; abstract class CommandForm extends Form @@ -25,7 +27,7 @@ abstract class CommandForm extends Form protected $defaultAttributes = ['class' => 'icinga-form icinga-controls']; - /** @var mixed */ + /** @var (Traversable&Countable)|array */ protected $objects; /** @var bool */ @@ -43,7 +45,7 @@ abstract class CommandForm extends Form /** * Set the objects to issue the command for * - * @param mixed $objects A traversable that is also countable + * @param (Traversable&Countable)|array $objects A traversable that is also countable * * @return $this */ @@ -57,7 +59,7 @@ abstract class CommandForm extends Form /** * Get the objects to issue the command for * - * @return mixed + * @return (Traversable&Countable)|array */ public function getObjects() { @@ -105,11 +107,11 @@ abstract class CommandForm extends Form /** * Get the commands to issue for the given objects * - * @param Traversable $objects + * @param Iterator $objects * * @return Traversable */ - abstract protected function getCommands(Traversable $objects): Traversable; + abstract protected function getCommands(Iterator $objects): Traversable; protected function assemble() { @@ -123,10 +125,15 @@ abstract class CommandForm extends Form protected function onSuccess() { - $errors = []; $objects = $this->getObjects(); + if (is_array($objects)) { + $objects = new ArrayIterator($objects); + } else { + $objects = new IteratorIterator($objects); + } - foreach ($this->getCommands(is_array($objects) ? new ArrayIterator($objects) : $objects) as $command) { + $errors = []; + foreach ($this->getCommands($objects) as $command) { try { $this->sendCommand($command); } catch (Exception $e) { @@ -159,21 +166,4 @@ abstract class CommandForm extends Form { (new CommandTransport())->send($command); } - - /** - * Yield the $objects the currently logged in user has the permission $permission for - * - * @param string $permission - * @param Traversable $objects - * - * @return Generator - */ - protected function filterGrantedOn(string $permission, Traversable $objects): Generator - { - foreach ($objects as $object) { - if ($this->isGrantedOn($permission, $object)) { - yield $object; - } - } - } } -- cgit v1.2.3