Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
RUN docker-php-ext-install intl
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": "1.0.0",
"name": "simovative/zeus",
"description": "A Post-Redirect-Get specialised framework for PHP",
"keywords": [
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.9"
services:
php-cli:
build: .
Expand All @@ -7,4 +6,4 @@ services:
type: bind
target: /usr/src/myapp
tty: true
working_dir: /usr/src/myapp
working_dir: /usr/src/myapp
25 changes: 25 additions & 0 deletions src/Http/Url/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(array $serverArray): bool
{
return ! empty($serverArray['argv']);
}

/**
* @author mnoerenberg
* @return string
Expand Down Expand Up @@ -106,6 +128,9 @@ public function getFragment(): string {
* @return Url
*/
public static function createFromServerArray(array $serverArray): Url {
if (self::isCliRequest($serverArray)) {
return self::createFromCliRequest($serverArray);
}
if (self::isForwardedRequest($serverArray)) {
return self::createUrlForForwardedRequest($serverArray);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Http/Url/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}