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 .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = true
[*.yml]
indent_style = space
indent_size = 2

[*.neon]
indent_style = tab
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ permissions:
jobs:
testsuite:
uses: ADmad/.github/.github/workflows/testsuite-without-db.yml@master
secrets: inherit
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

cs-stan:
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"issues":"https://github.com/ADmad/cakephp-glide/issues"
},
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0",
"league/glide": "^2.3"
"league/glide": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^10.1"
Expand Down
10 changes: 6 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
parameters:
level: 8
checkMissingIterableValueType: false
paths:
- src/
level: 8
paths:
- src/
ignoreErrors:
-
identifier: missingType.iterableValue
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
ensureOverrideAttribute="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<ClassMustBeFinal errorLevel="suppress"/>
</issueHandlers>
</psalm>
17 changes: 5 additions & 12 deletions src/Middleware/GlideMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$response = $this->_withCacheHeaders(
$response,
$config['cacheTime'],
$modifiedTime
$modifiedTime,
);
}

Expand Down Expand Up @@ -165,7 +165,7 @@ protected function _checkSignature(ServerRequestInterface $request): void
try {
SignatureFactory::create($signKey)->validateRequest(
$this->_path,
$request->getQueryParams()
$request->getQueryParams(),
);
} catch (Exception $exception) {
throw new SignatureException($exception->getMessage(), null, $exception);
Expand All @@ -184,28 +184,21 @@ protected function _checkSignature(ServerRequestInterface $request): void
*/
protected function _checkModified(ServerRequestInterface $request, Server $server): ResponseInterface|int|null
{
$modifiedTime = false;

try {
/** @var string|int|false $modifiedTime */
$modifiedTime = $server->getSource()
->lastModified($server->getSourcePath($this->_path));
} catch (Exception $exception) {
return $this->_handleException($request, $exception);
}

if ($modifiedTime === false) {
return null;
}

if ($this->_isNotModified($request, $modifiedTime)) {
$response = new Response(['status' => 304]);
$response = $this->_withCustomHeaders($response);

return $response->withHeader('Last-Modified', (string)$modifiedTime);
}

return (int)$modifiedTime;
return $modifiedTime;
}

/**
Expand Down Expand Up @@ -306,7 +299,7 @@ protected function _isNotModified(ServerRequestInterface $request, string|int $m
protected function _withCacheHeaders(
ResponseInterface $response,
string $cacheTime,
string|int $modifiedTime
string|int $modifiedTime,
): ResponseInterface {
/** @var int $expire */
$expire = strtotime($cacheTime);
Expand Down Expand Up @@ -346,7 +339,7 @@ protected function _handleException(ServerRequestInterface $request, Exception $
{
$event = $this->dispatchEvent(
static::RESPONSE_FAILURE_EVENT,
compact('request', 'exception')
compact('request', 'exception'),
);
$result = $event->getResult();

Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/GlideHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function image(string $path, array $params = [], array $options = []): st
{
return $this->Html->image(
$this->url($path, $params + ['_base' => false]),
$options
$options,
);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ public function urlBuilder(?UrlBuilder $urlBuilder = null): UrlBuilder

$this->_urlBuilder = UrlBuilderFactory::create(
$config['baseUrl'],
$config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null
$config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null,
);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Middleware/GlideMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function setUp(): void

$this->request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/images/cake-logo.png'],
['w' => '100']
['w' => '100'],
);
$this->handler = new TestRequestHandler();

Expand All @@ -63,7 +63,7 @@ public function testServerCallable()
$config = $this->config;
$config['server'] = function () {
return ServerFactory::create(
$this->config['server'] + ['base_url' => '/images']
$this->config['server'] + ['base_url' => '/images'],
);
};

Expand All @@ -81,7 +81,7 @@ public function testAllowedParams()

$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/images/cake-logo.png'],
['w' => '100', 'foo' => 'bar']
['w' => '100', 'foo' => 'bar'],
);

$middleware = new GlideMiddleware($this->config);
Expand All @@ -108,7 +108,7 @@ public function testOriginalPassThrough()
$this->assertNotSame(
$fileSize,
(int)$headers['Content-Length'][0],
'Content length shouldnt be same as original filesize since glide always generates new file.'
'Content length shouldnt be same as original filesize since glide always generates new file.',
);

exec('rm -rf ' . TMP . 'cache/cake-logo.png');
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testSecureUrl()

$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/images/cake%20logo.png'],
['w' => 100, 's' => $sig]
['w' => 100, 's' => $sig],
);

$middleware = new GlideMiddleware($this->config);
Expand All @@ -169,7 +169,7 @@ public function testCache()
'REQUEST_URI' => '/images/cake-logo.png',
'HTTP_IF_MODIFIED_SINCE' => $headers['Last-Modified'][0],
],
['w' => '100']
['w' => '100'],
);

$middleware = new GlideMiddleware($this->config);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/View/Helper/GlideHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testUrl()
$this->assertEquals('/images/logo.png?w=100', $result);

$this->helper->getView()->setRequest(
$this->helper->getView()->getRequest()->withAttribute('webroot', '/subfolder/')
$this->helper->getView()->getRequest()->withAttribute('webroot', '/subfolder/'),
);
$result = $this->helper->url('logo.png', ['w' => 100]);
$this->assertEquals('/subfolder/images/logo.png?w=100', $result);
Expand All @@ -58,7 +58,7 @@ public function testImage()

Router::setRequest(
$this->helper->getView()->getRequest()
->withAttribute('webroot', '/subfolder/')
->withAttribute('webroot', '/subfolder/'),
);
$result = $this->helper->image('logo.png', ['w' => 100], ['width' => 100]);
$this->assertHtml([
Expand Down