PHP Class Psr7Middlewares\Middleware\ImageTransformer

Inheritance: use trait Psr7Middlewares\Utils\BasePathTrait, use trait Psr7Middlewares\Utils\CryptTrait
Show file Open project: oscarotero/psr7-middlewares

Public Methods

Method Description
__construct ( array $sizes ) Define the available sizes, for example: [ 'small' => 'resizeCrop,50,50', 'medium' => 'resize,500', 'big' => 'resize,1000', ].
__invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface Execute the middleware.
cache ( Psr\Cache\CacheItemPoolInterface $cache ) : self To save the transformed images in the cache.
clientHints ( array $clientHints = ['Dpr', 'Viewport-Width', 'Width'] ) : self Enable the client hints.
getGenerator ( Psr\Http\Message\ServerRequestInterface $request ) : callable | null Returns a callable to generate urls.

Private Methods

Method Description
getCacheKey ( Psr\Http\Message\ServerRequestInterface $request ) : string Generates the key used to save the image in cache.
getClientHints ( Psr\Http\Message\ServerRequestInterface $request ) : array | null Returns the client hints sent.
parsePath ( string $path ) : false | array Parses the path and return the file and transform values.
transform ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, string $transform ) : Psr\Http\Message\ResponseInterface Transform the image.

Method Details

__construct() public method

Define the available sizes, for example: [ 'small' => 'resizeCrop,50,50', 'medium' => 'resize,500', 'big' => 'resize,1000', ].
public __construct ( array $sizes )
$sizes array

__invoke() public method

Execute the middleware.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface

cache() public method

To save the transformed images in the cache.
public cache ( Psr\Cache\CacheItemPoolInterface $cache ) : self
$cache Psr\Cache\CacheItemPoolInterface
return self

clientHints() public method

Enable the client hints.
public clientHints ( array $clientHints = ['Dpr', 'Viewport-Width', 'Width'] ) : self
$clientHints array
return self

getGenerator() public static method

Returns a callable to generate urls.
public static getGenerator ( Psr\Http\Message\ServerRequestInterface $request ) : callable | null
$request Psr\Http\Message\ServerRequestInterface
return callable | null