PHP code example of kaspi / psr7-wizard
1. Go to this page and download the library: Download kaspi/psr7-wizard 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/ */
kaspi / psr7-wizard example snippets
// Example build ServerRequest class with package kaspi/http-message
$httpFactory = new \Kaspi\HttpMessage\HttpFactory();
$wizard = new \Kaspi\Psr7Wizard\ServerRequestWizard(
serverRequestFactory: $httpFactory,
streamFactory: $httpFactory,
uploadedFileFactory: $httpFactory,
uriFactory: $httpFactory,
);
/** @var \Psr\Http\Message\ServerRequestInterface $serverRequest */
$serverRequest = $wizard->fromGlobals();
// ✋🏻 Or create by params 👇🏻
$serverEnv = [
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '35096',
'SERVER_SOFTWARE' => 'PHP 8.2.14 Development Server',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_NAME' => '127.0.0.1',
'SERVER_PORT' => '8080',
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'POST',
'SCRIPT_NAME' => '/index.php',
'CONTENT_LENGTH' => '53',
'HTTP_CONTENT_LENGTH' => '53'
];
$queryStringParams = [
'search' => 'php%',
];
$cookie = [
'save' => 'no'
];
$uploadedFiles = [
$httpFactory->createUploadedFile('/tmp/file1');
];
$parsedBody = [
'form' => [
'name' => 'Joe',
'contact' => '+555-36-89'
],
];
$body = 'form%5Bname%5D=Joe&form%5Bcontact%5D=%2B555-36-89';
$wizard->fromParams(
serverParams: $serverEnv,
queryParams: $queryStringParams,
cookieParams: $cookie,
files: $uploadedFiles,
parsedBody: $parsedBody,
body: $body
);
shell
docker-compose run --rm php composer install
shell
docker-compose run --rm php vendor/bin/pest --compact
shell
docker-compose run --rm php vendor/bin/phan
shell
docker-compose run --rm php sh