From 765f68cf0967c36d6a3c922d380ecf03350cf07a Mon Sep 17 00:00:00 2001 From: Matthias von Bargen Date: Sun, 9 Jun 2024 18:18:03 +0200 Subject: [PATCH] upgrade caddy version and introduce phpmnd (#18) --- .github/workflows/ci_cd.yml | 3 ++- composer.json | 9 ++++++--- docker/caddy/Dockerfile | 3 +-- src/Caddy.php | 9 +++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 36ddd06..79698c7 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -68,7 +68,7 @@ jobs: pull-image: true # Raise the flag to try to pull image phpunit: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: - build-caddy-image - build-composer-image @@ -94,6 +94,7 @@ jobs: docker run -v $(pwd):/app docker.pkg.github.com/mattvb91/${{ env.REPO_NAME }}/composer:head composer phpstan docker run -v $(pwd):/app docker.pkg.github.com/mattvb91/${{ env.REPO_NAME }}/composer:head composer codesniffer docker run -v $(pwd):/app docker.pkg.github.com/mattvb91/${{ env.REPO_NAME }}/composer:head composer rector + docker run -v $(pwd):/app docker.pkg.github.com/mattvb91/${{ env.REPO_NAME }}/composer:head composer phpmnd docker run --network="caddy-network" -e XDEBUG_MODE=coverage -v $(pwd):/app docker.pkg.github.com/mattvb91/${{ env.REPO_NAME }}/composer:head composer phpunit env: REPO_NAME: ${{ github.event.repository.name }} diff --git a/composer.json b/composer.json index 0ab0acc..f0c59b5 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "codesniffer": "phpcs ./src ./tests/**/*.php --standard=./codesniffer.xml -p", "codefixer": "phpcbf ./src ./tests/**/*.php --standard=./codesniffer.xml", "rector": "rector process --dry-run", - "rector-fix": "rector process" + "rector-fix": "rector process", + "phpmnd": "phpmnd ./src" }, "autoload": { "psr-4": { @@ -26,13 +27,15 @@ }, "require": { "php": "^8.1", - "guzzlehttp/guzzle": "^7.0" + "guzzlehttp/guzzle": "^7.0", + "symfony/http-foundation": "^7.1" }, "require-dev": { "phpunit/phpunit": "^9.5", "dms/phpunit-arraysubset-asserts": "^0.4.0", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.7", - "rector/rector": "^0.17" + "rector/rector": "^1.0", + "povils/phpmnd": "^3.5" } } diff --git a/docker/caddy/Dockerfile b/docker/caddy/Dockerfile index 6cf3002..d1b2f86 100644 --- a/docker/caddy/Dockerfile +++ b/docker/caddy/Dockerfile @@ -1,9 +1,8 @@ -FROM caddy:2.6.0-builder-alpine +FROM caddy:2.8.4-builder-alpine RUN xcaddy build --with github.com/darkweak/souin/plugins/caddy@a2e88383a2bced983914cc12bde413ad8887b56d \ --with github.com/darkweak/souin@a2e88383a2bced983914cc12bde413ad8887b56d - # See https://caddyserver.com/docs/conventions#file-locations for details ENV XDG_CONFIG_HOME /config ENV XDG_DATA_HOME /data diff --git a/src/Caddy.php b/src/Caddy.php index 3ab779f..47990ed 100644 --- a/src/Caddy.php +++ b/src/Caddy.php @@ -13,6 +13,7 @@ use mattvb91\CaddyPhp\Exceptions\CaddyClientException; use mattvb91\CaddyPhp\Interfaces\App; use mattvb91\CaddyPhp\Interfaces\Arrayable; +use Symfony\Component\HttpFoundation\Response; class Caddy implements Arrayable { @@ -94,7 +95,7 @@ public function addHostname(string $hostIdentifier, string $hostname): bool if ( $this->client->put($this->hostsCache[$hostIdentifier]['path'] . '/0', [ 'json' => $hostname, - ])->getStatusCode() === 200 + ])->getStatusCode() === Response::HTTP_OK ) { $this->hostsCache[$hostIdentifier]['host']->addHost($hostname); return true; @@ -116,7 +117,7 @@ public function removeHostname(string $hostIdentifier, string $hostname): bool if ( $this->client->delete($path, [ 'json' => $hostname, - ])->getStatusCode() === 200 + ])->getStatusCode() === Response::HTTP_OK ) { $this->hostsCache[$hostIdentifier]['host']->syncRemoveHost($hostname); return true; @@ -159,7 +160,7 @@ public function flushSurrogates(array $surrogates): bool 'Surrogate-Key' => implode(', ', $surrogates), 'Host' => $this->cacheHostnameHeader, ], - ])->getStatusCode() === 204; + ])->getStatusCode() === Response::HTTP_NO_CONTENT; } /** @@ -171,7 +172,7 @@ public function load(): bool try { return $this->client->post('/load', [ 'json' => $this->toArray(), - ])->getStatusCode() === 200; + ])->getStatusCode() === Response::HTTP_OK; } catch (ClientException $e) { throw new CaddyClientException( $e->getResponse()->getBody() . PHP_EOL . json_encode($this->toArray(), JSON_PRETTY_PRINT)