* * * 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:----NylzsYe7Yf+ECJHinEbMiuOUjLCeO4lhU/ontE9uiwDS3gGZit1V/lwygue9r4NE7haH7/6FoIrocw8z17PyBZRoHvf9XAbZAvT/fy7QsO+RQKLT7wDGhS/VQ5hI0mumsouWHipkataaqaHqBaT9KDRAyALWj5qFWf3s1Vn7UggWe6jTPL07bL0WkD9fA20sEl2WKgjjJ6P281Pv61q+15+5sryJhKZ3j5aHzCrikXVv7OCyHiOho+pkRacIMxdA3LUPdR3bp3ll0Qr+PhTZwuAk0fkYI5uOd/enHvWK1DkG6V08hi7TPA69i8WodbA9aei1ncAVftDee6uaUu4WeFZ8+InZsn8SBnUUbsmUSnOyVn3c296zx79lsscPBO73JIKASXU4fAC6M2V8xRwrFbyC2iNZDIFTofmloNJkzzxfrFw5RyKWJNcGqaWnPoHoQqLw27h69qoOqLQ1OKD3gUUs7XArTx91VVKkOJ0QHVeEeDajpMNWG8FS/vN+veOMO6I0ZykxxjJglS0JR5l+o/Lz4dMrVUiOnpc3K9y22T12I2jJlITl2XTcbtiA475nBUNH1DwNYtaFmsIjysXFPsz7kAg0OtA0UPXuweamTM9De7JspTePVJjsF3tEbDkhpxhep3gjdn6z0x89lTjTEa3Nk8AVzWt4KsYajpLSBEw=----ATTACHMENT:----NTEwMTgwNjY0OTQzMDU5OCAzMDUwMjcxODI3NzU5NTUyIDM2OTM4MjgyMDQ2Njg3MTM=