From 95c503645b83a77f8f8f29ff07bfc9cbe9d10150 Mon Sep 17 00:00:00 2001 From: "benedikt.schaller" Date: Tue, 4 Feb 2025 18:09:08 +0100 Subject: [PATCH 1/2] =?UTF-8?q?ACFIVE-48435=20H=C3=A4ufige=20Fehlermeldung?= =?UTF-8?q?=20auf=20IU=20Cron-Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - also support cli request in the url, to be failure tolerant --- Dockerfile | 4 ++-- composer.json | 1 + docker-compose.yaml | 3 +-- src/Http/Url/Url.php | 25 +++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d85cd0..e1efc9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM php:7.4-cli +FROM php:8.2-cli RUN pecl install xdebug RUN apt-get update RUN apt-get install -y libicu-dev zip unzip RUN docker-php-ext-enable xdebug -RUN docker-php-ext-install intl \ No newline at end of file +RUN docker-php-ext-install intl diff --git a/composer.json b/composer.json index 0187a6f..6c0670d 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "version": "1.0.0", "name": "simovative/zeus", "description": "A Post-Redirect-Get specialised framework for PHP", "keywords": [ diff --git a/docker-compose.yaml b/docker-compose.yaml index 9a66ad4..865feee 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: "3.9" services: php-cli: build: . @@ -7,4 +6,4 @@ services: type: bind target: /usr/src/myapp tty: true - working_dir: /usr/src/myapp \ No newline at end of file + working_dir: /usr/src/myapp diff --git a/src/Http/Url/Url.php b/src/Http/Url/Url.php index 1667830..7d60e37 100644 --- a/src/Http/Url/Url.php +++ b/src/Http/Url/Url.php @@ -25,6 +25,28 @@ public function __construct($url) { $this->url = $url; } + private static function createFromCliRequest(array $serverArray): Url + { + $url = 'cli://'; + # Add hostname + $hostname = gethostname(); + if ($hostname !== false) { + $url .= $hostname; + } else { + $hostname = 'unknown'; + } + # Add script name + if (! empty($serverArray['argv'])) { + $url .= '/' . $serverArray['argv'][0]; + } + return new self($url); + } + + private static function isCliRequest(): bool + { + return PHP_SAPI === 'cli'; + } + /** * @author mnoerenberg * @return string @@ -106,6 +128,9 @@ public function getFragment(): string { * @return Url */ public static function createFromServerArray(array $serverArray): Url { + if (self::isCliRequest()) { + return self::createFromCliRequest($serverArray); + } if (self::isForwardedRequest($serverArray)) { return self::createUrlForForwardedRequest($serverArray); } From 70e3eeeb094340551d9862efe829eeda5adb720e Mon Sep 17 00:00:00 2001 From: "benedikt.schaller" Date: Tue, 4 Feb 2025 18:31:07 +0100 Subject: [PATCH 2/2] =?UTF-8?q?ACFIVE-48435=20H=C3=A4ufige=20Fehlermeldung?= =?UTF-8?q?=20auf=20IU=20Cron-Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add url test for cli requests --- src/Http/Url/Url.php | 6 +++--- tests/Unit/Http/Url/UrlTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Http/Url/Url.php b/src/Http/Url/Url.php index 7d60e37..3e93bb7 100644 --- a/src/Http/Url/Url.php +++ b/src/Http/Url/Url.php @@ -42,9 +42,9 @@ private static function createFromCliRequest(array $serverArray): Url return new self($url); } - private static function isCliRequest(): bool + private static function isCliRequest(array $serverArray): bool { - return PHP_SAPI === 'cli'; + return ! empty($serverArray['argv']); } /** @@ -128,7 +128,7 @@ public function getFragment(): string { * @return Url */ public static function createFromServerArray(array $serverArray): Url { - if (self::isCliRequest()) { + if (self::isCliRequest($serverArray)) { return self::createFromCliRequest($serverArray); } if (self::isForwardedRequest($serverArray)) { diff --git a/tests/Unit/Http/Url/UrlTest.php b/tests/Unit/Http/Url/UrlTest.php index f902a8a..e235f12 100644 --- a/tests/Unit/Http/Url/UrlTest.php +++ b/tests/Unit/Http/Url/UrlTest.php @@ -15,6 +15,8 @@ class UrlTest extends TestCase { private const URL_WITH_CREDENTIALS = 'https://username:password@www.simovative.com:443/api/v1/event/20?param=1&user=1#myFragment'; private const URL = 'https://www.simovative.com/api/v1/event/20?param=1&user=1#myFragment'; + + private const URL_PATTERN_CLI = '#^cli\:\/\/[^\/]+\/bin\/cli\.php$#'; private const URL_HTTPS = 'on'; private const URL_REQUEST_URI = '/api/v1/event/20?param=1&user=1#myFragment'; private const URL_SERVER_PORT = 443; @@ -179,4 +181,14 @@ public function testThatUrlIsCorrectlyParsedFromForwardedServerArray(): void $url = Url::createFromServerArray($serverArray); self::assertEquals(self::URL, $url->__toString()); } + + public function testThatUrlIsCorrectlyParsedFromCliRequest(): void + { + $serverArray = [ + 'argv' => ['bin/cli.php'], + 'argc' => 1, + ]; + $url = Url::createFromServerArray($serverArray); + self::assertMatchesRegularExpression(self::URL_PATTERN_CLI, $url->__toString()); + } }