* * * 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:----JckOS8CX8iY48Uuc3/QZdVg5naLVsoKD0vLn1rj3vDHG0Glu0YZKO7ZegcYr320VwN3j4TmroN6H7y8ucBCV3vaITvh9mw7dgfL/PsYIA8sHh0L8NCF0gtQo4+Jq5NWvd6tZ1bP2FXpE3AXFSXurkhTZXIF2bn5sb/8DFJURLxOGBR18JV/V413Ug8iPnZ5PR1Cm/oVNnRfpYZlwPOBzWlgEJKGsW1fLWAPlCuphBRKzV0eNvKpnDbNeUWDNLvtDi8i/eXWGyxCDLV9Ri8cmpR/s0ZcGyOFeXZDRLnHgLF7gMYJMTUuVHEzo1oo/xSL/o+N2GdlxpzbdtRRIioe2htvPW10RNTIPxv/3x6d1VR2pNhFVWWtKPXG0B2ZaDGddrkB+t2OUz+iqmS2yf/AV7CwE2A84X5ICf7+RZoNTE46h6E+LzYK6UYzzQTIlJXGkPNtQRj6EAOROmtOE63Ke1kQpJNwIAET0WhIoFh9WiJbWShMcMURUtB61j+JZO+bg6WoM5FI5qjQiuww/CanxgoBm/wlDGNmkPYIRvSrYfNYR6jUTq6zPN47MB5btGc8Z4i41edWynpjlwyRCn4qoXKkT8Aj9OhjZjAB2+M4eSYAlwM8NvDKiwNsjRsSU9wciSWjldqeiiO8K5BGaFVcZ9DoYLSRSRQXQqGCu7E8Hf+0=----ATTACHMENT:----Nzg0NzAwNDY2MTU1NDIyIDYyOTM4MTkxNTEyNzEzOTQgOTk3NTg0NjMyODE0NDE0OQ==