* * * 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:----KMxdK0jye3Exb9XxTk+OQW3cqPnhvYqcVsDFnjZ/DBWxCYZvXZpPEK144EC6q1wEFQyFkrbtPPWfCslTUCwmNXEpJgreLWfkKy1HAQWM4wl248sFuIGGkqSxG9atpqTErc3DQfIk4dCj04U0TBzNoc9mEY64HrRpnD8P4OcMen5gCUlD70ZuwmeHmoaLJ3CD3b8Z5lJ/M1MYsrfUpFiCuL8371GlkHQADR2HtzU79gfbDkWShtMh5Y680uDYB+3UjS05BrLdBWiGTm9QwadrQ+6acX2XV/sY7rhaNgtC38hfvUbjZwZSWrniVooaaOkPYim1qOGh2d5SXOeQz8HEpC89NXfjn2cdze3PMjP4iZwd5HOvYSTyR77Hzv/dkh7og/M6i3vO+dRCurqFlSc4BeEwA28FfOdyND6SYOQgNAAlmo3EyzDrdwxpcq90ev//ktSaUZeGFkIcz3bn6yXGhv4A+7yDe0WgEtzyhCpIKdPyIJXboTUpllv7Q0Rsyq1CK17Fd1s5hm1tArBHvW/W1Rm5BZhsY/VpUHoYc0Mn/o+RMo3+8T52lLWB/BogI2Sqojnapp1eh8ScpNYtm+1Sapzsrmo4dwuSRJRo4cfnnFGzmIUiKDTiD0F3ACZNd4PPfvHtN+43P4TLm7/OkQhx26Ln36G1XikKMs43qgSsWf4=----ATTACHMENT:----NDQ4OTY4NzY5MzA2NzA3IDY4MzgwNzQ4NTM2ODM1OTUgODE2MTY4NjMzNDI0MDQ0NA==