Skip to content

Commit 61763bf

Browse files
committed
fix(occ): Fix compatibility with PHP<8.2
iterator_to_array cannot take an array parameter prior to 8.2 Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 3e28a89 commit 61763bf

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

core/Command/Base.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ protected function configure() {
4040
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, iterable $items, string $prefix = ' - '): void {
4141
switch ($input->getOption('output')) {
4242
case self::OUTPUT_FORMAT_JSON:
43-
$output->writeln(json_encode(iterator_to_array($items)));
43+
$items = (is_array($items) ? $items : iterator_to_array($items));
44+
$output->writeln(json_encode($items));
4445
break;
4546
case self::OUTPUT_FORMAT_JSON_PRETTY:
46-
$output->writeln(json_encode(iterator_to_array($items), JSON_PRETTY_PRINT));
47+
$items = (is_array($items) ? $items : iterator_to_array($items));
48+
$output->writeln(json_encode($items, JSON_PRETTY_PRINT));
4749
break;
4850
default:
4951
foreach ($items as $key => $item) {

0 commit comments

Comments
 (0)