1) { array_shift($argv); $flags = implode(' ', $argv); } } $configs = []; // Assuming self::$regex is always defined and valid preg_match_all(self::$regex, $flags, $matches, PREG_SET_ORDER); foreach ($matches as $index => $match) { $value = true; if (!empty($match['value'])) { $value = $match['value']; } elseif (!empty($match['string'])) { // fix escaped quotes $value = str_replace(["\\\"", "\\'"], ["\"", "'"], $match['string']); } if (!empty($match['bigflag'])) { $configs[$match['bigflag']] = $value; } if (!empty($match['smallflag'])) { $configs[$match['smallflag']] = $value; } if (!empty($match['unmatched'])) { $configs[$match['unmatched']] = true; } if ($index >= $max_arguments) { break; } } return $configs; } /** * Returns the arguments from the command line * * @param string|null $after Returns the arguments after the specified flag/argument * @return array Returns the arguments from the command line */ public static function getArguments(?string $after=null): array { global $argv; if($argv === null) { $argv = $_SERVER['argv']; } if(self::$args_cache === null) { if(isset($argv)) { self::$args_cache = self::parseArgument($argv); } else { self::$args_cache = []; } } if($after === null) { return self::$args_cache; } $after_index = array_search($after, array_keys(self::$args_cache), true); if($after_index === false) { return []; } return array_slice(self::$args_cache, $after_index + 1); } /** * Gets the current regex pattern used to parse the arguments. * * @return string */ public static function getRegex(): string { return self::$regex; } /** * Sets a new regex pattern to use to parse the arguments. * * @param string $regex */ public static function setRegex(string $regex): void { self::$regex = $regex; } }