Bumped version to 1.1.0
- Updated optslib to work with ncc 2.+. - Fixed code-smell from optslib.
This commit is contained in:
parent
62ded30363
commit
d15eb47ef1
7 changed files with 96 additions and 42 deletions
3
.idea/inspectionProfiles/Project_Default.xml
generated
3
.idea/inspectionProfiles/Project_Default.xml
generated
|
@ -19,6 +19,9 @@
|
||||||
<option value="X-Args-3" />
|
<option value="X-Args-3" />
|
||||||
<option value="X-Args-4" />
|
<option value="X-Args-4" />
|
||||||
<option value="X-Args-5" />
|
<option value="X-Args-5" />
|
||||||
|
<option value="X-Temperature" />
|
||||||
|
<option value="X-Model" />
|
||||||
|
<option value="X-OPENAI-API-KEY" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
|
20
.idea/php-inspections-ea-ultimate.xml
generated
Normal file
20
.idea/php-inspections-ea-ultimate.xml
generated
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EAUltimateProjectSettings">
|
||||||
|
<categories>
|
||||||
|
<STRICTNESS_CATEGORY_SECURITY enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_PROBABLE_BUGS enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_PERFORMANCE enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_ARCHITECTURE enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_CONTROL_FLOW enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_LANGUAGE_LEVEL_MIGRATION enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_CODE_STYLE enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_UNUSED enabled="yes" />
|
||||||
|
<STRICTNESS_CATEGORY_PHPUNIT enabled="yes" />
|
||||||
|
</categories>
|
||||||
|
<settings>
|
||||||
|
<ANALYZE_ONLY_MODIFIED_FILES value="no" />
|
||||||
|
<PREFER_YODA_COMPARISON_STYLE value="no" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
|
</project>
|
5
.idea/php.xml
generated
5
.idea/php.xml
generated
|
@ -9,6 +9,11 @@
|
||||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PhpIncludePathManager">
|
||||||
|
<include_path>
|
||||||
|
<path value="/usr/share/php" />
|
||||||
|
</include_path>
|
||||||
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.1">
|
<component name="PhpProjectSharedConfiguration" php_language_level="7.1">
|
||||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|
14
.idea/webResources.xml
generated
Executable file
14
.idea/webResources.xml
generated
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="WebResourcesPaths">
|
||||||
|
<contentEntries>
|
||||||
|
<entry url="file://$PROJECT_DIR$">
|
||||||
|
<entryData>
|
||||||
|
<resourceRoots>
|
||||||
|
<path value="file://$PROJECT_DIR$/assets" />
|
||||||
|
</resourceRoots>
|
||||||
|
</entryData>
|
||||||
|
</entry>
|
||||||
|
</contentEntries>
|
||||||
|
</component>
|
||||||
|
</project>
|
17
CHANGELOG.md
17
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.
|
Initial release of ConfigLib.
|
|
@ -21,7 +21,7 @@
|
||||||
"package": "net.nosial.optslib",
|
"package": "net.nosial.optslib",
|
||||||
"copyright": "Copyright (c) 2022-2023 Nosial",
|
"copyright": "Copyright (c) 2022-2023 Nosial",
|
||||||
"description": "A simple options parser library for PHP",
|
"description": "A simple options parser library for PHP",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"uuid": "20aefdfa-7b91-11ed-919f-cb63712c8e36"
|
"uuid": "20aefdfa-7b91-11ed-919f-cb63712c8e36"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
@ -30,6 +30,10 @@
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "release",
|
"name": "release",
|
||||||
|
"build_type": "ncc",
|
||||||
|
"options": {
|
||||||
|
"compression": "high"
|
||||||
|
},
|
||||||
"output_path": "build/release"
|
"output_path": "build/release"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -26,14 +26,14 @@
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $Regex = "/(?(?=-)-(?(?=-)-(?'bigflag'[^\\s=]+)|(?'smallflag'\\S))(?:\\s*=\\s*|\\s+)(?(?!-)(?(?=[\\\"\\'])((?<![\\\\])['\"])(?'string'(?:.(?!(?<![\\\\])\\3))*.?)\\3|(?'value'\\S+)))(?:\\s+)?|(?'unmatched'\\S+))/";
|
private static $regex = "/(?(?=-)-(?(?=-)-(?'bigflag'[^\\s=]+)|(?'smallflag'\\S))(?:\\s*=\\s*|\\s+)(?(?!-)(?(?=[\\\"\\'])((?<![\\\\])['\"])(?'string'(?:.(?!(?<![\\\\])\\3))*.?)\\3|(?'value'\\S+)))(?:\\s+)?|(?'unmatched'\\S+))/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache of the parsed arguments. This is used to prevent the arguments from being parsed more than once.
|
* Cache of the parsed arguments. This is used to prevent the arguments from being parsed more than once.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $ArgsCache;
|
private static $args_cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the input arguments into an array of flags and values
|
* Parses the input arguments into an array of flags and values
|
||||||
|
@ -63,42 +63,43 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$configs = array();
|
$configs = array();
|
||||||
preg_match_all(self::$Regex, $flags, $matches, PREG_SET_ORDER);
|
preg_match_all(self::$regex, $flags, $matches, PREG_SET_ORDER);
|
||||||
|
|
||||||
foreach ($matches as $index => $match)
|
foreach ($matches as $index => $match)
|
||||||
{
|
{
|
||||||
if (isset($match['value']) && $match['value'] !== '')
|
if(isset($match['value']) && $match['value'] !== '')
|
||||||
{
|
{
|
||||||
$value = $match['value'];
|
$value = $match['value'];
|
||||||
}
|
}
|
||||||
else if (isset($match['string']) && $match['string'] !== '')
|
elseif(isset($match['string']) && $match['string'] !== '')
|
||||||
{
|
{
|
||||||
// fix escaped quotes
|
// fix escaped quotes
|
||||||
$value = str_replace("\\\"", "\"", $match['string']);
|
$value = str_replace(["\\\"", "\\'"], ["\"", "'"], $match['string']);
|
||||||
$value = str_replace("\\'", "'", $value);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$value = true;
|
$value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($match['bigflag']) && $match['bigflag'] !== '')
|
if(isset($match['bigflag']) && $match['bigflag'] !== '')
|
||||||
{
|
{
|
||||||
$configs[$match['bigflag']] = $value;
|
$configs[$match['bigflag']] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($match['smallflag']) && $match['smallflag'] !== '')
|
if(isset($match['smallflag']) && $match['smallflag'] !== '')
|
||||||
{
|
{
|
||||||
$configs[$match['smallflag']] = $value;
|
$configs[$match['smallflag']] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($match['unmatched']) && $match['unmatched'] !== '')
|
if(isset($match['unmatched']) && $match['unmatched'] !== '')
|
||||||
{
|
{
|
||||||
$configs[$match['unmatched']] = true;
|
$configs[$match['unmatched']] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($index >= $max_arguments)
|
if($index >= $max_arguments)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $configs;
|
return $configs;
|
||||||
|
@ -113,45 +114,37 @@
|
||||||
public static function getArguments(?string $after=null): array
|
public static function getArguments(?string $after=null): array
|
||||||
{
|
{
|
||||||
global $argv;
|
global $argv;
|
||||||
if(self::$ArgsCache == null)
|
|
||||||
|
if($argv === null)
|
||||||
|
{
|
||||||
|
$argv = $_SERVER['argv'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self::$args_cache === null)
|
||||||
{
|
{
|
||||||
if(isset($argv))
|
if(isset($argv))
|
||||||
{
|
{
|
||||||
self::$ArgsCache = self::parseArgument($argv);
|
self::$args_cache = self::parseArgument($argv);
|
||||||
}
|
}
|
||||||
else
|
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));
|
return [];
|
||||||
|
|
||||||
if($after_index === false)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return array_slice(self::$ArgsCache, $after_index + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return array_slice(self::$args_cache, $after_index + 1);
|
||||||
* Returns the cached arguments
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getArgsCache(): array
|
|
||||||
{
|
|
||||||
return self::$ArgsCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,16 +154,16 @@
|
||||||
*/
|
*/
|
||||||
public static function getRegex(): string
|
public static function getRegex(): string
|
||||||
{
|
{
|
||||||
return self::$Regex;
|
return self::$regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a new regex pattern to use to parse the arguments.
|
* 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue