* * * 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:----zgchqMVrxNQcpTwPcKgwGx5lQpPv35K7jcsghOzIsVSmDfCB+oFFNFso9UIPJSf28czvfC2QHvSfVo8utKiv0lTC13Uor1EDiNvjnzNrNROCEzarCFlaXemkzlVYcuNEf+VmtGKGJkGcexOs95o5AhzLYeLXO9NYN8oiGdJv8dkg+NKA0D3FXigpgvzHO8YRB57xVFIdCsXFT/SQeG7nZ+yQugUzDC6S3r/pWjn/HzWFzZ7crGjgGpMsf5VZn0dRyr0+meqVKIGOD8FlxXRePeUKtxoK/WfwGuZOGEerwlhkgkdeJjTe8fdVDtUdO9GHJuOYgCyQIhaI4uNQjvacAXViwvPNIzLi1dZR/hZJBHJ7EwJVUV6lgnQQBqrQYFaIeQwHRB23jIQe8kI+9BQAXwiHcmpguXYYTFfstP/5NnXW7U0wAzj9TEL6cDouso8ZUmR51y2OvOZUzTyJdj6SyWtMEhzmxsLN26IaE9542uk4m7v70zXpPBrZWHX3aUSJnXuOFaUYlX9yL+cPZb52KVxRZBPalhv6/ciQZxNSKpGjd+4cR4sJuC+83+6LhowSCDorJ+YMU2FbaYdmuaNfVzlHOTpVPzrVmazhn4JniFN8jdrBJiJCwouPRr141WCdxivl/ExQDO8MvlRMrCnUGuWz0HgRxrtX7/LbCngBce4=----ATTACHMENT:----MTUyOTE0MzA2Mzk0ODk3NSAyNzE5MzQ4MDY3NTE5NzAyIDg5MTcwMzI3NzIyMjQwNjk=