1. Go to this page and download the library: Download pew-pew/http-factory 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/ */
pew-pew / http-factory example snippets
// Symfony Request
$request = new \Symfony\Component\HttpFoundation\Request();
// Requests Factory
$requests = new \PewPew\HttpFactory\RequestDecoderFactory([
new \PewPew\HttpFactory\Driver\JsonDriver(),
]);
$payload = $requests
->createDecoder($request) // Detect passed "content-type" header and
// create decoder if available.
?->decode($request->getContent(true)); // Decode request body.
// Symfony Request
$request = new \Symfony\Component\HttpFoundation\Request();
// Responses Factory
$responses = new \PewPew\HttpFactory\ResponseEncoderFactory([
new \PewPew\HttpFactory\Driver\JsonDriver(),
]);
$response = $responses
->createEncoder($request) // Detect passed "accept" header and create
// encoder if available.
?->encode(['some' => 'any'], 200); // Encode payload and create response.
use PewPew\HttpFactory\ResponseEncoderFactoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
final readonly class ExampleController
{
public function __construct(
private ResponseEncoderFactoryInterface $responses,
) {}
public function someAction(Request $request): Response
{
$encoder = $this->responses->createEncoder($request);
if ($encoder === null) {
throw new \Symfony\Component\HttpFoundation\Exception\BadRequestException(
'Unsupported "accept" request header',
);
}
return $encoder->encode([
'status' => 'ok'
], Response::HTTP_OK);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.