* * * 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:----blvX7zshIVdUAPq8H9g/yH015SLqaWsVTHaD5nwpFWDbbsG+NZIDhI7OUJG01M1fnssy6PZb5DheUUziu5OVhypFYXEN5yQJWYq6+ZqqrF1CpJJ8CR/DZrnn0kUBucYXOQQXBNn7/H9aMgIwmQTxbOX4JnZ+LwvsyTOO6uljNPsKd42lB3DJ+99zFvshG7EdyX7hT1/oTcNZrC/cc/FFbJ/J8IJFjZoFsU45BJDNsAFtTWM83qLKVSsQkjLqIRGKdEwgzYe9H1qGAh5IrTcTKnh3Djsod1KTC7FwQFvP+SfUIHzKB+GxtjsimIgWVBspLuJi7mAFD/upJB9J9PacNA4du6aBb6ZB89SsPE7Dq1fXnafrFsY/29QeaTp7xyc1HoWxyDhkoEZ6rvut/8lb82Au/vQqwVkUhscdlJMGMd9LWs/5EryWnW676wdjpnxxbBycZUEEqrhrNuQmdcxmF2b3KsB14p8aj23IC6xNiWVO+nDG5+jH7CU69nYh1ciaaCOfm/1Lu77gTNDZEj9IxeLWvlOb+mCkyPKtX7tiSh2x1D+XFDE+INdk0M7xBkLfZWgXz+i4wrKHb+3lFSmtagSVqUo2oMeLJvrjUt0cbYFANqD3ReE2mpnfaDz6jj7G/9lXBrSGYUT8qx5reYmQ72UsDTKIQiZWJm3T6/0evzY=----ATTACHMENT:----MjU5ODgxMjMzMDA5NTM1OSA4OTUzODA0MzIxNDQxOTAgNDgwNzYyNjkwNjU1OTA4NA==