1. Go to this page and download the library: Download bermudaphp/psr15factory 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/ */
bermudaphp / psr15factory example snippets
$factory = new MiddlewareFactory($containerInterface, $responseFactoryInterface);
class MyMiddleware implements MiddlewareInterface
{
private ResponseFactoryInterface $factory;
public function __construct(ResponseFactoryInterface $factory)
{
$this->factory = $factory;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return $this->factory->createResponse(200, 'OK!');
}
}
$middleware = $factory->make(MyMiddleware::class);
$middleware instanceof MyMiddleware::class // true
class MyHandler implements RequestHandlerInterface
{
private ResponseFactoryInterface $factory;
public function __construct(ResponseFactoryInterface $factory)
{
$this->factory = $factory;
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->factory->createResponse(200, 'OK!');
}
}
$middleware = $factory->make(MyHandler::class);
$middleware instanceof MiddlewareInterface::class // true