From cfac711454bb05b96069caff98093ab8c9b36f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Tue, 9 Oct 2018 11:56:03 +0200 Subject: [PATCH 1/2] adds a default value for the assets URI prefix --- src/AssetsMiddleware.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AssetsMiddleware.php b/src/AssetsMiddleware.php index 1d61d0f..31d0b78 100644 --- a/src/AssetsMiddleware.php +++ b/src/AssetsMiddleware.php @@ -30,7 +30,6 @@ use CodeInc\AssetsMiddleware\Responses\AssetMinifiedResponse; use CodeInc\AssetsMiddleware\Responses\NotModifiedAssetResponse; use Micheh\Cache\CacheUtil; -use function PHPSTORM_META\elementType; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -88,7 +87,7 @@ class AssetsMiddleware implements MiddlewareInterface * @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, string $assetsUriPrefix = '/', bool $cacheAssets = true, bool $minifyAssets = false) { $this->resolver = $resolver; From 1766cf46675c8acb3f1a45b0a6fd0a35bf95fee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Tue, 9 Oct 2018 11:56:11 +0200 Subject: [PATCH 2/2] updated examples --- README.md | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 09975eb..3e1cfc2 100644 --- a/README.md +++ b/README.md @@ -7,24 +7,43 @@ This PHP 7.1 library is a [PSR-15](https://www.php-fig.org/psr/psr-15/) middlewa ```php addAssetsDirectory('/path/to/my/first/web-assets-directory'); -$assetsMiddleware->addAssetsDirectory('/path/to/another/web-assets-directory'); - + new AssetsDirectoryResolver( + '/path/to/my/assets/assets/', // <-- directory path + '/assets/' // <-- assets URI prefix + ) +); // optionally you can limit the acceptable media types $assetsMiddleware->setAllowMediaTypes([ - 'image/*', + 'image/*', // supports shell patterns through fnmatch() 'text/css', 'application/javascript' ]); -// returns the computed path to the assets directory -$assetsMiddleware->getAssetUri('/path/to/another/web-assets-directory/an-image.jpg'); +// processed a PSR-7 server request as a PSR-15 middleware +$assetsMiddleware->process($aPsr7ServerRequest, $aPsr15RequestHandler); // <-- returns a PSR-7 response +``` + +### Using multiple resolver + +```php + '/local/favicon/file.ico']), + new AssetsDirectoryResolver( + '/path/to/my/assets/assets/', // <-- directory path + '/assets/' // <-- assets URI prefix + ) + ]) +); // processed a PSR-7 server request as a PSR-15 middleware $assetsMiddleware->process($aPsr7ServerRequest, $aPsr15RequestHandler); // <-- returns a PSR-7 response