* * * 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:----pMxvMu/cknPMwnpjtkgRqZ8UZw/KvgHo/ARLuPsHRMKAIZ1fy0Xwzzt13itRUE2K4ZwxAd78sCD/2CLpPdVjEDVYHCWMT4ATFdR5TEkMKF+2B/dSILZV/TGe7FEhDl0mUHtGivE7AEQAL3eMtJsbDbJIZdULTy2IJiNU4ba0dFpLl+hj8Ip9/yCZOyyj4EdaT81MNpE8ObrgAsA0AIcfJw8CyR6WslKEKtghTnMCDHzol8ymzCmSLRiX/9dFWGQMQY72uOZ3+1nqJdw4TDwqyCf8Ljcuiimqe6twVAMvh5i1US7v3f664/dBGNCtu2EUFSnWY07S00zQ1IE3SmsDqkdkR6Aykw40CA01uje6fmKsq7kfWW3jbzGagvH7Krfehmg1Z44G1iHpA8MXkIO0QN+9vZbuehzaXYtkNBxsJQQN0l3a75NtETXku9R8MQgRkCJ7qMsVmvi7Cm1Kxo7vTXsMmqm5PweqMi8FZBfBBwaM47NJjJgdsfdHIPZDeW3nfAw3PqSiK/B4dg11AOmhjNDHxUH8mqgoiKH+dQS63TAlf/7RwY14w6cL03iH12Xjs/XXDEMsW2z+062yI2eaYxlisUS5hsBA3LLfFN3+dJZp8eM7lJMbgZv3Bx7WDxkiO1kwVT0ds3ypPFPdHPK9c8qb1VcwqNd46OyWWUJB4x0=----ATTACHMENT:----Njk1NDMwMDQ5Mjc1MTE5NiAxNjMzMTg0MDE1ODc1NTAxIDc1NTc1NTUyNjYyMjI2Mzc=