- Added the ability to clean arrays in \ncc\Utilities > Functions > cleanArray()

This commit is contained in:
Netkas 2023-09-01 04:06:52 -04:00
parent 0e8397ec1f
commit 45c53981ef
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
4 changed files with 26 additions and 2 deletions

View file

@ -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()`

View file

@ -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

View file

@ -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);
}
/**

View file

@ -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;
}
}