Giter Site home page Giter Site logo

agdobrynin / psr7-wizard Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 50 KB

Building ServerRequest class which implement PSR-7 ServerRequestInterface from global PHP variables.

License: MIT License

PHP 98.47% Dockerfile 0.91% Makefile 0.62%
php-library psr-17 psr-7

psr7-wizard's Introduction

๐Ÿง™๐Ÿปโ€โ™‚๏ธ psr7-wizard

Building ServerRequest class which implement PSR-7 ServerRequestInterface from global PHP variables.

Require PHP 8.1 or newest.

additional links: PSR-7, PSR-17

Installation

composer kaspi/psr7-wizard

Usage

// 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 
);

Development environment

Local development

Required PHP 8.1, php Composer 2.x

Testing

Run test without code coverage

composer test

Running tests with checking code coverage by tests with a report in html format

./vendor/bin/pest

Requires installed PCOV driver

โ›‘ the results will be in the folder .coverage-html

Static code analysis

For static analysis we use the package Phan.

Running without PHP extension PHP AST

./vendor/bin/phan --allow-polyfill-parser

Code style

To bring the code to standards, we use php-cs-fixer which is declared in composer's dev dependencies.

composer fixer

Using Docker image with PHP 8.1, 8.2, 8.3

You can specify the image with the PHP version in the .env file in the PHP_IMAGE key. By default, the container is built with the php:8.1-cli-alpine image.

Build docker container

docker-compose build

Install php composer dependencies:

docker-compose run --rm php composer install

Run tests with a code coverage report and a report in html format

docker-compose run --rm php vendor/bin/pest --compact

โ›‘ the results will be in the folder .coverage-html

Phan (static analyzer for PHP)

docker-compose run --rm php vendor/bin/phan

You can work in a shell into a docker container:

docker-compose run --rm php sh
Using Makefile commands.

Check and correct code style:

make fix

Run the static code analyzer:

make stat

Run tests:

make test

Run all stages of checks:

make all

psr7-wizard's People

Contributors

agdobrynin avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.