From 23c3303b67948c89d23bccebfa3fed87d021fbb4 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 13 Jun 2024 15:11:02 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- .idea/nur-sery.iml | 1 - composer.json | 1 + composer.lock | 15 ++++++++------- lib/{launch.php => _launch.php} | 2 ++ src/app/launcher.php | 4 ++-- src/str.php | 4 ++-- src/wip/app/app.php | 13 +++++++++---- tests/strTest.php | 24 ++++++++++++++++++++++++ 8 files changed, 48 insertions(+), 16 deletions(-) rename lib/{launch.php => _launch.php} (94%) create mode 100644 tests/strTest.php diff --git a/.idea/nur-sery.iml b/.idea/nur-sery.iml index 8f5e5e3..93a8f92 100644 --- a/.idea/nur-sery.iml +++ b/.idea/nur-sery.iml @@ -6,7 +6,6 @@ - diff --git a/composer.json b/composer.json index 9363e80..bfacaba 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,7 @@ } }, "bin": [ + "lib/_launch.php", "nur_bin/compctl.php", "nur_bin/compdep.php", "nur_bin/cachectl.php", diff --git a/composer.lock b/composer.lock index b73565a..c10af18 100644 --- a/composer.lock +++ b/composer.lock @@ -547,16 +547,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.1", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", "shasum": "" }, "require": { @@ -564,11 +564,12 @@ }, "conflict": { "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3,<3.2.2" + "doctrine/common": "<2.13.3 || >=3 <3.2.2" }, "require-dev": { "doctrine/collections": "^1.6.8", "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", @@ -594,7 +595,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" }, "funding": [ { @@ -602,7 +603,7 @@ "type": "tidelift" } ], - "time": "2023-03-08T13:26:56+00:00" + "time": "2024-06-12T14:39:25+00:00" }, { "name": "myclabs/php-enum", diff --git a/lib/launch.php b/lib/_launch.php similarity index 94% rename from lib/launch.php rename to lib/_launch.php index f5b4c5d..d551c96 100755 --- a/lib/launch.php +++ b/lib/_launch.php @@ -34,6 +34,8 @@ Application::run(new class extends Application { $appClass = $this->args[0] ?? null; if ($appClass === null) { self::die("Vous devez spécifier la classe de l'application"); + } elseif (!class_exists($appClass)) { + self::die("$appClass: Cette classe n'existe pas"); } $args = array_slice($this->args, 1); diff --git a/src/app/launcher.php b/src/app/launcher.php index 5f2c877..1318b47 100644 --- a/src/app/launcher.php +++ b/src/app/launcher.php @@ -8,11 +8,11 @@ use nur\sery\StateException; class launcher { static function launch(string $appClass, ...$args): int { $cmd = new Cmd([ - __DIR__."/../../lib/launch.php", + __DIR__."/../../lib/_launch.php", $appClass, ...$args, ]); - $cmd->addRedir("null"); + //$cmd->addRedir("null"); $cmd->passthru($exitcode); return $exitcode; } diff --git a/src/str.php b/src/str.php index 257344a..bb74a45 100644 --- a/src/str.php +++ b/src/str.php @@ -335,7 +335,7 @@ class str { const CAMEL_PATTERN0 = '/([A-Z0-9]+)$/A'; const CAMEL_PATTERN1 = '/([A-Z0-9]+)[A-Z]/A'; - const CAMEL_PATTERN2 = '/([^A-Z]+)/A'; + const CAMEL_PATTERN2 = '/([A-Z]?[^A-Z]+)/A'; const CAMEL_PATTERN3 = '/([A-Z][^A-Z]*)/A'; /** @@ -366,7 +366,7 @@ class str { } $parts[] = strtolower($vs[1][0]); $index = intval($vs[1][1]) + strlen($vs[1][0]); - while (preg_match(self::CAMEL_PATTERN3, $camel, $vs, PREG_OFFSET_CAPTURE, $index)) { + while (preg_match(self::CAMEL_PATTERN3, $camel, $vs, PREG_OFFSET_CAPTURE, $index) !== false && $vs) { $parts[] = strtolower($vs[1][0]); $index = intval($vs[1][1]) + strlen($vs[1][0]); } diff --git a/src/wip/app/app.php b/src/wip/app/app.php index f0455a4..a3520b9 100644 --- a/src/wip/app/app.php +++ b/src/wip/app/app.php @@ -68,10 +68,15 @@ class app { $this->projdir = $projdir = path::abspath($params["projdir"] ?? "."); $this->appcode = $appcode = $params["appcode"] ?? "app"; $this->apptype = $apptype = $params["apptype"] ?? "cli"; - # si $name est une classe, enlever le package et normaliser - $name = $params["name"] ?? $appcode; - $name = preg_replace('/.*\\\\/', "", $name); - $name = str::without_suffix("-app", str::camel2us($name)); + $name = $params["name"] ?? null; + if ($name === null) { + $name = $appcode; + } else { + # si $name est une classe, enlever le package et normaliser + $name = $params["name"] ?? $appcode; + $name = preg_replace('/.*\\\\/', "", $name); + $name = str::without_suffix("-app", str::camel2us($name, false, "-")); + } $this->name = $name; $this->title = $params["title"] ?? null; $appcode = strtoupper($appcode); diff --git a/tests/strTest.php b/tests/strTest.php new file mode 100644 index 0000000..9ff69f2 --- /dev/null +++ b/tests/strTest.php @@ -0,0 +1,24 @@ +