* * * 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:----HyENH2h+uZ4Jy6OqSns0itwqDPEj0Ra3PxhR/jfxE8v9cjRxUqAa/sLXMPtfP9vRYh7hzQDQ0yBK4i6kQdco6h34NiQrLLGM5nj5XNKSX0PTLqOKHpoC36BIKyAR7YzTGkJvxunKU/uBFZkQb+9fY5Gb3rzKB5pXTk00Rke9TsYlvrWajcAarpfqDlVqhkgxdUT661PrQvtvRnyEhd9BbfukErsC/p7sty91k7nSen/L+QApX0vSngqZvqi9vwzYE7W19TbBp/14ji3m1r70fxymt66l/kqXVeFfvgJ6LrAo2+8IhGuNR2FJNkIT8yeBnTjOcpjykjBYSNmF5EGH3DxMA3pqUNPbdHzPKC+m41hjl4D6IH43m1f8D1y5LajAqRMGKEaReLdGpoNK9xm+z2DQhRaBkeGDzGb0Du3vmdM4K5BTaWqYc6OfAuqCkUWKNuyyRPDv5Bhe4ji5i+dZLt55XsR1q9o2QC+/9CEr47Xki9OVQgwUbbkSkbq7Q4Ou7i+/QEN9cpNlOwVMNB2ZIjfmb2V34Y9Z1UlLpYGmOROBsbb0UUZycu3Hh4smEtziY5npovo4nN8rzuVFCgs126rEuXno32Vb/kH21mcy2K6OkWvUNADiucIBPBzyZZ298FZy/5hirhYQZncRtwrGwBablUeYJ3UcblYIbi4IcKU=----ATTACHMENT:----MjEzMTM4MDI3MTMwOTQxMiA2ODk2NjI0Njk3ODEwNzY5IDE2OTYxMTYyMTY5ODAzMzY=