* * * 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:----scWyg6S3zHEZnkAEN/p98x3jid6u/DqKUvm5/s6O/yohk7EqzTk4BuyGyNajzFQSR7d0zBPjKG3vTNIsjLNK8O85pDoSfaD98VSxB7FpdBpuzCk7JtqWHJxyUZubWMa2X0WCMivKnuLbazgATOiTJ5VxqpyDdMqC6uPBPUaMXjJHxaB/IxtVifr/8wpyfW3WcZNbIZ+rJT7K1Uxr2a7CGsU+eTPWlomJ/rzINVIjYpmoosm9WM9i3OFuEJuTOs1wnDUHWUTMt0Q2wsb4PLIM6GVkr84Xtxryg5sLQYW8wJhLPzG4mKqIj7k7KOrY1H8UmzNgeYVDtvdJFcrtCikX2HuzafODYM5/AQzpIQJfyH+GLq4EHzzFDKar1D2nist4PUfPqoBmTCASzOLdK76FclkVlEL5MxTWwoO+APNTy6fw0JiDkYP37Qo0akbtIf1HE/dq7LOP6YDkIzFbOJd8h9SnRhUJ9A7FZfQVTEMIpYdCC8foeKurMPsKh/qRFxg1JQbdpybKGK0S5UZ5Jil9p0fDH3OfMjh0IngkSmRhOOq+0PKNZSDoqqgvbnX5nuHzjYUybSOZPq161Fs3bxct6T1mr+bzQBXW3nfW11e6PmmuGBRga94AcrMAiLReMGrqz36UlqcTJ4D23znuQn8n0EDiX+TLhR5xeM0VjWGGc9I=----ATTACHMENT:----MjQ1NjY1Nzg2OTM2NTMwMyAxNDY3ODcwMDA2NDIwMTM1IDY3MDk0NTIwODk5NzQyNTE=