* * * 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:----3CaHrIJEAj8u2CO+9hNAwQ5XW6JexIxPT762ozUURdf11WmWDMx82U+8B3ozgT9UTLQRBE6vnZAh30bhLAxbQbZNLwwXIE5l/NbNQws1dpimTQw/Xv9OBkdXdGWb3XwRXhRDBTig2GiJOy7hyJspoaL60sTbq2FWmz4Zu4q01P3Rdf8Zj2o1cWhvZuDiTDDiGptsJic3G9PCz9Whxsyxnx06WYtAn93GfOrc8cz4P9jCeVzauwKQG0j++qxDo3NFjvBBiUBdglblHsiAM81h3zjA46XgpeYvj7VBEhC2COrJChY5D+3WCoLzp1OX7nIBrvuFgFzyybDAwGJWivNF5MNwjvXURc7vnZBORWO73JWvH4mZA+TIRU1yK16OiKE/r0o/AyzRLtcVOR63mkM94tsofUbW//GTST50Bj/7jjAvBrhHMarDt+17cJpyhQ5Ons84LLUBc7qAFXYVGird29a46w02SDchj0XL02Ku5LbFJxrdwaflGDjo/mTlXwMRo3NMBtRhEYw2BCK8if9qMRgiTARuwRz+V670wKqTTkcrTn907gxZwA5bMgaccizMSzZopSnmPg5bExlpczS34CpPLuC8E7tRz5VU7Vbqlibiyu1h/5t/6lkpAcyai1qqqsDHIn90uFaogIL4ZuI0W+bKxYXeycfrSSzRVVS0avE=----ATTACHMENT:----NzM1MzU3NzcwMDA5MTUzOSA3Mzk4MTI3MDE5MDkwMjc0IDIxNzM1MjgwNjY0ODAxODE=