From 65f484f2ca1dd965b8ce5d9b1d4ff01f820e8e6f Mon Sep 17 00:00:00 2001 From: Alexandre 'pocky' Balmes Date: Mon, 16 Jun 2025 22:50:11 +0200 Subject: [PATCH] feat: Allow multiple lines addition with array --- src/GenerateFlexEndpointCommand.php | 8 ++++++++ src/LintManifestsCommand.php | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/GenerateFlexEndpointCommand.php b/src/GenerateFlexEndpointCommand.php index 7eb81d2..aff843a 100644 --- a/src/GenerateFlexEndpointCommand.php +++ b/src/GenerateFlexEndpointCommand.php @@ -123,6 +123,14 @@ private function generatePackageJson(string $package, string $version, array $ma { unset($manifest['aliases']); + if (isset($manifest['add-lines']) && is_array($manifest['add-lines'])) { + foreach ($manifest['add-lines'] as $i => $config) { + if (isset($config['content']) && is_array($config['content'])) { + $manifest['add-lines'][$i]['content'] = implode("\n", $config['content']); + } + } + } + $files = []; $it = new \RecursiveDirectoryIterator($package.'/'.$version); $it->setFlags($it::SKIP_DOTS | $it::FOLLOW_SYMLINKS | $it::UNIX_PATHS); diff --git a/src/LintManifestsCommand.php b/src/LintManifestsCommand.php index 89bfaed..d66ee8d 100644 --- a/src/LintManifestsCommand.php +++ b/src/LintManifestsCommand.php @@ -149,7 +149,24 @@ private function isAddLinesValid(mixed $data, string $manifest, OutputInterface continue; } - if (!is_string($addLine[$key])) { + if ('content' === $key) { + if (!is_string($addLine[$key]) && !is_array($addLine[$key])) { + $output->writeln(sprintf('::error file=%s::"add-lines" (index %d) has a "%s" key but it must be a string or an array of strings', $manifest, $index, $key)); + $isValid = false; + + continue; + } + + if (is_array($addLine[$key])) { + foreach ($addLine[$key] as $lineIndex => $line) { + if (!is_string($line)) { + $output->writeln(sprintf('::error file=%s::"add-lines" (index %d) has a "%s" array but element at index %d is not a string', $manifest, $index, $key, $lineIndex)); + + $isValid = false; + } + } + } + } elseif (!is_string($addLine[$key])) { $output->writeln(sprintf('::error file=%s::"add-lines" (index %d) has a "%s" key but it must be a string value', $manifest, $index, $key)); $isValid = false;