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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ FORCE_TOKEN=

# Signed URL secret (empty = URL signing disabled)
SIGNATURE_SECRET=

# App version
APP_VERSION=
4 changes: 4 additions & 0 deletions .github/workflows/deploy-lambda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
6 changes: 5 additions & 1 deletion phpmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
<properties>
<property name="minimum" value="15"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/TooManyFields"/>
<rule ref="rulesets/codesize.xml/TooManyMethods">
Expand Down
13 changes: 12 additions & 1 deletion src/Cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct(
private readonly LoggerInterface $logger,
private readonly string $forceToken = '',
private readonly ?UrlSigner $urlSigner = null,
private readonly string $appVersion = '',
) {
}

Expand All @@ -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());
}
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function boot(): void
$this->get(LoggerInterface::class),
$this->get(self::KEY_FORCE_TOKEN),
$urlSigner,
$this->getEnv('APP_VERSION') ?? '',
),
);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Cdn/CdnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading