PHP code example of loophp / psr-http-message-bridge-bundle
1. Go to this page and download the library: Download loophp/psr-http-message-bridge-bundle 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/ */
loophp / psr-http-message-bridge-bundle example snippets
declare(strict_types=1);
namespace App\Controller;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
final class HelloWorldController {
private ResponseFactoryInterface $responseFactory;
private StreamFactoryInterface $streamFactory;
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
{
$this->responseFactory = $responseFactory;
$this->streamFactory = $streamFactory;
}
/**
* @Route("/hello-world", name="hello_world")
*/
public function __invoke(RequestInterface $psrRequest): ResponseInterface {
// You can do something with $psrRequest if needed.
// Build the PSR response.
$response = $this->responseFactory->createResponse();
// Return the new PSR response.
return $response->withBody($this->streamFactory->createStream('Hello world!'));
}
}