* * * 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:----dVqvAWUvzZQ6E2h5zcyYOMIpaPAUIfvkZG4MZUNhCh1riZDXOB6fuKB3nhA9Zk3yG+XITAxX3IUTh26zJ8Z2MENLK5rIZc60txtVeeTaHm5HzatvKLDXUYg/VhicnwNFMXfC7FYVP4OSH4DYncmXMkkd67YlD3G4v1/+hi95oXTv4J8CZ/rIPH+wPCLBcpFW0zTzn01gLOyonVE3lZ1/1K7vuzh28JeXgpQczArBnM8OTMHDoTJWXzWqqolIEZkkdtn1mnAyz1KkTWvcqSHGBfaYP3i3sZRP/wJtFiGaR9poIcEITEylD2wl3/TZbIx7exuwtNnHkJBIF0fvdVPScMU/3mPxn9DdQWcngDnsa+w2YXKzLRc2nXWxHewTBEqZv3if/KNmWNbOpgtci+FH514Kk5zZAWx8XTuqd89rSSlyETyMg1KsI3sga2y2vQqnoRL8uFL07LRpLn60mHHIHOx8zl9n3IbCbSpY5W7Qe4rWp/PFosSaoHGA6ItDAIMCgcXF9H19GXPQy+03gMT3XPgzt2Q5FbhN5LJIQ3qpOBQEjX+8RXWaEWEXt63E2TCFqznI9BENbIQntT6BQAZxEiSD9r2EBlo+TIteBc6KN23n68c66QUfH7jTPNllQVugxwpva3Vj1LjnEUfPdrpGhMRLS4ifD2rzrP4YN5+9bHo=----ATTACHMENT:----NDA2NTkxOTI0NDQwODIxMCAyOTk0NTIxMzUyMTYyNzQ1IDM3MDcxOTAyNDI1NTg5OTg=