Skip to content

Commit 3ff8c01

Browse files
authored
Merge pull request #2 from agdobrynin/development
Feat/server request interface from globals (#1)
2 parents 1eb454c + 184e5d6 commit 3ff8c01

18 files changed

+1191
-34
lines changed

.php-cs-fixer.dist.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
->setRules([
1212
'@PhpCsFixer' => true,
1313
'declare_strict_types' => true,
14-
'php_unit_test_class_requires_covers' => false,
1514
'native_function_invocation' => [
1615
'include' => ['@all'],
1716
'scope' => 'all',
@@ -20,7 +19,10 @@
2019
'import_classes' => true,
2120
'import_constants' => true,
2221
'import_functions' => true,
23-
]
22+
],
23+
'yoda_style' => [
24+
'always_move_variable' => true,
25+
],
2426
])
2527
->setRiskyAllowed(true)
2628
->setFinder($finder)

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
# 🧙🏻‍♂️ Build PSR-7 ServerRequestInterface from global PHP variables.
2-
3-
`kaspi/psr7-globals` help build PSR7 ServerRequestInterface compatible class.
1+
# 🧙🏻‍♂️ Building ServerRequest class which implement PSR-7 ServerRequestInterface from global PHP variables.
42

53
Require PHP 8.1 or newest.
64

5+
additional links:
76
- [PSR-7](https://www.php-fig.org/psr/psr-7)
87
- [PSR-17](https://www.php-fig.org/psr/psr-17)
98

109
## Installation
1110

1211
```shell
13-
composer kaspi/psr7-globals
12+
composer kaspi/psr7-wizard
13+
```
14+
15+
## Usage
16+
17+
```php
18+
// Example build ServerRequest class with package kaspi/http-message
19+
20+
$httpFactory = new \Kaspi\HttpMessage\HttpFactory();
21+
22+
$wizard = new \Kaspi\Psr7Wizard\ServerRequestWizard(
23+
serverRequestFactory: $httpFactory,
24+
streamFactory: $httpFactory,
25+
uploadedFileFactory: $httpFactory,
26+
uriFactory: $httpFactory,
27+
);
28+
29+
/** @var \Psr\Http\Message\ServerRequestInterface $serverRequest */
30+
$serverRequest = $wizard->fromGlobals();
31+
32+
//👆🏻 Or create by params
33+
$uploadedFiles = [
34+
$httpFactory->createUploadedFile('/tmp/file1');
35+
];
36+
37+
$wizard->fromParams(
38+
serverParams: $serverEnv,
39+
queryParams: $queryStringParams,
40+
cookieParams: $cookie,
41+
files: $uploadedFiles,
42+
parsedBody: $parsedBody,
43+
body: 'raw content'
44+
);
1445
```
1546

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

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

81-
You can work in a shell in a docker container:
112+
You can work in a shell into a docker container:
82113
```shell
83114
docker-compose run --rm php sh
84115
```

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "kaspi/psr7-globals",
3-
"description": "Creating PSR-7 ServerRequest from global variables",
2+
"name": "kaspi/psr7-wizard",
3+
"description": "Make PSR-7 ServerRequest from global variables",
44
"keywords": ["http-message", "psr-7", "psr-17"],
55
"type": "library",
66
"require": {
@@ -11,12 +11,12 @@
1111
"license": "MIT",
1212
"autoload": {
1313
"psr-4": {
14-
"Kaspi\\Psr7Globals\\": "src"
14+
"Kaspi\\Psr7Wizard\\": "src"
1515
}
1616
},
1717
"autoload-dev": {
1818
"psr-4": {
19-
"Tests\\Kaspi\\Psr7Globals\\": "tests/"
19+
"Tests\\Kaspi\\Psr7Wizard\\": "tests/"
2020
}
2121
},
2222
"authors": [

composer.lock

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)