diff --git a/composer.json b/composer.json index c18a221..1d27a32 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "codeinc/assets-middleware", - "version": "2.1.0", + "version": "2.1.1", "description": "A PSR-15 middleware to server static assets (CSS, JS, images, etc.)", "homepage": "https://github.com/CodeIncHQ/AssetsMiddleware", "type": "library", diff --git a/src/AssetsMiddleware.php b/src/AssetsMiddleware.php index 31d0b78..7ca5b13 100644 --- a/src/AssetsMiddleware.php +++ b/src/AssetsMiddleware.php @@ -51,13 +51,6 @@ class AssetsMiddleware implements MiddlewareInterface */ private $resolver; - /** - * Base assets URI path. - * - * @var string - */ - private $assetsUriPrefix; - /** * Allows the assets to the cached in the web browser. * @@ -83,15 +76,13 @@ class AssetsMiddleware implements MiddlewareInterface * AssetsMiddleware constructor. * * @param AssetResolverInterface $resolver - * @param string $assetsUriPrefix Base assets URI path * @param bool $cacheAssets Allows the assets to the cached in the web browser * @param bool $minifyAssets Minimizes the assets before sending them (@see AssetCompressedResponse) */ - public function __construct(AssetResolverInterface $resolver, string $assetsUriPrefix = '/', + public function __construct(AssetResolverInterface $resolver, bool $cacheAssets = true, bool $minifyAssets = false) { $this->resolver = $resolver; - $this->assetsUriPrefix = $assetsUriPrefix; $this->cacheAssets = $cacheAssets; $this->minifyAssets = $minifyAssets; } @@ -125,9 +116,7 @@ public function getAllowedMediaTypes():?array */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler):ResponseInterface { - $reqUriPath = $request->getUri()->getPath(); - if (preg_match('/^'.preg_quote($this->assetsUriPrefix, '/').'.+$/ui', $reqUriPath) - && ($asset = $this->resolver->getAsset($reqUriPath)) !== null) + if (($asset = $this->resolver->getAsset($request->getUri()->getPath())) !== null) { try { // checking the asset's media type @@ -157,7 +146,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface throw new ResponseErrorException($asset, 0, $exception); } } - return $handler->handle($request); }