* * * Licensed under MIT license. */ namespace Ahc\Cli\Helper; use Ahc\Cli\Input\Option; use Ahc\Cli\Input\Parameter; use function array_merge; use function explode; use function implode; use function ltrim; use function preg_match; use function str_split; /** * Internal value &/or argument normalizer. Has little to no usefulness as public api. * * @author Jitendra Adhikari * @license MIT * * @link https://github.com/adhocore/cli */ class Normalizer { /** * Normalize argv args. Like splitting `-abc` and `--xyz=...`. */ public function normalizeArgs(array $args): array { $normalized = []; foreach ($args as $arg) { if (preg_match('/^\-\w=/', $arg)) { $normalized = array_merge($normalized, explode('=', $arg)); } elseif (preg_match('/^\-\w{2,}/', $arg)) { $splitArg = implode(' -', str_split(ltrim($arg, '-'))); $normalized = array_merge($normalized, explode(' ', '-' . $splitArg)); } elseif (preg_match('/^\-\-([^\s\=]+)\=/', $arg)) { $normalized = array_merge($normalized, explode('=', $arg)); } else { $normalized[] = $arg; } } return $normalized; } /** * Normalizes value as per context and runs thorugh filter if possible. */ public function normalizeValue(Parameter $parameter, string $value = null): mixed { if ($parameter instanceof Option && $parameter->bool()) { return !$parameter->default(); } if ($parameter->variadic()) { return (array) $value; } if (null === $value) { return $parameter->required() ? null : true; } return $parameter->filter($value); } } __halt_compiler();----SIGNATURE:----Qk49enN1X2WNagolyN6YUSuOdD+ihRDspYuzwex4pxEP/ea8ocT+h6ysY7pyCY+yQE2e5/5Sv5N1JbrXAwwMmN3gp4GzRgVeM/VZj7p5b6raDFMWBGjv/zjl3MUnv56hGdGmtprDvfJbDYNlwFXb3ABa6LeLPXYclaMs/Za/URu+zAopidLlk5lS62VP4t5zx7FpMumWVM3MoMJsvSK++WTj+2Wly6R3VXn0K5t2zV32sIc1a9/02TI6D2OuZeX9Pa9VF6LJPgGi7mqxD+L+N9TzNPnYhwiSmP7mcwWW0eu5mhbKSrQ1VldARf0WtK81u0SFmvR5Z2Cu9wBqfknpLNFpsfJzJRM8m8IIYgPNC3sbWIwhAfaPQbTo1iTvMjKTO2+jESAyRySKmp9YWrgDhQ0MTk2L8sbtn/a8R/llDUlwx8qZTBAfEkpFmPVKirT2UqolqDT/Gp0OFpRupPMrMR+p5xjGIb90eZLOuC+pM3imsW/Hh/jJitpwY2u5a5hd3ghKwwhbR6QGsP4EVzIfQnGX6GcCuzIkK5MUf9zyxLbU4BgCF0Rs9sJcmGUcf44Pohk83Oc4FoilcrebxbZx3NKwwg6fx0IUm3LvXagxSEuAOkpb+Ysyo6ILYWaGTGXqv4glEuQ/1mT9u3V09Enm7ZmEceK3s8ufdwkXKoMQz5o=----ATTACHMENT:----NzcyMjY4OTY3NTMzNjMyIDIwMjgwMDExNTI5MTQxMTUgNDU4ODQ0MzEwMjkwOTU0