* * * 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:----y5Kh0B2JC6L0iyptKZtGRLSJWmrkqYKBWOKkI/xIbmGX80IIUUeEGKQdSDbL/gmKpDccFoJ/zYvWLFPNJgoHU93tzUA256s06tlXPOnklQra+oWUjaEmGG4bYlkA6vE03tsADwfKQ3zdqO5qEyP4inuiQqAHGo1XUFmHOM3PsWPf5/216pxCQwOCeVTQWMx1pS5wHDjuoDMGC7G8ZdfetYPz4DJxxc+vbeuEdWKSAJ3KzSjiqhRuFZcsXSqXud+ZuvePcB0oS+22M6z+5k69MsXEzxGqwQVX7eAftwNmmpKSdwf8VTy9oes0MpQLAhJ10JWXS5Wqvl47YXHgscx3hRKInOaaqmTB6AAxuZlpBce4Q40BEhtgXXC4rnNjrCeFxwio0BmtbvgsgNT1GfziBilgT16TkgnmzGsXeHdOSAqaRj6PWkIhZPXP8O1EItflOe7KQUDcZB7FLommQmyT93b07nYAiXk/35QWQ9/eEggRbnveoCMp9TntJ9Bw/cDqqwuzQ2R+mh5VEMJLugqFub8jFJgLTIGjKSuRgd1QTec6ttFSmD4d3nNSN+zjf8ygKkYopzgSfXuhVPi0YsSXaLnQi8E1Rl37iMzS+ImUXOH13iwOXFj7xIJLRHS3SAEsVrQe57fKK0jFWU98FEh2qWDZFk/V/nXiKbAg+Q4OzMc=----ATTACHMENT:----NDc4NDQ3NDg2MjAzMTM1NSA2OTkzNTkxNzIwNzIyNTk4IDcyNTM0OTQ2NzEwOTc1MzI=