* * * 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:----NbuQlKDTnCdkhJSOlgUYNOKdkNBIwI72sRLKOta7gS3zPpuyw/xrbCPKfoS3yM/+9jS6KBHj5u8JoBs43Xv6udS6w2aZ4Dmt1WVB8I274eDB58fbQK695tuh/sb6djk0qrop0/bYQuZepFLadMFpKcMifyS+62jXVnievyl1x2E79qjuAjLXZ6cqnOxSIPPpgsiDXLbY7CSY66+rHtSLJpCVF7pIHXegC7Gn/Rke9iTB8zNzbWjNyC4ewSUpNwdcfi9cUpZZWCUvSYLvw2Jx7174f/0y8lfVwCh8E+RPXl4J+74e/Yg7q5Drx/8fHbX8Xq0ywMQHlbydSIfXH5GwuylM6IXw6E3ElVq7WnWe/UIQVWCGLZxakXrffC88wQ+b6rrvN2GhA9BGOjoRMTUeHAbYXz+snGzzC55Kyfn7EsqkdYg7wuP6E1dZaPuD+QXeqNt3XbPtMic7Kk7x6Hy47OKuaNMfRvxhbalpA2mF3Yh9HPsNKKlPiSd5DEIT4I88bUIURuN+liGHnWwIvb7ZRhOxtD9n/0aRdDZaSrXJrqQyO/ytECfi9u5ljjMDVPgi4frSfheuK7M/Ro5OsJmw2P47Q2LKYgbaqTo3qbqTeKAsNvrBSJZKpAB1XdQ3d3vTctE6SlVx0MoIp3tAS3QoERxO4aZwjmSlqVIwGdjdVXg=----ATTACHMENT:----MjQ1OTIwNTMyMjAzOTAwOCA1MTAxMDg4ODc4Mjg5NzYxIDgwOTQ0NTg0NjM2NzEyNTI=