2323use Psr \Http \Server \MiddlewareInterface ;
2424use Psr \Http \Server \RequestHandlerInterface ;
2525
26+ /**
27+ * @implements \Cake\Event\EventDispatcherInterface<\ADmad\Glide\Middleware\GlideMiddleware>
28+ */
2629class GlideMiddleware implements MiddlewareInterface, EventDispatcherInterface
2730{
31+ /**
32+ * @use \Cake\Event\EventDispatcherTrait<\ADmad\Glide\Middleware\GlideMiddleware>
33+ */
2834 use EventDispatcherTrait;
35+
2936 use InstanceConfigTrait;
3037
3138 public const RESPONSE_FAILURE_EVENT = 'Glide.response_failure ' ;
@@ -35,7 +42,7 @@ class GlideMiddleware implements MiddlewareInterface, EventDispatcherInterface
3542 *
3643 * @var array
3744 */
38- protected $ _defaultConfig = [
45+ protected array $ _defaultConfig = [
3946 'path ' => null ,
4047 'cacheTime ' => '+1 days ' ,
4148 'server ' => [
@@ -56,7 +63,7 @@ class GlideMiddleware implements MiddlewareInterface, EventDispatcherInterface
5663 *
5764 * @var string
5865 */
59- protected $ _path = '' ;
66+ protected string $ _path = '' ;
6067
6168 /**
6269 * Constructor.
@@ -129,10 +136,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
129136 /**
130137 * Get glide server instance.
131138 *
132- * @param array| callable $config Config array or callable.
139+ * @param callable|array $config Config array or callable.
133140 * @return \League\Glide\Server
134141 */
135- protected function _getServer ($ config ): Server
142+ protected function _getServer (callable | array $ config ): Server
136143 {
137144 if (is_array ($ config )) {
138145 return ServerFactory::create ($ config );
@@ -148,7 +155,7 @@ protected function _getServer($config): Server
148155 * @throws \ADmad\Glide\Exception\SignatureException
149156 * @return void
150157 */
151- protected function _checkSignature (ServerRequestInterface $ request )
158+ protected function _checkSignature (ServerRequestInterface $ request ): void
152159 {
153160 if (!$ this ->getConfig ('security.secureUrls ' )) {
154161 return ;
@@ -175,12 +182,12 @@ protected function _checkSignature(ServerRequestInterface $request)
175182 * @param \League\Glide\Server $server Glide server.
176183 * @return \Psr\Http\Message\ResponseInterface|int|null
177184 */
178- protected function _checkModified (ServerRequestInterface $ request , Server $ server )
185+ protected function _checkModified (ServerRequestInterface $ request , Server $ server ): ResponseInterface | int | null
179186 {
180187 $ modifiedTime = false ;
181188
182189 try {
183- /** @var int| string|false $modifiedTime */
190+ /** @var string|int |false $modifiedTime */
184191 $ modifiedTime = $ server ->getSource ()
185192 ->lastModified ($ server ->getSourcePath ($ this ->_path ));
186193 } catch (Exception $ exception ) {
@@ -278,7 +285,7 @@ protected function _passThrough(ServerRequestInterface $request, Server $server)
278285 * @param string|int $modifiedTime Last modified time of file.
279286 * @return bool
280287 */
281- protected function _isNotModified (ServerRequestInterface $ request , $ modifiedTime )
288+ protected function _isNotModified (ServerRequestInterface $ request , string | int $ modifiedTime ): bool
282289 {
283290 $ modifiedSince = $ request ->getHeaderLine ('If-Modified-Since ' );
284291 if (!$ modifiedSince ) {
@@ -293,11 +300,14 @@ protected function _isNotModified(ServerRequestInterface $request, $modifiedTime
293300 *
294301 * @param \Psr\Http\Message\ResponseInterface $response The response.
295302 * @param string $cacheTime Cache time.
296- * @param int| string $modifiedTime Modified time.
303+ * @param string|int $modifiedTime Modified time.
297304 * @return \Psr\Http\Message\ResponseInterface
298305 */
299- protected function _withCacheHeaders (ResponseInterface $ response , string $ cacheTime , $ modifiedTime )
300- {
306+ protected function _withCacheHeaders (
307+ ResponseInterface $ response ,
308+ string $ cacheTime ,
309+ string |int $ modifiedTime
310+ ): ResponseInterface {
301311 /** @var int $expire */
302312 $ expire = strtotime ($ cacheTime );
303313 $ maxAge = $ expire - time ();
@@ -315,7 +325,7 @@ protected function _withCacheHeaders(ResponseInterface $response, string $cacheT
315325 * @param \Psr\Http\Message\ResponseInterface $response The response.
316326 * @return \Psr\Http\Message\ResponseInterface
317327 */
318- protected function _withCustomHeaders (ResponseInterface $ response )
328+ protected function _withCustomHeaders (ResponseInterface $ response ): ResponseInterface
319329 {
320330 foreach ((array )$ this ->getConfig ('headers ' ) as $ key => $ value ) {
321331 $ response = $ response ->withHeader ($ key , $ value );
@@ -332,7 +342,7 @@ protected function _withCustomHeaders(ResponseInterface $response)
332342 * @throws \ADmad\Glide\Exception\ResponseException
333343 * @return \Psr\Http\Message\ResponseInterface|null
334344 */
335- protected function _handleException (ServerRequestInterface $ request , $ exception ): ?ResponseInterface
345+ protected function _handleException (ServerRequestInterface $ request , Exception $ exception ): ?ResponseInterface
336346 {
337347 $ event = $ this ->dispatchEvent (
338348 static ::RESPONSE_FAILURE_EVENT ,
0 commit comments