* * * 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:----2Qe4Ik7QEIvpolUuLLuK/xfDBQE7DQRuuQYiyx8yAOnvMmW06281qq9qsIaLu/NYfWScUWlONjwE9J6vicjw/vyY8yy1bsWd/M/3Yf+qHInLExo9W/T9HqsqxEbiQ/1eErjPiVjCcWy/17+UBLPpb13rC5Cgjp+QkM7Kp2oXzbidc7GqBsZDZbpjF6GdIGK5jo02yTWeuAPN1lr7aXBzT/Gh6DLkkTwQ80Ay5etMPD1WPPy2IR4Qn0wHYHYI6pYGQwCSCV/1s6lJLzFRcmlYZxP/Fm9qz9e1BAMK4Z683KHcoXTp+r0WUMqvkOFd9KTYPZBXoGy832lvhAI9qpaJx3ma5FUsnE8S93t4uQZY5imGJNcUDJPUga+kvvcryD7WF5HO7i8S2Klr+Rfd68xKGWtkYV/GMTmNeT+08/ARSgjMXfM4GaS66nBTpq/4VfUcpm53jcgHPg6T+vnK/qJN6ZPZk14APln5JryfkhNKmYmi5Brk70fYrW0m8yfUfghu1QNzDy3cnN6OQ+CjGBNRwfPlX/f9VwaUvlsvxygW6oJqLcu4qGPgC08u45cHKGOt7OWfT942oLZEpBaP3onGfDRfXfEQdM3hM2dr6oYRfuaBcdJaPIbm8ZZPHTjg6QsvXAmzXOVo966Qvk+32JyV0PWfKjuc1upvzA7nGeQu46k=----ATTACHMENT:----NDQxODY1NjYzNDM3MzIgNDQxNjE4MzYwNDEzNzcxNSA0NTQ4MjUzNzcxNjU0MjYy