codeinc / assets-middleware
This package is abandoned and no longer maintained.
No replacement package was suggested.
A PSR-15 middleware to server static assets (CSS, JS, images, etc.)
2.1.1
2018-10-11 17:16 UTC
Requires
- php: >=7.1
- ext-gettext: *
- codeinc/collection-interface: ^1.1
- codeinc/media-types: ^1.0
- codeinc/psr7-responses: ^2
- enshrined/svg-sanitize: ^0.8.2
- matthiasmullie/minify: ^1.3
- micheh/psr7-cache: ^0.5.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
Suggests
- codeinc/middleware-dispatcher: A PSR-15 middleware dispatcher
- codeinc/psr7-response-sender: A PSR-7 response sender
README
This PHP 7.1 library is a PSR-15 middleware dedicated to manage static assets like CSS, JS, or image files.
Usage
<?php use CodeInc\AssetsMiddleware\AssetsMiddleware; use CodeInc\AssetsMiddleware\Resolvers\AssetsDirectoryResolver; $assetsMiddleware = new AssetsMiddleware( new AssetsDirectoryResolver( '/path/to/my/assets/assets/', // <-- directory path '/assets/' // <-- assets URI prefix ) ); // optionally you can limit the acceptable media types $assetsMiddleware->setAllowMediaTypes([ 'image/*', // supports shell patterns through fnmatch() 'text/css', 'application/javascript' ]); // processed a PSR-7 server request as a PSR-15 middleware $assetsMiddleware->process($aPsr7ServerRequest, $aPsr15RequestHandler); // <-- returns a PSR-7 response
Using multiple resolvers
<?php use CodeInc\AssetsMiddleware\AssetsMiddleware; use CodeInc\AssetsMiddleware\Resolvers\AssetsDirectoryResolver; use CodeInc\AssetsMiddleware\Resolvers\StaticAssetsResolver; use CodeInc\AssetsMiddleware\Resolvers\AssetResolverAggregator; $assetsMiddleware = new AssetsMiddleware( new AssetResolverAggregator([ new StaticAssetsResolver(['/favicon.ico' => '/local/favicon/file.ico']), new AssetsDirectoryResolver('/path/to/my/css/', '/css/'), new AssetsDirectoryResolver('/path/to/my/images/', '/images/') ]) ); // processed a PSR-7 server request as a PSR-15 middleware $assetsMiddleware->process($aPsr7ServerRequest, $aPsr15RequestHandler); // <-- returns a PSR-7 response
Installation
This library is available through Packagist and can be installed using Composer:
composer require codeinc/assets-middleware
License
The library is published under the MIT license (see LICENSE
file).