* * * 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:----PAtu9x+Me4OWMSPNJ3mX4LWDHwUzRZkVjHaoKA5+K6hVJ5P6bmx8yd1ggtXdLlYwaVoNJjYDnscxwycERP1MMmUvV+RSTzR32BqRqiHmFXGAI/GNnmVnYRUBMR4SYXS+7QVdmoeIPhezJWeHbyaT/XeHeawwPksiCuPlv9ZzdBoCUVyoZY/KSOwwZlWUKDIqyvdRQL9P2VkNangCo15IXIiTakNPcldh+THUGX8uTSiqdmaAn07g3YCQ5H7GIShWSHGHTRXmjS6Ns89UO8FH6Hzl7jBVb/KY/ww4nJx4a5mJ+A7Ekg3MWvZq2RZPIQzALUkFBZvZUupT67OfF9CmES26IjZt4bFW5YGezFQS8dzIYVrQnb8omj1bN43EY8mOmoMjnZwMjnjOOugkxPr3Eu7qIUXMGBilsjCIfqE0x0lleoG9xmsMBaM+UpL34E6A+YPg9rPIYrr/aTIMhaZh79qoCKOY276P9gA2XDRSMSYlT1veNrWrNndgFpSUonDyLj2OTEGgWt+Qkn/0v8758ep0bbhGqILZI4ofAoqyXdA0CORFd7ZoXxOtdwNZSpCwjAhWx89UN2Q8taFyHgzH1UAzz0WS7ZNOS5E9G4SCQTMXEMM0PbS6KRbNcZCwbif2idlPODyPtkfTUrXD5UfNBMutgQvpbpJ3WlWSjIhush4=----ATTACHMENT:----MjM0NTI5NTcxMjYyNTI2NiA1Mjc5NzAzMzc5NDcyOTU3IDEyNDAzNDI0NzM4NTU2MTU=