From e2b842c29dfe23717f39cc0cc0e47dc2a39efaf8 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 28 Mar 2022 21:28:38 +0200 Subject: [PATCH] improve cli argument handling --- Message/Console/ConsoleRequest.php | 7 +++++++ Module/ModuleAbstract.php | 2 -- Module/StatusAbstract.php | 1 - Uri/Argument.php | 3 +++ Utils/ArrayUtils.php | 8 +++----- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Message/Console/ConsoleRequest.php b/Message/Console/ConsoleRequest.php index cf93688e9..f69e7e1a6 100644 --- a/Message/Console/ConsoleRequest.php +++ b/Message/Console/ConsoleRequest.php @@ -111,6 +111,13 @@ final class ConsoleRequest extends RequestAbstract } } + public function hasData(string $key) : bool + { + $key = '-' . \mb_strtolower($key); + + return ArrayUtils::hasArg($key, $this->data) > -1; + } + /** * Set request data. * diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 9e2b30d69..f1a8280b4 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -14,9 +14,7 @@ declare(strict_types=1); namespace phpOMS\Module; -use Modules\Admin\Models\PermissionAbstractMapper; use phpOMS\Application\ApplicationAbstract; -use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\System\MimeType; diff --git a/Module/StatusAbstract.php b/Module/StatusAbstract.php index 5acf26d0a..f363d0f72 100644 --- a/Module/StatusAbstract.php +++ b/Module/StatusAbstract.php @@ -16,7 +16,6 @@ namespace phpOMS\Module; use phpOMS\Application\ApplicationAbstract; use phpOMS\Application\ApplicationInfo; -use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\System\File\Local\Directory; use phpOMS\System\File\Local\File; use phpOMS\System\File\PathException; diff --git a/Uri/Argument.php b/Uri/Argument.php index 669d164ea..c3c0670e4 100644 --- a/Uri/Argument.php +++ b/Uri/Argument.php @@ -169,6 +169,9 @@ final class Argument implements UriInterface $uriParts = \explode(' ', $uri); + // Handle no path information only data + $uriParts = \stripos($uriParts[0], '-') === 0 ? ['/', $uriParts[0]] : $uriParts; + $this->path = \array_shift($uriParts); $this->pathElements = \explode('/', \ltrim($this->path, '/')); diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 04de37098..2b7cf1dc3 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -292,11 +292,9 @@ final class ArrayUtils */ public static function hasArg(string $id, array $args) : int { - if (($key = \array_search($id, $args)) === false) { - return -1; - } - - return (int) $key; + return ($key = \array_search($id, $args)) === false + ? -1 + : (int) $key; } /**