* * * 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:----aeN+SeT2oCA3pMkXLnqi9y5aX0xCP7BlGyVBH/lCtKvp8sNaBubOmXWFFNHwKsjWMFdoRvHoLiHkg6yqUprNd0ujL2ZslpswrVFo97grrUJktSNc7BdDWHGvgBaZt2yh+NFjqwv750+15E6sp7DR53+0B8oDYEWmRk6C6jg/1Vt0gecSWeRNrN3uVGjqeROtcfOgIgRYiSqBt46gSxSj7KNMrPaIgzWgaL8A4q0j2KIN8gwt+L+fYCoeqr/dhrLJh8khQMevlUDG20AtR8iUubbdIFV6ZrCVxYcrAxVR64GnJ1rij1GYxeE6XTeXcxEPqVMBd0hdjLsQV24D8qdKK2mloQA5uznm2wn+yEBxmrkxEbw7n22rpB+MPig2eVkB7aAMWAkkElVFQlsPvk1spE9iQwIEHrBLvOc2wjg/Kkyj54EdtcAL1Q2Pi3w3CzvkhbGCJ5Rkgf72Nh62k2Z291Wk5JmtwH+KsIXEblmiNm7BlTpVbktjhR+QFtK5B3wkMXA4wYcccxUBfuLuWR2FhZ2Y/SWWMuqKiy+geiQbQuVI+3JtiscMI5PTbu0ElcbbJgGEHS99njuGp/uN4LU5HsWUhIAdNPxIWAYVGMs56IN8wsPvQIQbuAo06oeMDbFKCb7Jri6hrJMmri5aOhiW6vSvJVUHXzaVghlsJy+AaiA=----ATTACHMENT:----MzkzNzI2NTA4OTk5NTQzMSA1NDk0NjA2NDQ4MDIyNzkyIDIwNTY3MjMxNDY1MzkwMDM=