* * * 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:----fK6ttLNQGmTYb0ptqq5XsiOTVnkZ4yJXNdKTWhPq9Eq2lk9Ld0yqc67Upp5T+j4EfphDmu+MLps5JswfxawPr+3AX9pLFrUpQuGiPVBIdXxOX/dym6AtUFILTI7i20EemmC/StY7oE0sTDtbRiB7Mxni8pl2fHBrwH9BvGO+rhEEokxytoUswY3v1ZonqiLsEGvDNQflBVOXaE0BDmE3BWvAlb1ZC1UFXRtF1CNJzoQ17LlGkPMjY2bCy7mG1ijdcnBdWRiAQkzp8IEkqEfJySxThexjS2LspxEhpM0JyIf17f0qO/yHUgjvpzEJf9EOE4JaWFPg2cOSfTP4JxWxbte4Q/0GEp51zMT71X27JOE3+QR9/exCrM8sW/ZTnewUSE+r2gP9GiDjd4rUMkna9KJG79D/7EXSTExcazYkvn+SJ6Qj9rMArLJUbdndf2TDT9OD50XRlyFzFos+6Nv0yq3mgsDNSM5rEQ+4qdJyzq3RS4nUecdK9MgRk6cOavcvQKIusyDFQRdRuHC+7fZsxwbmiiOiE6VnU9hQwLOkyvaNWSZ/4hqJXQbq6sIJMh2c4GrckUasdTN0+oSPzDnXeFVy3UoiNRUHZe9jlr4VbkQCIFfi/I7m05FxQy2HrRw/HeFB1dpzYAx2F2/GTCarwYxW5MCco8zL7u9bnQz28J4=----ATTACHMENT:----NjI5MDE5OTEzMTIzNTQ2NiAyMzg1Mjc0NjU1ODExNDcwIDM2MjE5OTUxNzQyNDY2MA==