Skip to content

Commit a5f4e97

Browse files
authored
Merge pull request #40 from ADmad/glide-v3
Bump up to Glide v3
2 parents ea696b3 + 57d6662 commit a5f4e97

File tree

9 files changed

+33
-28
lines changed

9 files changed

+33
-28
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ trim_trailing_whitespace = true
1313
[*.yml]
1414
indent_style = space
1515
indent_size = 2
16+
17+
[*.neon]
18+
indent_style = tab

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ permissions:
1414
jobs:
1515
testsuite:
1616
uses: ADmad/.github/.github/workflows/testsuite-without-db.yml@master
17-
secrets: inherit
17+
secrets:
18+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1819

1920
cs-stan:
2021
uses: ADmad/.github/.github/workflows/cs-stan.yml@master

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"issues":"https://github.com/ADmad/cakephp-glide/issues"
2929
},
3030
"require": {
31+
"php": ">=8.1",
3132
"cakephp/cakephp": "^5.0",
32-
"league/glide": "^2.3"
33+
"league/glide": "^3.0"
3334
},
3435
"require-dev": {
3536
"phpunit/phpunit": "^10.1"

phpstan.neon

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
2-
level: 8
3-
checkMissingIterableValueType: false
4-
paths:
5-
- src/
2+
level: 8
3+
paths:
4+
- src/
5+
ignoreErrors:
6+
-
7+
identifier: missingType.iterableValue

psalm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
77
findUnusedBaselineEntry="true"
88
findUnusedCode="false"
9+
ensureOverrideAttribute="false"
910
>
1011
<projectFiles>
1112
<directory name="src" />
1213
<ignoreFiles>
1314
<directory name="vendor" />
1415
</ignoreFiles>
1516
</projectFiles>
17+
18+
<issueHandlers>
19+
<ClassMustBeFinal errorLevel="suppress"/>
20+
</issueHandlers>
1621
</psalm>

src/Middleware/GlideMiddleware.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
124124
$response = $this->_withCacheHeaders(
125125
$response,
126126
$config['cacheTime'],
127-
$modifiedTime
127+
$modifiedTime,
128128
);
129129
}
130130

@@ -165,7 +165,7 @@ protected function _checkSignature(ServerRequestInterface $request): void
165165
try {
166166
SignatureFactory::create($signKey)->validateRequest(
167167
$this->_path,
168-
$request->getQueryParams()
168+
$request->getQueryParams(),
169169
);
170170
} catch (Exception $exception) {
171171
throw new SignatureException($exception->getMessage(), null, $exception);
@@ -184,28 +184,21 @@ protected function _checkSignature(ServerRequestInterface $request): void
184184
*/
185185
protected function _checkModified(ServerRequestInterface $request, Server $server): ResponseInterface|int|null
186186
{
187-
$modifiedTime = false;
188-
189187
try {
190-
/** @var string|int|false $modifiedTime */
191188
$modifiedTime = $server->getSource()
192189
->lastModified($server->getSourcePath($this->_path));
193190
} catch (Exception $exception) {
194191
return $this->_handleException($request, $exception);
195192
}
196193

197-
if ($modifiedTime === false) {
198-
return null;
199-
}
200-
201194
if ($this->_isNotModified($request, $modifiedTime)) {
202195
$response = new Response(['status' => 304]);
203196
$response = $this->_withCustomHeaders($response);
204197

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

208-
return (int)$modifiedTime;
201+
return $modifiedTime;
209202
}
210203

211204
/**
@@ -306,7 +299,7 @@ protected function _isNotModified(ServerRequestInterface $request, string|int $m
306299
protected function _withCacheHeaders(
307300
ResponseInterface $response,
308301
string $cacheTime,
309-
string|int $modifiedTime
302+
string|int $modifiedTime,
310303
): ResponseInterface {
311304
/** @var int $expire */
312305
$expire = strtotime($cacheTime);
@@ -346,7 +339,7 @@ protected function _handleException(ServerRequestInterface $request, Exception $
346339
{
347340
$event = $this->dispatchEvent(
348341
static::RESPONSE_FAILURE_EVENT,
349-
compact('request', 'exception')
342+
compact('request', 'exception'),
350343
);
351344
$result = $event->getResult();
352345

src/View/Helper/GlideHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function image(string $path, array $params = [], array $options = []): st
5959
{
6060
return $this->Html->image(
6161
$this->url($path, $params + ['_base' => false]),
62-
$options
62+
$options,
6363
);
6464
}
6565

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

105105
$this->_urlBuilder = UrlBuilderFactory::create(
106106
$config['baseUrl'],
107-
$config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null
107+
$config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null,
108108
);
109109
}
110110

tests/TestCase/Middleware/GlideMiddlewareTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function setUp(): void
3737

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

@@ -63,7 +63,7 @@ public function testServerCallable()
6363
$config = $this->config;
6464
$config['server'] = function () {
6565
return ServerFactory::create(
66-
$this->config['server'] + ['base_url' => '/images']
66+
$this->config['server'] + ['base_url' => '/images'],
6767
);
6868
};
6969

@@ -81,7 +81,7 @@ public function testAllowedParams()
8181

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

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

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

144144
$request = ServerRequestFactory::fromGlobals(
145145
['REQUEST_URI' => '/images/cake%20logo.png'],
146-
['w' => 100, 's' => $sig]
146+
['w' => 100, 's' => $sig],
147147
);
148148

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

175175
$middleware = new GlideMiddleware($this->config);

tests/TestCase/View/Helper/GlideHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testUrl()
3232
$this->assertEquals('/images/logo.png?w=100', $result);
3333

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

5959
Router::setRequest(
6060
$this->helper->getView()->getRequest()
61-
->withAttribute('webroot', '/subfolder/')
61+
->withAttribute('webroot', '/subfolder/'),
6262
);
6363
$result = $this->helper->image('logo.png', ['w' => 100], ['width' => 100]);
6464
$this->assertHtml([

0 commit comments

Comments
 (0)