Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #21 from CodeIncHQ/2.x
Browse files Browse the repository at this point in the history
v2.1.1
  • Loading branch information
Joan Fabrégat authored Oct 11, 2018
2 parents 198797e + e1f96d1 commit 6e63b26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 2 additions & 14 deletions src/AssetsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -157,7 +146,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
throw new ResponseErrorException($asset, 0, $exception);
}
}

return $handler->handle($request);
}

Expand Down

0 comments on commit 6e63b26

Please sign in to comment.