diff --git a/.env b/.env
index 6292e2c..f4f6972 100644
--- a/.env
+++ b/.env
@@ -39,3 +39,6 @@ FORCE_TOKEN=
# Signed URL secret (empty = URL signing disabled)
SIGNATURE_SECRET=
+
+# App version
+APP_VERSION=
diff --git a/.github/workflows/deploy-lambda.yaml b/.github/workflows/deploy-lambda.yaml
index 84fa17f..7788611 100644
--- a/.github/workflows/deploy-lambda.yaml
+++ b/.github/workflows/deploy-lambda.yaml
@@ -41,6 +41,10 @@ jobs:
echo "bref:" >> serverless.yml
echo " team: babeuloula" >> serverless.yml
+ - name: Inject tag version into .env
+ if: github.ref_type == 'tag'
+ run: sed -i "s/APP_VERSION=/APP_VERSION=${{ github.ref_name }}/" .env
+
- run: bref deploy --env=prod
env:
BREF_TOKEN: ${{ secrets.BREF_TOKEN }}
diff --git a/phpmd-ruleset.xml b/phpmd-ruleset.xml
index d046a71..920c05e 100644
--- a/phpmd-ruleset.xml
+++ b/phpmd-ruleset.xml
@@ -32,7 +32,11 @@
-
+
+
+
+
+
diff --git a/src/Cdn.php b/src/Cdn.php
index 44b45a5..9d2625b 100644
--- a/src/Cdn.php
+++ b/src/Cdn.php
@@ -54,6 +54,7 @@ public function __construct(
private readonly LoggerInterface $logger,
private readonly string $forceToken = '',
private readonly ?UrlSigner $urlSigner = null,
+ private readonly string $appVersion = '',
) {
}
@@ -68,7 +69,7 @@ public function handleRequest(Request $request): Response
try {
$this->validate($decoder);
} catch (EmptyUriException) {
- return new Response('Welcome to your CDN PHP (https://github.com/babeuloula/cdn-php)', Response::HTTP_OK);
+ return new Response($this->getWelcomeMessage(), Response::HTTP_OK);
} catch (CdnException $e) {
return new Response($e->getMessage(), $e->getCode());
}
@@ -276,4 +277,14 @@ private function validate(UriDecoder $decoder): void
}
}
}
+
+ private function getWelcomeMessage(): string
+ {
+ $welcome = 'Welcome to your CDN PHP (https://github.com/babeuloula/cdn-php)';
+ if ('' !== $this->appVersion) {
+ $welcome .= " (v{$this->appVersion})";
+ }
+
+ return $welcome;
+ }
}
diff --git a/src/Container.php b/src/Container.php
index ec322ae..89e3669 100644
--- a/src/Container.php
+++ b/src/Container.php
@@ -74,6 +74,7 @@ public function boot(): void
$this->get(LoggerInterface::class),
$this->get(self::KEY_FORCE_TOKEN),
$urlSigner,
+ $this->getEnv('APP_VERSION') ?? '',
),
);
}
diff --git a/tests/Cdn/CdnTest.php b/tests/Cdn/CdnTest.php
index 613dfcb..5e89e4e 100644
--- a/tests/Cdn/CdnTest.php
+++ b/tests/Cdn/CdnTest.php
@@ -71,6 +71,29 @@ public function canHandleRequestWithEmptyUri(): void
static::assertSame(Response::HTTP_OK, $response->getStatusCode());
}
+ #[Test]
+ public function canHandleRequestWithEmptyUriAndVersion(): void
+ {
+ $cdn = new Cdn(
+ $this->getContainer('allowed_domains'),
+ $this->getContainer('domains_aliases'),
+ $this->getContainer(Storage::class),
+ $this->getContainer(ImageProcessor::class),
+ $this->getContainer(StaticAssetProcessor::class),
+ $this->getContainer(Cache::class),
+ $this->getContainer(LoggerInterface::class),
+ '',
+ null,
+ '1.2.3'
+ );
+ $request = Request::create('');
+
+ $response = $cdn->handleRequest($request);
+
+ static::assertSame(Response::HTTP_OK, $response->getStatusCode());
+ static::assertStringContainsString('(v1.2.3)', $response->getContent());
+ }
+
#[Test]
public function cantHandleRequestInvalidUri(): void
{