Skip to content

Commit

Permalink
Merge pull request #2 from agdobrynin/development
Browse files Browse the repository at this point in the history
Feat/server request interface from globals (#1)
  • Loading branch information
agdobrynin authored Jan 30, 2024
2 parents 1eb454c + 184e5d6 commit 3ff8c01
Show file tree
Hide file tree
Showing 18 changed files with 1,191 additions and 34 deletions.
6 changes: 4 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
->setRules([
'@PhpCsFixer' => true,
'declare_strict_types' => true,
'php_unit_test_class_requires_covers' => false,
'native_function_invocation' => [
'include' => ['@all'],
'scope' => 'all',
Expand All @@ -20,7 +19,10 @@
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
]
],
'yoda_style' => [
'always_move_variable' => true,
],
])
->setRiskyAllowed(true)
->setFinder($finder)
Expand Down
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
# 🧙🏻‍♂️ Build PSR-7 ServerRequestInterface from global PHP variables.

`kaspi/psr7-globals` help build PSR7 ServerRequestInterface compatible class.
# 🧙🏻‍♂️ Building ServerRequest class which implement PSR-7 ServerRequestInterface from global PHP variables.

Require PHP 8.1 or newest.

additional links:
- [PSR-7](https://www.php-fig.org/psr/psr-7)
- [PSR-17](https://www.php-fig.org/psr/psr-17)

## Installation

```shell
composer kaspi/psr7-globals
composer kaspi/psr7-wizard
```

## Usage

```php
// 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
$uploadedFiles = [
$httpFactory->createUploadedFile('/tmp/file1');
];

$wizard->fromParams(
serverParams: $serverEnv,
queryParams: $queryStringParams,
cookieParams: $cookie,
files: $uploadedFiles,
parsedBody: $parsedBody,
body: 'raw content'
);
```

## Development environment
Expand All @@ -29,7 +60,7 @@ composer test
```
Running tests with checking code coverage by tests with a report in html format
```shell
./vendor/bin/pest --compact
./vendor/bin/pest
```
Requires installed [PCOV](https://github.com/krakjoe/pcov) driver

Expand Down Expand Up @@ -78,7 +109,7 @@ Phan (_static analyzer for PHP_)
docker-compose run --rm php vendor/bin/phan
```

You can work in a shell in a docker container:
You can work in a shell into a docker container:
```shell
docker-compose run --rm php sh
```
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kaspi/psr7-globals",
"description": "Creating PSR-7 ServerRequest from global variables",
"name": "kaspi/psr7-wizard",
"description": "Make PSR-7 ServerRequest from global variables",
"keywords": ["http-message", "psr-7", "psr-17"],
"type": "library",
"require": {
Expand All @@ -11,12 +11,12 @@
"license": "MIT",
"autoload": {
"psr-4": {
"Kaspi\\Psr7Globals\\": "src"
"Kaspi\\Psr7Wizard\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Kaspi\\Psr7Globals\\": "tests/"
"Tests\\Kaspi\\Psr7Wizard\\": "tests/"
}
},
"authors": [
Expand Down
29 changes: 14 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ff8c01

Please sign in to comment.