diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index ea8af9c..a854623 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -19,6 +19,9 @@ diff --git a/.idea/php-inspections-ea-ultimate.xml b/.idea/php-inspections-ea-ultimate.xml new file mode 100644 index 0000000..26c2a68 --- /dev/null +++ b/.idea/php-inspections-ea-ultimate.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml index bb335e2..fe09da7 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -9,6 +9,11 @@ + + + + + diff --git a/.idea/webResources.xml b/.idea/webResources.xml new file mode 100755 index 0000000..7356908 --- /dev/null +++ b/.idea/webResources.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2aaf3..82f802e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ -## Release v1.0.0 (2023-01-29) +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.1] - Unreleased + +Updated optslib to work with ncc 2.+. + +### Fixed + - Fixed code-smell from optslib. + + +## [1.0.0] - 2023-01-29 Initial release of ConfigLib. \ No newline at end of file diff --git a/project.json b/project.json index a37b3ed..67e9b0f 100644 --- a/project.json +++ b/project.json @@ -21,7 +21,7 @@ "package": "net.nosial.optslib", "copyright": "Copyright (c) 2022-2023 Nosial", "description": "A simple options parser library for PHP", - "version": "1.0.0", + "version": "1.1.0", "uuid": "20aefdfa-7b91-11ed-919f-cb63712c8e36" }, "build": { @@ -30,6 +30,10 @@ "configurations": [ { "name": "release", + "build_type": "ncc", + "options": { + "compression": "high" + }, "output_path": "build/release" } ] diff --git a/src/OptsLib/Parse.php b/src/OptsLib/Parse.php index 63069bc..7d3a205 100644 --- a/src/OptsLib/Parse.php +++ b/src/OptsLib/Parse.php @@ -26,14 +26,14 @@ * * @var string */ - private static $Regex = "/(?(?=-)-(?(?=-)-(?'bigflag'[^\\s=]+)|(?'smallflag'\\S))(?:\\s*=\\s*|\\s+)(?(?!-)(?(?=[\\\"\\'])((? $match) { - if (isset($match['value']) && $match['value'] !== '') + if(isset($match['value']) && $match['value'] !== '') { $value = $match['value']; } - else if (isset($match['string']) && $match['string'] !== '') + elseif(isset($match['string']) && $match['string'] !== '') { // fix escaped quotes - $value = str_replace("\\\"", "\"", $match['string']); - $value = str_replace("\\'", "'", $value); + $value = str_replace(["\\\"", "\\'"], ["\"", "'"], $match['string']); } else { $value = true; } - if (isset($match['bigflag']) && $match['bigflag'] !== '') + if(isset($match['bigflag']) && $match['bigflag'] !== '') { $configs[$match['bigflag']] = $value; } - if (isset($match['smallflag']) && $match['smallflag'] !== '') + if(isset($match['smallflag']) && $match['smallflag'] !== '') { $configs[$match['smallflag']] = $value; } - if (isset($match['unmatched']) && $match['unmatched'] !== '') + if(isset($match['unmatched']) && $match['unmatched'] !== '') { $configs[$match['unmatched']] = true; } - if ($index >= $max_arguments) + if($index >= $max_arguments) + { break; + } } return $configs; @@ -113,45 +114,37 @@ public static function getArguments(?string $after=null): array { global $argv; - if(self::$ArgsCache == null) + + if($argv === null) + { + $argv = $_SERVER['argv']; + } + + if(self::$args_cache === null) { if(isset($argv)) { - self::$ArgsCache = self::parseArgument($argv); + self::$args_cache = self::parseArgument($argv); } else { - self::$ArgsCache = []; + self::$args_cache = []; } } - if($after == null) + if($after === null) { - return self::$ArgsCache; + return self::$args_cache; } - else + + $after_index = array_search($after, array_keys(self::$args_cache), true); + + if($after_index === false) { - $after_index = array_search($after, array_keys(self::$ArgsCache)); - - if($after_index === false) - { - return []; - } - else - { - return array_slice(self::$ArgsCache, $after_index + 1); - } + return []; } - } - /** - * Returns the cached arguments - * - * @return array - */ - public static function getArgsCache(): array - { - return self::$ArgsCache; + return array_slice(self::$args_cache, $after_index + 1); } /** @@ -161,16 +154,16 @@ */ public static function getRegex(): string { - return self::$Regex; + return self::$regex; } /** * Sets a new regex pattern to use to parse the arguments. * - * @param string $Regex + * @param string $regex */ - public static function setRegex(string $Regex): void + public static function setRegex(string $regex): void { - self::$Regex = $Regex; + self::$regex = $regex; } } \ No newline at end of file