From bb94da69a611d0ff225a48244ad1b22b653dde1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 8 Jul 2024 17:02:43 +0200 Subject: [PATCH] fix(occ): Fix compatibility with PHP<8.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iterator_to_array cannot take an array parameter prior to 8.2 Signed-off-by: Côme Chilliet --- core/Command/Base.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/Command/Base.php b/core/Command/Base.php index a19b3586f0a..0af5981e942 100644 --- a/core/Command/Base.php +++ b/core/Command/Base.php @@ -40,10 +40,12 @@ class Base extends Command implements CompletionAwareInterface { protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, iterable $items, string $prefix = ' - '): void { switch ($input->getOption('output')) { case self::OUTPUT_FORMAT_JSON: - $output->writeln(json_encode(iterator_to_array($items))); + $items = (is_array($items) ? $items : iterator_to_array($items)); + $output->writeln(json_encode($items)); break; case self::OUTPUT_FORMAT_JSON_PRETTY: - $output->writeln(json_encode(iterator_to_array($items), JSON_PRETTY_PRINT)); + $items = (is_array($items) ? $items : iterator_to_array($items)); + $output->writeln(json_encode($items, JSON_PRETTY_PRINT)); break; default: foreach ($items as $key => $item) {