1. Go to this page and download the library: Download codeinc/assets-middleware library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codeinc / assets-middleware example snippets
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
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.