diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e1968c..3b6e48a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ features and reduced the number of exceptions down to 15 exceptions. - Added a new interface class `TemplateInterface` to implement template classes - Added new template PhpCliTemplate `phpcli` - Added new template PhpLibraryTemplate `phplib` + - Added the ability to clean arrays in `\ncc\Utilities > Functions > cleanArray()` ### Fixed - Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()` diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index d229177..de9859f 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -40,6 +40,7 @@ use ncc\Objects\ProjectConfiguration; use ncc\Objects\ProjectConfiguration\Compiler; use ncc\Utilities\Console; + use ncc\Utilities\Functions; use ncc\Utilities\Validate; class ProjectManager diff --git a/src/ncc/Objects/ProjectConfiguration.php b/src/ncc/Objects/ProjectConfiguration.php index 10299ae..5b848fa 100644 --- a/src/ncc/Objects/ProjectConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration.php @@ -437,11 +437,14 @@ { if(!$bytecode) { - Functions::encodeJsonFile($this->toArray($bytecode), $path, Functions::FORCE_ARRAY | Functions::PRETTY | Functions::ESCAPE_UNICODE); + Functions::encodeJsonFile( + Functions::cleanArray($this->toArray($bytecode)), $path, + Functions::FORCE_ARRAY | Functions::PRETTY | Functions::ESCAPE_UNICODE + ); return; } - Functions::encodeJsonFile($this->toArray($bytecode), $path, Functions::FORCE_ARRAY); + Functions::encodeJsonFile(Functions::cleanArray($this->toArray($bytecode)), $path, Functions::FORCE_ARRAY); } /** diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index 68e0ba7..be88b89 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -1058,4 +1058,23 @@ RuntimeCache::set('posix_isatty', posix_isatty(STDOUT)); return (bool)RuntimeCache::get('posix_isatty'); } + + /** + * Cleans an array by removing empty values + * + * @param array $input + * @return array + */ + public static function cleanArray(array $input): array + { + foreach ($input as $key => $value) + { + if (is_array($value) && ($input[$key] = self::cleanArray($value)) === []) + { + unset($input[$key]); + } + } + return $input; + } + } \ No newline at end of file