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

Commit

Permalink
adds usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Fabrégat committed Oct 4, 2018
1 parent 50d277e commit 5e8b25e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

This PHP 7.1 library is a [PSR-15](https://www.php-fig.org/psr/psr-15/) middleware dedicated to manage static assets like CSS, JS, or image files.

## Usage

```php
<?php
use CodeInc\AssetsMiddleware\AssetsMiddleware;

$assetsMiddleware = new AssetsMiddleware(
'/assets/' // <-- specifies the assets base URI path
);

// adding web assets directories
$assetsMiddleware->addAssetsDirectory('/path/to/my/first/web-assets-directory');
$assetsMiddleware->addAssetsDirectory('/path/to/another/web-assets-directory');

// optionally you can limit the acceptable media types
$assetsMiddleware->setAllowMediaTypes([
'image/*',
'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
```

## Installation

This library is available through [Packagist](https://packagist.org/packages/codeinc/assets-middleware) and can be installed using [Composer](https://getcomposer.org/):
Expand Down

0 comments on commit 5e8b25e

Please sign in to comment.