Skip to content

Commit 1102f8f

Browse files
committed
Upgrade to Glide 2 (Flysystem 2).
1 parent 3de5b2e commit 1102f8f

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Router::scope('/images', function ($routes) {
5555
'base_url' => '/images/',
5656

5757
// Response class for serving images. If unset (default) an instance of
58-
// \ADmad\Glide\Responses\PsrResponseFactory() will be used.
58+
// \ADmad\Glide\Response\PsrResponseFactory() will be used.
5959
// http://glide.thephpleague.com/1.0/config/responses/
6060
'response' => null,
6161
],

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"require": {
3131
"cakephp/cakephp": "^4.0.2",
32-
"league/glide": "^1.6"
32+
"league/glide": "^2.0"
3333
},
3434
"require-dev": {
3535
"phpunit/phpunit": "^8.5 || ^9.3"

src/Middleware/GlideMiddleware.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use ADmad\Glide\Exception\ResponseException;
77
use ADmad\Glide\Exception\SignatureException;
8-
use ADmad\Glide\Responses\PsrResponseFactory;
8+
use ADmad\Glide\Response\PsrResponseFactory;
99
use Cake\Core\InstanceConfigTrait;
1010
use Cake\Event\EventDispatcherInterface;
1111
use Cake\Event\EventDispatcherTrait;
@@ -180,7 +180,7 @@ protected function _checkModified(ServerRequestInterface $request, Server $serve
180180
try {
181181
/** @var int|string|false $modifiedTime */
182182
$modifiedTime = $server->getSource()
183-
->getTimestamp($server->getSourcePath($this->_path));
183+
->lastModified($server->getSourcePath($this->_path));
184184
} catch (Exception $exception) {
185185
return $this->_handleException($request, $exception);
186186
}
@@ -254,13 +254,10 @@ protected function _passThrough(ServerRequestInterface $request, Server $server)
254254
$path = $server->getSourcePath($this->_path);
255255

256256
$resource = $source->readStream($path);
257-
if ($resource === false) {
258-
throw new ResponseException();
259-
}
260257
$stream = new Stream($resource);
261258

262-
$contentType = $source->getMimetype($path);
263-
$contentLength = $source->getSize($path);
259+
$contentType = $source->mimeType($path);
260+
$contentLength = $source->fileSize($path);
264261

265262
/** @psalm-suppress PossiblyFalseArgument */
266263
return (new Response())->withBody($stream)
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace ADmad\Glide\Responses;
4+
namespace ADmad\Glide\Response;
55

66
use ADmad\Glide\Exception\ResponseException;
77
use Cake\Http\Response;
88
use Laminas\Diactoros\Stream;
9-
use League\Flysystem\FilesystemInterface;
10-
use League\Glide\Filesystem\FilesystemException;
9+
use League\Flysystem\FilesystemOperator;
1110
use League\Glide\Responses\ResponseFactoryInterface;
1211

1312
class PsrResponseFactory implements ResponseFactoryInterface
1413
{
1514
/**
1615
* Create response.
1716
*
18-
* @param \League\Flysystem\FilesystemInterface $cache Cache file system.
17+
* @param \League\Flysystem\FilesystemOperator $cache Cache file system.
1918
* @param string $path Cached file path.
2019
* @return \Psr\Http\Message\ResponseInterface Response object.
2120
*/
22-
public function create(FilesystemInterface $cache, $path)
21+
public function create(FilesystemOperator $cache, $path)
2322
{
2423
$resource = $cache->readStream($path);
2524
if ($resource === false) {
2625
throw new ResponseException();
2726
}
2827
$stream = new Stream($resource);
2928

30-
$contentType = $cache->getMimetype($path);
31-
$contentLength = $cache->getSize($path);
32-
33-
if ($contentType === false) {
34-
throw new FilesystemException('Unable to determine the image content type.');
35-
}
36-
37-
if ($contentLength === false) {
38-
throw new FilesystemException('Unable to determine the image content length.');
39-
}
29+
$contentType = $cache->mimeType($path);
30+
$contentLength = $cache->fileSize($path);
4031

4132
return (new Response())->withBody($stream)
4233
->withHeader('Content-Type', $contentType)

0 commit comments

Comments
 (0)