Maurits van der Schee 5 years ago
parent
commit
8460d99091
32 changed files with 140 additions and 3353 deletions
  1. 3
    0
      .gitignore
  2. 90
    94
      api.php
  3. 40
    17
      build.php
  4. 7
    1
      composer.json
  5. 0
    21
      src/Nyholm/LICENSE
  6. 0
    68
      src/Nyholm/Psr7/Factory/Psr17Factory.php
  7. 0
    202
      src/Nyholm/Psr7/MessageTrait.php
  8. 0
    45
      src/Nyholm/Psr7/Request.php
  9. 0
    113
      src/Nyholm/Psr7/RequestTrait.php
  10. 0
    88
      src/Nyholm/Psr7/Response.php
  11. 0
    162
      src/Nyholm/Psr7/ServerRequest.php
  12. 0
    257
      src/Nyholm/Psr7/Stream.php
  13. 0
    171
      src/Nyholm/Psr7/UploadedFile.php
  14. 0
    310
      src/Nyholm/Psr7/Uri.php
  15. 0
    275
      src/Nyholm/Psr7Server/ServerRequestCreator.php
  16. 0
    58
      src/Nyholm/Psr7Server/ServerRequestCreatorInterface.php
  17. 0
    187
      src/Psr/Http/Message/MessageInterface.php
  18. 0
    18
      src/Psr/Http/Message/RequestFactoryInterface.php
  19. 0
    129
      src/Psr/Http/Message/RequestInterface.php
  20. 0
    18
      src/Psr/Http/Message/ResponseFactoryInterface.php
  21. 0
    68
      src/Psr/Http/Message/ResponseInterface.php
  22. 0
    24
      src/Psr/Http/Message/ServerRequestFactoryInterface.php
  23. 0
    261
      src/Psr/Http/Message/ServerRequestInterface.php
  24. 0
    43
      src/Psr/Http/Message/StreamFactoryInterface.php
  25. 0
    158
      src/Psr/Http/Message/StreamInterface.php
  26. 0
    34
      src/Psr/Http/Message/UploadedFileFactoryInterface.php
  27. 0
    123
      src/Psr/Http/Message/UploadedFileInterface.php
  28. 0
    17
      src/Psr/Http/Message/UriFactoryInterface.php
  29. 0
    323
      src/Psr/Http/Message/UriInterface.php
  30. 0
    25
      src/Psr/Http/Server/MiddlewareInterface.php
  31. 0
    22
      src/Psr/Http/Server/RequestHandlerInterface.php
  32. 0
    21
      src/Psr/LICENSE

+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@
1
+vendor/
2
+composer.phar
3
+composer.lock

+ 90
- 94
api.php View File

@@ -7,7 +7,65 @@
7 7
 
8 8
 namespace Tqdev\PhpCrudApi;
9 9
 
10
-// file: src/Psr/Http/Message/MessageInterface.php
10
+// file: vendor/psr/http-factory/src/RequestFactoryInterface.php
11
+
12
+interface RequestFactoryInterface
13
+{
14
+    
15
+    public function createRequest(string $method, $uri): RequestInterface;
16
+}
17
+
18
+// file: vendor/psr/http-factory/src/ResponseFactoryInterface.php
19
+
20
+interface ResponseFactoryInterface
21
+{
22
+    
23
+    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface;
24
+}
25
+
26
+// file: vendor/psr/http-factory/src/ServerRequestFactoryInterface.php
27
+
28
+interface ServerRequestFactoryInterface
29
+{
30
+    
31
+    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface;
32
+}
33
+
34
+// file: vendor/psr/http-factory/src/StreamFactoryInterface.php
35
+
36
+interface StreamFactoryInterface
37
+{
38
+    
39
+    public function createStream(string $content = ''): StreamInterface;
40
+
41
+    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface;
42
+
43
+    public function createStreamFromResource($resource): StreamInterface;
44
+}
45
+
46
+// file: vendor/psr/http-factory/src/UploadedFileFactoryInterface.php
47
+
48
+interface UploadedFileFactoryInterface
49
+{
50
+    
51
+    public function createUploadedFile(
52
+        StreamInterface $stream,
53
+        int $size = null,
54
+        int $error = \UPLOAD_ERR_OK,
55
+        string $clientFilename = null,
56
+        string $clientMediaType = null
57
+    ): UploadedFileInterface;
58
+}
59
+
60
+// file: vendor/psr/http-factory/src/UriFactoryInterface.php
61
+
62
+interface UriFactoryInterface
63
+{
64
+    
65
+    public function createUri(string $uri = ''): UriInterface;
66
+}
67
+
68
+// file: vendor/psr/http-message/src/MessageInterface.php
11 69
 
12 70
 interface MessageInterface
13 71
 {
@@ -35,15 +93,7 @@ interface MessageInterface
35 93
     public function withBody(StreamInterface $body);
36 94
 }
37 95
 
38
-// file: src/Psr/Http/Message/RequestFactoryInterface.php
39
-
40
-interface RequestFactoryInterface
41
-{
42
-    
43
-    public function createRequest(string $method, $uri): RequestInterface;
44
-}
45
-
46
-// file: src/Psr/Http/Message/RequestInterface.php
96
+// file: vendor/psr/http-message/src/RequestInterface.php
47 97
 
48 98
 interface RequestInterface extends MessageInterface
49 99
 {
@@ -61,15 +111,7 @@ interface RequestInterface extends MessageInterface
61 111
     public function withUri(UriInterface $uri, $preserveHost = false);
62 112
 }
63 113
 
64
-// file: src/Psr/Http/Message/ResponseFactoryInterface.php
65
-
66
-interface ResponseFactoryInterface
67
-{
68
-    
69
-    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface;
70
-}
71
-
72
-// file: src/Psr/Http/Message/ResponseInterface.php
114
+// file: vendor/psr/http-message/src/ResponseInterface.php
73 115
 
74 116
 interface ResponseInterface extends MessageInterface
75 117
 {
@@ -81,15 +123,7 @@ interface ResponseInterface extends MessageInterface
81 123
     public function getReasonPhrase();
82 124
 }
83 125
 
84
-// file: src/Psr/Http/Message/ServerRequestFactoryInterface.php
85
-
86
-interface ServerRequestFactoryInterface
87
-{
88
-    
89
-    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface;
90
-}
91
-
92
-// file: src/Psr/Http/Message/ServerRequestInterface.php
126
+// file: vendor/psr/http-message/src/ServerRequestInterface.php
93 127
 
94 128
 interface ServerRequestInterface extends RequestInterface
95 129
 {
@@ -121,19 +155,7 @@ interface ServerRequestInterface extends RequestInterface
121 155
     public function withoutAttribute($name);
122 156
 }
123 157
 
124
-// file: src/Psr/Http/Message/StreamFactoryInterface.php
125
-
126
-interface StreamFactoryInterface
127
-{
128
-    
129
-    public function createStream(string $content = ''): StreamInterface;
130
-
131
-    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface;
132
-
133
-    public function createStreamFromResource($resource): StreamInterface;
134
-}
135
-
136
-// file: src/Psr/Http/Message/StreamInterface.php
158
+// file: vendor/psr/http-message/src/StreamInterface.php
137 159
 
138 160
 interface StreamInterface
139 161
 {
@@ -169,21 +191,7 @@ interface StreamInterface
169 191
     public function getMetadata($key = null);
170 192
 }
171 193
 
172
-// file: src/Psr/Http/Message/UploadedFileFactoryInterface.php
173
-
174
-interface UploadedFileFactoryInterface
175
-{
176
-    
177
-    public function createUploadedFile(
178
-        StreamInterface $stream,
179
-        int $size = null,
180
-        int $error = \UPLOAD_ERR_OK,
181
-        string $clientFilename = null,
182
-        string $clientMediaType = null
183
-    ): UploadedFileInterface;
184
-}
185
-
186
-// file: src/Psr/Http/Message/UploadedFileInterface.php
194
+// file: vendor/psr/http-message/src/UploadedFileInterface.php
187 195
 
188 196
 interface UploadedFileInterface
189 197
 {
@@ -201,15 +209,7 @@ interface UploadedFileInterface
201 209
     public function getClientMediaType();
202 210
 }
203 211
 
204
-// file: src/Psr/Http/Message/UriFactoryInterface.php
205
-
206
-interface UriFactoryInterface
207
-{
208
-    
209
-    public function createUri(string $uri = ''): UriInterface;
210
-}
211
-
212
-// file: src/Psr/Http/Message/UriInterface.php
212
+// file: vendor/psr/http-message/src/UriInterface.php
213 213
 
214 214
 interface UriInterface
215 215
 {
@@ -247,23 +247,23 @@ interface UriInterface
247 247
     public function __toString();
248 248
 }
249 249
 
250
-// file: src/Psr/Http/Server/MiddlewareInterface.php
250
+// file: vendor/psr/http-server-handler/src/RequestHandlerInterface.php
251 251
 
252
-interface MiddlewareInterface
252
+interface RequestHandlerInterface
253 253
 {
254 254
     
255
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
255
+    public function handle(ServerRequestInterface $request): ResponseInterface;
256 256
 }
257 257
 
258
-// file: src/Psr/Http/Server/RequestHandlerInterface.php
258
+// file: vendor/psr/http-server-middleware/src/MiddlewareInterface.php
259 259
 
260
-interface RequestHandlerInterface
260
+interface MiddlewareInterface
261 261
 {
262 262
     
263
-    public function handle(ServerRequestInterface $request): ResponseInterface;
263
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
264 264
 }
265 265
 
266
-// file: src/Nyholm/Psr7/Factory/Psr17Factory.php
266
+// file: vendor/nyholm/psr7/src/Factory/Psr17Factory.php
267 267
 
268 268
 final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
269 269
 {
@@ -321,7 +321,7 @@ final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInte
321 321
     }
322 322
 }
323 323
 
324
-// file: src/Nyholm/Psr7/MessageTrait.php
324
+// file: vendor/nyholm/psr7/src/MessageTrait.php
325 325
 
326 326
 trait MessageTrait
327 327
 {
@@ -486,7 +486,7 @@ trait MessageTrait
486 486
     }
487 487
 }
488 488
 
489
-// file: src/Nyholm/Psr7/Request.php
489
+// file: vendor/nyholm/psr7/src/Request.php
490 490
 
491 491
 final class Request implements RequestInterface
492 492
 {
@@ -514,7 +514,7 @@ final class Request implements RequestInterface
514 514
     }
515 515
 }
516 516
 
517
-// file: src/Nyholm/Psr7/RequestTrait.php
517
+// file: vendor/nyholm/psr7/src/RequestTrait.php
518 518
 
519 519
 trait RequestTrait
520 520
 {
@@ -611,7 +611,7 @@ trait RequestTrait
611 611
     }
612 612
 }
613 613
 
614
-// file: src/Nyholm/Psr7/Response.php
614
+// file: vendor/nyholm/psr7/src/Response.php
615 615
 
616 616
 final class Response implements ResponseInterface
617 617
 {
@@ -678,7 +678,7 @@ final class Response implements ResponseInterface
678 678
     }
679 679
 }
680 680
 
681
-// file: src/Nyholm/Psr7/ServerRequest.php
681
+// file: vendor/nyholm/psr7/src/ServerRequest.php
682 682
 
683 683
 final class ServerRequest implements ServerRequestInterface
684 684
 {
@@ -815,7 +815,7 @@ final class ServerRequest implements ServerRequestInterface
815 815
     }
816 816
 }
817 817
 
818
-// file: src/Nyholm/Psr7/Stream.php
818
+// file: vendor/nyholm/psr7/src/Stream.php
819 819
 
820 820
 final class Stream implements StreamInterface
821 821
 {
@@ -1042,7 +1042,7 @@ final class Stream implements StreamInterface
1042 1042
     }
1043 1043
 }
1044 1044
 
1045
-// file: src/Nyholm/Psr7/UploadedFile.php
1045
+// file: vendor/nyholm/psr7/src/UploadedFile.php
1046 1046
 
1047 1047
 final class UploadedFile implements UploadedFileInterface
1048 1048
 {
@@ -1184,7 +1184,7 @@ final class UploadedFile implements UploadedFileInterface
1184 1184
     }
1185 1185
 }
1186 1186
 
1187
-// file: src/Nyholm/Psr7/Uri.php
1187
+// file: vendor/nyholm/psr7/src/Uri.php
1188 1188
 
1189 1189
 final class Uri implements UriInterface
1190 1190
 {
@@ -1463,7 +1463,7 @@ final class Uri implements UriInterface
1463 1463
     }
1464 1464
 }
1465 1465
 
1466
-// file: src/Nyholm/Psr7Server/ServerRequestCreator.php
1466
+// file: vendor/nyholm/psr7-server/src/ServerRequestCreator.php
1467 1467
 
1468 1468
 final class ServerRequestCreator implements ServerRequestCreatorInterface
1469 1469
 {
@@ -1496,7 +1496,7 @@ final class ServerRequestCreator implements ServerRequestCreatorInterface
1496 1496
 
1497 1497
         $headers = \function_exists('getallheaders') ? getallheaders() : static::getHeadersFromServer($_SERVER);
1498 1498
 
1499
-        return $this->fromArrays($server, $headers, $_COOKIE, $_GET, $_POST, $_FILES, \fopen('php://input', 'r') ?: null);
1499
+        return $this->fromArrays($server, $headers, $_COOKIE, $_GET, $_POST, $_FILES, fopen('php://input', 'r') ?: null);
1500 1500
     }
1501 1501
 
1502 1502
     public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], array $post = [], array $files = [], $body = null): ServerRequestInterface
@@ -1649,20 +1649,16 @@ final class ServerRequestCreator implements ServerRequestCreatorInterface
1649 1649
             $uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http');
1650 1650
         }
1651 1651
 
1652
-        if (isset($server['SERVER_PORT'])) {
1653
-            $uri = $uri->withPort($server['SERVER_PORT']);
1654
-        }
1655
-
1656 1652
         if (isset($server['HTTP_HOST'])) {
1657
-            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
1658
-                $uri = $uri->withHost($matches[1])->withPort($matches[2]);
1659
-            } else {
1660
-                $uri = $uri->withHost($server['HTTP_HOST']);
1661
-            }
1653
+            $uri = $uri->withHost($server['HTTP_HOST']);
1662 1654
         } elseif (isset($server['SERVER_NAME'])) {
1663 1655
             $uri = $uri->withHost($server['SERVER_NAME']);
1664 1656
         }
1665 1657
 
1658
+        if (isset($server['SERVER_PORT'])) {
1659
+            $uri = $uri->withPort($server['SERVER_PORT']);
1660
+        }
1661
+
1666 1662
         if (isset($server['REQUEST_URI'])) {
1667 1663
             $uri = $uri->withPath(\current(\explode('?', $server['REQUEST_URI'])));
1668 1664
         }
@@ -1675,7 +1671,7 @@ final class ServerRequestCreator implements ServerRequestCreatorInterface
1675 1671
     }
1676 1672
 }
1677 1673
 
1678
-// file: src/Nyholm/Psr7Server/ServerRequestCreatorInterface.php
1674
+// file: vendor/nyholm/psr7-server/src/ServerRequestCreatorInterface.php
1679 1675
 
1680 1676
 interface ServerRequestCreatorInterface
1681 1677
 {
@@ -3466,7 +3462,7 @@ class GenericDB
3466 3462
     private $columns;
3467 3463
     private $converter;
3468 3464
 
3469
-    private function getDsn(string $address, string $port, string $database): string
3465
+    private function getDsn(string $address, int $port, string $database): string
3470 3466
     {
3471 3467
         switch ($this->driver) {
3472 3468
             case 'mysql':return "$this->driver:host=$address;port=$port;dbname=$database;charset=utf8mb4";
@@ -3514,7 +3510,7 @@ class GenericDB
3514 3510
         }
3515 3511
     }
3516 3512
 
3517
-    public function __construct(string $driver, string $address, string $port, string $database, string $username, string $password)
3513
+    public function __construct(string $driver, string $address, int $port, string $database, string $username, string $password)
3518 3514
     {
3519 3515
         $this->driver = $driver;
3520 3516
         $this->database = $database;

+ 40
- 17
build.php View File

@@ -1,35 +1,42 @@
1 1
 <?php
2 2
 
3
-function prioritySort(string $dir, array $entries, array $priority): array
3
+function removeIgnored(string $dir, array &$entries, array $ignore)
4 4
 {
5
-    $result = array();
6
-    foreach ($priority as $file) {
7
-        if (dirname($file) == $dir) {
8
-            if (in_array(basename($file), $entries)) {
9
-                array_push($result, basename($file));
10
-            }
5
+    foreach ($entries as $i => $entry) {
6
+        if (isset($ignore[$dir . '/' . $entry])) {
7
+            unset($entries[$i]);
8
+        }
9
+    }
10
+}
11
+
12
+function prioritySort(string $dir, array &$entries, array $priority)
13
+{
14
+    $first = array();
15
+    foreach ($entries as $i => $entry) {
16
+        if (isset($priority[$dir . '/' . $entry])) {
17
+            array_push($first, $entry);
18
+            unset($entries[$i]);
11 19
         }
12 20
     }
13
-    $entries = array_diff($entries, $result);
14 21
     sort($entries);
15
-    foreach ($entries as $entry) {
16
-        array_push($result, $entry);
22
+    foreach ($first as $entry) {
23
+        array_unshift($entries, $entry);
17 24
     }
18
-    return $result;
19 25
 }
20 26
 
21
-function runDir(string $base, string $dir, array &$lines, array $priority): int
27
+function runDir(string $base, string $dir, array &$lines, array $ignore, array $priority): int
22 28
 {
23 29
     $count = 0;
24 30
     $entries = scandir($dir);
25
-    $entries = prioritySort($dir, $entries, $priority);
31
+    removeIgnored($dir, $entries, $ignore);
32
+    prioritySort($dir, $entries, $priority);
26 33
     foreach ($entries as $entry) {
27 34
         if ($entry === '.' || $entry === '..') {
28 35
             continue;
29 36
         }
30 37
         $filename = "$base/$dir/$entry";
31 38
         if (is_dir($filename)) {
32
-            $count += runDir($base, "$dir/$entry", $lines, $priority);
39
+            $count += runDir($base, "$dir/$entry", $lines, $ignore, $priority);
33 40
         }
34 41
     }
35 42
     foreach ($entries as $entry) {
@@ -70,12 +77,17 @@ EOF;
70 77
     }
71 78
 }
72 79
 
73
-function run(string $base, string $dir, string $filename, array $priority)
80
+function run(string $base, array $dirs, string $filename, array $ignore, array $priority)
74 81
 {
75 82
     $lines = [];
76 83
     $start = microtime(true);
77 84
     addHeader($lines);
78
-    $count = runDir($base, 'src', $lines, $priority);
85
+    $ignore = array_flip($ignore);
86
+    $priority = array_flip($priority);
87
+    $count = 0;
88
+    foreach ($dirs as $dir) {
89
+        $count += runDir($base, $dir, $lines, $ignore, $priority);
90
+    }
79 91
     $data = implode("\n", $lines);
80 92
     $data = preg_replace('/\n\s*\n\s*\n/', "\n\n", $data);
81 93
     file_put_contents('tmp_' . $filename, $data);
@@ -88,4 +100,15 @@ function run(string $base, string $dir, string $filename, array $priority)
88 100
     echo sprintf("%d files combined in %d ms into '%s'\n", $count, $time, $filename);
89 101
 }
90 102
 
91
-run(__DIR__, 'src', 'api.php', ['src/Psr']);
103
+$ignore = [
104
+    'vendor/autoload.php',
105
+    'vendor/composer',
106
+    'vendor/php-http',
107
+    'vendor/nyholm/psr7/src/Factory/HttplugFactory.php',
108
+];
109
+
110
+$priority = [
111
+    'vendor/psr',
112
+];
113
+
114
+run(__DIR__, ['vendor', 'src'], 'api.php', $ignore, $priority);

+ 7
- 1
composer.json View File

@@ -35,7 +35,13 @@
35 35
       "php": ">=7.0.0",
36 36
       "ext-zlib": "*",
37 37
       "ext-json": "*",
38
-      "ext-pdo": "*"
38
+      "ext-pdo": "*",
39
+      "psr/http-message": "*",
40
+      "psr/http-factory": "*",
41
+      "psr/http-server-handler": "*",
42
+      "psr/http-server-middleware": "*",
43
+      "nyholm/psr7": "*",
44
+      "nyholm/psr7-server": "*"
39 45
     },
40 46
     "suggest": {
41 47
       "ext-memcache": "*",

+ 0
- 21
src/Nyholm/LICENSE View File

@@ -1,21 +0,0 @@
1
-MIT License
2
-
3
-Copyright (c) 2018 Tobias Nyholm
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
-SOFTWARE.

+ 0
- 68
src/Nyholm/Psr7/Factory/Psr17Factory.php View File

@@ -1,68 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7\Factory;
6
-
7
-use Nyholm\Psr7\{Request, Response, ServerRequest, Stream, UploadedFile, Uri};
8
-use Psr\Http\Message\{RequestFactoryInterface, RequestInterface, ResponseFactoryInterface, ResponseInterface, ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, StreamInterface, UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface};
9
-
10
-/**
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- */
14
-final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
15
-{
16
-    public function createRequest(string $method, $uri): RequestInterface
17
-    {
18
-        return new Request($method, $uri);
19
-    }
20
-
21
-    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
22
-    {
23
-        return new Response($code, [], null, '1.1', $reasonPhrase);
24
-    }
25
-
26
-    public function createStream(string $content = ''): StreamInterface
27
-    {
28
-        return Stream::create($content);
29
-    }
30
-
31
-    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
32
-    {
33
-        $resource = @\fopen($filename, $mode);
34
-        if (false === $resource) {
35
-            if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'])) {
36
-                throw new \InvalidArgumentException('The mode ' . $mode . ' is invalid.');
37
-            }
38
-
39
-            throw new \RuntimeException('The file ' . $filename . ' cannot be opened.');
40
-        }
41
-
42
-        return Stream::create($resource);
43
-    }
44
-
45
-    public function createStreamFromResource($resource): StreamInterface
46
-    {
47
-        return Stream::create($resource);
48
-    }
49
-
50
-    public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface
51
-    {
52
-        if (null === $size) {
53
-            $size = $stream->getSize();
54
-        }
55
-
56
-        return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
57
-    }
58
-
59
-    public function createUri(string $uri = ''): UriInterface
60
-    {
61
-        return new Uri($uri);
62
-    }
63
-
64
-    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
65
-    {
66
-        return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
67
-    }
68
-}

+ 0
- 202
src/Nyholm/Psr7/MessageTrait.php View File

@@ -1,202 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\StreamInterface;
8
-
9
-/**
10
- * Trait implementing functionality common to requests and responses.
11
- *
12
- * @author Michael Dowling and contributors to guzzlehttp/psr7
13
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
14
- * @author Martijn van der Ven <martijn@vanderven.se>
15
- *
16
- * @internal should not be used outside of Nyholm/Psr7 as it does not fall under our BC promise
17
- */
18
-trait MessageTrait
19
-{
20
-    /** @var array Map of all registered headers, as original name => array of values */
21
-    private $headers = [];
22
-
23
-    /** @var array Map of lowercase header name => original name at registration */
24
-    private $headerNames = [];
25
-
26
-    /** @var string */
27
-    private $protocol = '1.1';
28
-
29
-    /** @var StreamInterface|null */
30
-    private $stream;
31
-
32
-    public function getProtocolVersion(): string
33
-    {
34
-        return $this->protocol;
35
-    }
36
-
37
-    public function withProtocolVersion($version): self
38
-    {
39
-        if ($this->protocol === $version) {
40
-            return $this;
41
-        }
42
-
43
-        $new = clone $this;
44
-        $new->protocol = $version;
45
-
46
-        return $new;
47
-    }
48
-
49
-    public function getHeaders(): array
50
-    {
51
-        return $this->headers;
52
-    }
53
-
54
-    public function hasHeader($header): bool
55
-    {
56
-        return isset($this->headerNames[\strtolower($header)]);
57
-    }
58
-
59
-    public function getHeader($header): array
60
-    {
61
-        $header = \strtolower($header);
62
-        if (!isset($this->headerNames[$header])) {
63
-            return [];
64
-        }
65
-
66
-        $header = $this->headerNames[$header];
67
-
68
-        return $this->headers[$header];
69
-    }
70
-
71
-    public function getHeaderLine($header): string
72
-    {
73
-        return \implode(', ', $this->getHeader($header));
74
-    }
75
-
76
-    public function withHeader($header, $value): self
77
-    {
78
-        $value = $this->validateAndTrimHeader($header, $value);
79
-        $normalized = \strtolower($header);
80
-
81
-        $new = clone $this;
82
-        if (isset($new->headerNames[$normalized])) {
83
-            unset($new->headers[$new->headerNames[$normalized]]);
84
-        }
85
-        $new->headerNames[$normalized] = $header;
86
-        $new->headers[$header] = $value;
87
-
88
-        return $new;
89
-    }
90
-
91
-    public function withAddedHeader($header, $value): self
92
-    {
93
-        if (!\is_string($header) || '' === $header) {
94
-            throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string.');
95
-        }
96
-
97
-        $new = clone $this;
98
-        $new->setHeaders([$header => $value]);
99
-
100
-        return $new;
101
-    }
102
-
103
-    public function withoutHeader($header): self
104
-    {
105
-        $normalized = \strtolower($header);
106
-        if (!isset($this->headerNames[$normalized])) {
107
-            return $this;
108
-        }
109
-
110
-        $header = $this->headerNames[$normalized];
111
-        $new = clone $this;
112
-        unset($new->headers[$header], $new->headerNames[$normalized]);
113
-
114
-        return $new;
115
-    }
116
-
117
-    public function getBody(): StreamInterface
118
-    {
119
-        if (null === $this->stream) {
120
-            $this->stream = Stream::create('');
121
-        }
122
-
123
-        return $this->stream;
124
-    }
125
-
126
-    public function withBody(StreamInterface $body): self
127
-    {
128
-        if ($body === $this->stream) {
129
-            return $this;
130
-        }
131
-
132
-        $new = clone $this;
133
-        $new->stream = $body;
134
-
135
-        return $new;
136
-    }
137
-
138
-    private function setHeaders(array $headers): void
139
-    {
140
-        foreach ($headers as $header => $value) {
141
-            $value = $this->validateAndTrimHeader($header, $value);
142
-            $normalized = \strtolower($header);
143
-            if (isset($this->headerNames[$normalized])) {
144
-                $header = $this->headerNames[$normalized];
145
-                $this->headers[$header] = \array_merge($this->headers[$header], $value);
146
-            } else {
147
-                $this->headerNames[$normalized] = $header;
148
-                $this->headers[$header] = $value;
149
-            }
150
-        }
151
-    }
152
-
153
-    /**
154
-     * Make sure the header complies with RFC 7230.
155
-     *
156
-     * Header names must be a non-empty string consisting of token characters.
157
-     *
158
-     * Header values must be strings consisting of visible characters with all optional
159
-     * leading and trailing whitespace stripped. This method will always strip such
160
-     * optional whitespace. Note that the method does not allow folding whitespace within
161
-     * the values as this was deprecated for almost all instances by the RFC.
162
-     *
163
-     * header-field = field-name ":" OWS field-value OWS
164
-     * field-name   = 1*( "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^"
165
-     *              / "_" / "`" / "|" / "~" / %x30-39 / ( %x41-5A / %x61-7A ) )
166
-     * OWS          = *( SP / HTAB )
167
-     * field-value  = *( ( %x21-7E / %x80-FF ) [ 1*( SP / HTAB ) ( %x21-7E / %x80-FF ) ] )
168
-     *
169
-     * @see https://tools.ietf.org/html/rfc7230#section-3.2.4
170
-     */
171
-    private function validateAndTrimHeader($header, $values): array
172
-    {
173
-        if (!\is_string($header) || 1 !== \preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@", $header)) {
174
-            throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string.');
175
-        }
176
-
177
-        if (!\is_array($values)) {
178
-            // This is simple, just one value.
179
-            if ((!\is_numeric($values) && !\is_string($values)) || 1 !== \preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $values)) {
180
-                throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings.');
181
-            }
182
-
183
-            return [\trim((string) $values, " \t")];
184
-        }
185
-
186
-        if (empty($values)) {
187
-            throw new \InvalidArgumentException('Header values must be a string or an array of strings, empty array given.');
188
-        }
189
-
190
-        // Assert Non empty array
191
-        $returnValues = [];
192
-        foreach ($values as $v) {
193
-            if ((!\is_numeric($v) && !\is_string($v)) || 1 !== \preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $v)) {
194
-                throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings.');
195
-            }
196
-
197
-            $returnValues[] = \trim((string) $v, " \t");
198
-        }
199
-
200
-        return $returnValues;
201
-    }
202
-}

+ 0
- 45
src/Nyholm/Psr7/Request.php View File

@@ -1,45 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\{RequestInterface, StreamInterface, UriInterface};
8
-
9
-/**
10
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
11
- * @author Martijn van der Ven <martijn@vanderven.se>
12
- */
13
-final class Request implements RequestInterface
14
-{
15
-    use MessageTrait;
16
-    use RequestTrait;
17
-
18
-    /**
19
-     * @param string $method HTTP method
20
-     * @param string|UriInterface $uri URI
21
-     * @param array $headers Request headers
22
-     * @param string|resource|StreamInterface|null $body Request body
23
-     * @param string $version Protocol version
24
-     */
25
-    public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
26
-    {
27
-        if (!($uri instanceof UriInterface)) {
28
-            $uri = new Uri($uri);
29
-        }
30
-
31
-        $this->method = $method;
32
-        $this->uri = $uri;
33
-        $this->setHeaders($headers);
34
-        $this->protocol = $version;
35
-
36
-        if (!$this->hasHeader('Host')) {
37
-            $this->updateHostFromUri();
38
-        }
39
-
40
-        // If we got no body, defer initialization of the stream until Request::getBody()
41
-        if ('' !== $body && null !== $body) {
42
-            $this->stream = Stream::create($body);
43
-        }
44
-    }
45
-}

+ 0
- 113
src/Nyholm/Psr7/RequestTrait.php View File

@@ -1,113 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\UriInterface;
8
-
9
-/**
10
- * @author Michael Dowling and contributors to guzzlehttp/psr7
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- *
14
- * @internal should not be used outside of Nyholm/Psr7 as it does not fall under our BC promise
15
- */
16
-trait RequestTrait
17
-{
18
-    /** @var string */
19
-    private $method;
20
-
21
-    /** @var string|null */
22
-    private $requestTarget;
23
-
24
-    /** @var UriInterface|null */
25
-    private $uri;
26
-
27
-    public function getRequestTarget(): string
28
-    {
29
-        if (null !== $this->requestTarget) {
30
-            return $this->requestTarget;
31
-        }
32
-
33
-        if ('' === $target = $this->uri->getPath()) {
34
-            $target = '/';
35
-        }
36
-        if ('' !== $this->uri->getQuery()) {
37
-            $target .= '?' . $this->uri->getQuery();
38
-        }
39
-
40
-        return $target;
41
-    }
42
-
43
-    public function withRequestTarget($requestTarget): self
44
-    {
45
-        if (\preg_match('#\s#', $requestTarget)) {
46
-            throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
47
-        }
48
-
49
-        $new = clone $this;
50
-        $new->requestTarget = $requestTarget;
51
-
52
-        return $new;
53
-    }
54
-
55
-    public function getMethod(): string
56
-    {
57
-        return $this->method;
58
-    }
59
-
60
-    public function withMethod($method): self
61
-    {
62
-        if (!\is_string($method)) {
63
-            throw new \InvalidArgumentException('Method must be a string');
64
-        }
65
-
66
-        $new = clone $this;
67
-        $new->method = $method;
68
-
69
-        return $new;
70
-    }
71
-
72
-    public function getUri(): UriInterface
73
-    {
74
-        return $this->uri;
75
-    }
76
-
77
-    public function withUri(UriInterface $uri, $preserveHost = false): self
78
-    {
79
-        if ($uri === $this->uri) {
80
-            return $this;
81
-        }
82
-
83
-        $new = clone $this;
84
-        $new->uri = $uri;
85
-
86
-        if (!$preserveHost || !$this->hasHeader('Host')) {
87
-            $new->updateHostFromUri();
88
-        }
89
-
90
-        return $new;
91
-    }
92
-
93
-    private function updateHostFromUri(): void
94
-    {
95
-        if ('' === $host = $this->uri->getHost()) {
96
-            return;
97
-        }
98
-
99
-        if (null !== ($port = $this->uri->getPort())) {
100
-            $host .= ':' . $port;
101
-        }
102
-
103
-        if (isset($this->headerNames['host'])) {
104
-            $header = $this->headerNames['host'];
105
-        } else {
106
-            $this->headerNames['host'] = $header = 'Host';
107
-        }
108
-
109
-        // Ensure Host is the first header.
110
-        // See: http://tools.ietf.org/html/rfc7230#section-5.4
111
-        $this->headers = [$header => [$host]] + $this->headers;
112
-    }
113
-}

+ 0
- 88
src/Nyholm/Psr7/Response.php View File

@@ -1,88 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\{ResponseInterface, StreamInterface};
8
-
9
-/**
10
- * @author Michael Dowling and contributors to guzzlehttp/psr7
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- */
14
-final class Response implements ResponseInterface
15
-{
16
-    use MessageTrait;
17
-
18
-    /** @var array Map of standard HTTP status code/reason phrases */
19
-    private const PHRASES = [
20
-        100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing',
21
-        200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported',
22
-        300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect',
23
-        400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons',
24
-        500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 511 => 'Network Authentication Required',
25
-    ];
26
-
27
-    /** @var string */
28
-    private $reasonPhrase = '';
29
-
30
-    /** @var int */
31
-    private $statusCode;
32
-
33
-    /**
34
-     * @param int $status Status code
35
-     * @param array $headers Response headers
36
-     * @param string|resource|StreamInterface|null $body Response body
37
-     * @param string $version Protocol version
38
-     * @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
39
-     */
40
-    public function __construct(int $status = 200, array $headers = [], $body = null, string $version = '1.1', string $reason = null)
41
-    {
42
-        // If we got no body, defer initialization of the stream until Response::getBody()
43
-        if ('' !== $body && null !== $body) {
44
-            $this->stream = Stream::create($body);
45
-        }
46
-
47
-        $this->statusCode = $status;
48
-        $this->setHeaders($headers);
49
-        if (null === $reason && isset(self::PHRASES[$this->statusCode])) {
50
-            $this->reasonPhrase = self::PHRASES[$status];
51
-        } else {
52
-            $this->reasonPhrase = $reason;
53
-        }
54
-
55
-        $this->protocol = $version;
56
-    }
57
-
58
-    public function getStatusCode(): int
59
-    {
60
-        return $this->statusCode;
61
-    }
62
-
63
-    public function getReasonPhrase(): string
64
-    {
65
-        return $this->reasonPhrase;
66
-    }
67
-
68
-    public function withStatus($code, $reasonPhrase = ''): self
69
-    {
70
-        if (!\is_int($code) && !\is_string($code)) {
71
-            throw new \InvalidArgumentException('Status code has to be an integer');
72
-        }
73
-
74
-        $code = (int) $code;
75
-        if ($code < 100 || $code > 599) {
76
-            throw new \InvalidArgumentException('Status code has to be an integer between 100 and 599');
77
-        }
78
-
79
-        $new = clone $this;
80
-        $new->statusCode = $code;
81
-        if ((null === $reasonPhrase || '' === $reasonPhrase) && isset(self::PHRASES[$new->statusCode])) {
82
-            $reasonPhrase = self::PHRASES[$new->statusCode];
83
-        }
84
-        $new->reasonPhrase = $reasonPhrase;
85
-
86
-        return $new;
87
-    }
88
-}

+ 0
- 162
src/Nyholm/Psr7/ServerRequest.php View File

@@ -1,162 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\{ServerRequestInterface, StreamInterface, UploadedFileInterface, UriInterface};
8
-
9
-/**
10
- * @author Michael Dowling and contributors to guzzlehttp/psr7
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- */
14
-final class ServerRequest implements ServerRequestInterface
15
-{
16
-    use MessageTrait;
17
-    use RequestTrait;
18
-
19
-    /** @var array */
20
-    private $attributes = [];
21
-
22
-    /** @var array */
23
-    private $cookieParams = [];
24
-
25
-    /** @var array|object|null */
26
-    private $parsedBody;
27
-
28
-    /** @var array */
29
-    private $queryParams = [];
30
-
31
-    /** @var array */
32
-    private $serverParams;
33
-
34
-    /** @var UploadedFileInterface[] */
35
-    private $uploadedFiles = [];
36
-
37
-    /**
38
-     * @param string $method HTTP method
39
-     * @param string|UriInterface $uri URI
40
-     * @param array $headers Request headers
41
-     * @param string|resource|StreamInterface|null $body Request body
42
-     * @param string $version Protocol version
43
-     * @param array $serverParams Typically the $_SERVER superglobal
44
-     */
45
-    public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1', array $serverParams = [])
46
-    {
47
-        $this->serverParams = $serverParams;
48
-
49
-        if (!($uri instanceof UriInterface)) {
50
-            $uri = new Uri($uri);
51
-        }
52
-
53
-        $this->method = $method;
54
-        $this->uri = $uri;
55
-        $this->setHeaders($headers);
56
-        $this->protocol = $version;
57
-
58
-        if (!$this->hasHeader('Host')) {
59
-            $this->updateHostFromUri();
60
-        }
61
-
62
-        // If we got no body, defer initialization of the stream until ServerRequest::getBody()
63
-        if ('' !== $body && null !== $body) {
64
-            $this->stream = Stream::create($body);
65
-        }
66
-    }
67
-
68
-    public function getServerParams(): array
69
-    {
70
-        return $this->serverParams;
71
-    }
72
-
73
-    public function getUploadedFiles(): array
74
-    {
75
-        return $this->uploadedFiles;
76
-    }
77
-
78
-    public function withUploadedFiles(array $uploadedFiles)
79
-    {
80
-        $new = clone $this;
81
-        $new->uploadedFiles = $uploadedFiles;
82
-
83
-        return $new;
84
-    }
85
-
86
-    public function getCookieParams(): array
87
-    {
88
-        return $this->cookieParams;
89
-    }
90
-
91
-    public function withCookieParams(array $cookies)
92
-    {
93
-        $new = clone $this;
94
-        $new->cookieParams = $cookies;
95
-
96
-        return $new;
97
-    }
98
-
99
-    public function getQueryParams(): array
100
-    {
101
-        return $this->queryParams;
102
-    }
103
-
104
-    public function withQueryParams(array $query)
105
-    {
106
-        $new = clone $this;
107
-        $new->queryParams = $query;
108
-
109
-        return $new;
110
-    }
111
-
112
-    public function getParsedBody()
113
-    {
114
-        return $this->parsedBody;
115
-    }
116
-
117
-    public function withParsedBody($data)
118
-    {
119
-        if (!\is_array($data) && !\is_object($data) && null !== $data) {
120
-            throw new \InvalidArgumentException('First parameter to withParsedBody MUST be object, array or null');
121
-        }
122
-
123
-        $new = clone $this;
124
-        $new->parsedBody = $data;
125
-
126
-        return $new;
127
-    }
128
-
129
-    public function getAttributes(): array
130
-    {
131
-        return $this->attributes;
132
-    }
133
-
134
-    public function getAttribute($attribute, $default = null)
135
-    {
136
-        if (false === \array_key_exists($attribute, $this->attributes)) {
137
-            return $default;
138
-        }
139
-
140
-        return $this->attributes[$attribute];
141
-    }
142
-
143
-    public function withAttribute($attribute, $value): self
144
-    {
145
-        $new = clone $this;
146
-        $new->attributes[$attribute] = $value;
147
-
148
-        return $new;
149
-    }
150
-
151
-    public function withoutAttribute($attribute): self
152
-    {
153
-        if (false === \array_key_exists($attribute, $this->attributes)) {
154
-            return $this;
155
-        }
156
-
157
-        $new = clone $this;
158
-        unset($new->attributes[$attribute]);
159
-
160
-        return $new;
161
-    }
162
-}

+ 0
- 257
src/Nyholm/Psr7/Stream.php View File

@@ -1,257 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\StreamInterface;
8
-
9
-/**
10
- * @author Michael Dowling and contributors to guzzlehttp/psr7
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- */
14
-final class Stream implements StreamInterface
15
-{
16
-    /** @var resource|null A resource reference */
17
-    private $stream;
18
-
19
-    /** @var bool */
20
-    private $seekable;
21
-
22
-    /** @var bool */
23
-    private $readable;
24
-
25
-    /** @var bool */
26
-    private $writable;
27
-
28
-    /** @var array|mixed|void|null */
29
-    private $uri;
30
-
31
-    /** @var int|null */
32
-    private $size;
33
-
34
-    /** @var array Hash of readable and writable stream types */
35
-    private const READ_WRITE_HASH = [
36
-        'read' => [
37
-            'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
38
-            'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
39
-            'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
40
-            'x+t' => true, 'c+t' => true, 'a+' => true,
41
-        ],
42
-        'write' => [
43
-            'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
44
-            'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true,
45
-            'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
46
-            'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true,
47
-        ],
48
-    ];
49
-
50
-    private function __construct()
51
-    {
52
-    }
53
-
54
-    /**
55
-     * Creates a new PSR-7 stream.
56
-     *
57
-     * @param string|resource|StreamInterface $body
58
-     *
59
-     * @return StreamInterface
60
-     *
61
-     * @throws \InvalidArgumentException
62
-     */
63
-    public static function create($body = ''): StreamInterface
64
-    {
65
-        if ($body instanceof StreamInterface) {
66
-            return $body;
67
-        }
68
-
69
-        if (\is_string($body)) {
70
-            $resource = \fopen('php://temp', 'rw+');
71
-            \fwrite($resource, $body);
72
-            $body = $resource;
73
-        }
74
-
75
-        if (\is_resource($body)) {
76
-            $new = new self();
77
-            $new->stream = $body;
78
-            $meta = \stream_get_meta_data($new->stream);
79
-            $new->seekable = $meta['seekable'];
80
-            $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
81
-            $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
82
-            $new->uri = $new->getMetadata('uri');
83
-
84
-            return $new;
85
-        }
86
-
87
-        throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
88
-    }
89
-
90
-    /**
91
-     * Closes the stream when the destructed.
92
-     */
93
-    public function __destruct()
94
-    {
95
-        $this->close();
96
-    }
97
-
98
-    public function __toString(): string
99
-    {
100
-        try {
101
-            if ($this->isSeekable()) {
102
-                $this->seek(0);
103
-            }
104
-
105
-            return $this->getContents();
106
-        } catch (\Exception $e) {
107
-            return '';
108
-        }
109
-    }
110
-
111
-    public function close(): void
112
-    {
113
-        if (isset($this->stream)) {
114
-            if (\is_resource($this->stream)) {
115
-                \fclose($this->stream);
116
-            }
117
-            $this->detach();
118
-        }
119
-    }
120
-
121
-    public function detach()
122
-    {
123
-        if (!isset($this->stream)) {
124
-            return null;
125
-        }
126
-
127
-        $result = $this->stream;
128
-        unset($this->stream);
129
-        $this->size = $this->uri = null;
130
-        $this->readable = $this->writable = $this->seekable = false;
131
-
132
-        return $result;
133
-    }
134
-
135
-    public function getSize(): ?int
136
-    {
137
-        if (null !== $this->size) {
138
-            return $this->size;
139
-        }
140
-
141
-        if (!isset($this->stream)) {
142
-            return null;
143
-        }
144
-
145
-        // Clear the stat cache if the stream has a URI
146
-        if ($this->uri) {
147
-            \clearstatcache(true, $this->uri);
148
-        }
149
-
150
-        $stats = \fstat($this->stream);
151
-        if (isset($stats['size'])) {
152
-            $this->size = $stats['size'];
153
-
154
-            return $this->size;
155
-        }
156
-
157
-        return null;
158
-    }
159
-
160
-    public function tell(): int
161
-    {
162
-        if (false === $result = \ftell($this->stream)) {
163
-            throw new \RuntimeException('Unable to determine stream position');
164
-        }
165
-
166
-        return $result;
167
-    }
168
-
169
-    public function eof(): bool
170
-    {
171
-        return !$this->stream || \feof($this->stream);
172
-    }
173
-
174
-    public function isSeekable(): bool
175
-    {
176
-        return $this->seekable;
177
-    }
178
-
179
-    public function seek($offset, $whence = \SEEK_SET): void
180
-    {
181
-        if (!$this->seekable) {
182
-            throw new \RuntimeException('Stream is not seekable');
183
-        }
184
-
185
-        if (-1 === \fseek($this->stream, $offset, $whence)) {
186
-            throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, true));
187
-        }
188
-    }
189
-
190
-    public function rewind(): void
191
-    {
192
-        $this->seek(0);
193
-    }
194
-
195
-    public function isWritable(): bool
196
-    {
197
-        return $this->writable;
198
-    }
199
-
200
-    public function write($string): int
201
-    {
202
-        if (!$this->writable) {
203
-            throw new \RuntimeException('Cannot write to a non-writable stream');
204
-        }
205
-
206
-        // We can't know the size after writing anything
207
-        $this->size = null;
208
-
209
-        if (false === $result = \fwrite($this->stream, $string)) {
210
-            throw new \RuntimeException('Unable to write to stream');
211
-        }
212
-
213
-        return $result;
214
-    }
215
-
216
-    public function isReadable(): bool
217
-    {
218
-        return $this->readable;
219
-    }
220
-
221
-    public function read($length): string
222
-    {
223
-        if (!$this->readable) {
224
-            throw new \RuntimeException('Cannot read from non-readable stream');
225
-        }
226
-
227
-        return \fread($this->stream, $length);
228
-    }
229
-
230
-    public function getContents(): string
231
-    {
232
-        if (!isset($this->stream)) {
233
-            throw new \RuntimeException('Unable to read stream contents');
234
-        }
235
-
236
-        if (false === $contents = \stream_get_contents($this->stream)) {
237
-            throw new \RuntimeException('Unable to read stream contents');
238
-        }
239
-
240
-        return $contents;
241
-    }
242
-
243
-    public function getMetadata($key = null)
244
-    {
245
-        if (!isset($this->stream)) {
246
-            return $key ? null : [];
247
-        }
248
-
249
-        $meta = \stream_get_meta_data($this->stream);
250
-
251
-        if (null === $key) {
252
-            return $meta;
253
-        }
254
-
255
-        return $meta[$key] ?? null;
256
-    }
257
-}

+ 0
- 171
src/Nyholm/Psr7/UploadedFile.php View File

@@ -1,171 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\{StreamInterface, UploadedFileInterface};
8
-
9
-/**
10
- * @author Michael Dowling and contributors to guzzlehttp/psr7
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- */
14
-final class UploadedFile implements UploadedFileInterface
15
-{
16
-    /** @var array */
17
-    private const ERRORS = [
18
-        \UPLOAD_ERR_OK => 1,
19
-        \UPLOAD_ERR_INI_SIZE => 1,
20
-        \UPLOAD_ERR_FORM_SIZE => 1,
21
-        \UPLOAD_ERR_PARTIAL => 1,
22
-        \UPLOAD_ERR_NO_FILE => 1,
23
-        \UPLOAD_ERR_NO_TMP_DIR => 1,
24
-        \UPLOAD_ERR_CANT_WRITE => 1,
25
-        \UPLOAD_ERR_EXTENSION => 1,
26
-    ];
27
-
28
-    /** @var string */
29
-    private $clientFilename;
30
-
31
-    /** @var string */
32
-    private $clientMediaType;
33
-
34
-    /** @var int */
35
-    private $error;
36
-
37
-    /** @var string|null */
38
-    private $file;
39
-
40
-    /** @var bool */
41
-    private $moved = false;
42
-
43
-    /** @var int */
44
-    private $size;
45
-
46
-    /** @var StreamInterface|null */
47
-    private $stream;
48
-
49
-    /**
50
-     * @param StreamInterface|string|resource $streamOrFile
51
-     * @param int $size
52
-     * @param int $errorStatus
53
-     * @param string|null $clientFilename
54
-     * @param string|null $clientMediaType
55
-     */
56
-    public function __construct($streamOrFile, $size, $errorStatus, $clientFilename = null, $clientMediaType = null)
57
-    {
58
-        if (false === \is_int($errorStatus) || !isset(self::ERRORS[$errorStatus])) {
59
-            throw new \InvalidArgumentException('Upload file error status must be an integer value and one of the "UPLOAD_ERR_*" constants.');
60
-        }
61
-
62
-        if (false === \is_int($size)) {
63
-            throw new \InvalidArgumentException('Upload file size must be an integer');
64
-        }
65
-
66
-        if (null !== $clientFilename && !\is_string($clientFilename)) {
67
-            throw new \InvalidArgumentException('Upload file client filename must be a string or null');
68
-        }
69
-
70
-        if (null !== $clientMediaType && !\is_string($clientMediaType)) {
71
-            throw new \InvalidArgumentException('Upload file client media type must be a string or null');
72
-        }
73
-
74
-        $this->error = $errorStatus;
75
-        $this->size = $size;
76
-        $this->clientFilename = $clientFilename;
77
-        $this->clientMediaType = $clientMediaType;
78
-
79
-        if (\UPLOAD_ERR_OK === $this->error) {
80
-            // Depending on the value set file or stream variable.
81
-            if (\is_string($streamOrFile)) {
82
-                $this->file = $streamOrFile;
83
-            } elseif (\is_resource($streamOrFile)) {
84
-                $this->stream = Stream::create($streamOrFile);
85
-            } elseif ($streamOrFile instanceof StreamInterface) {
86
-                $this->stream = $streamOrFile;
87
-            } else {
88
-                throw new \InvalidArgumentException('Invalid stream or file provided for UploadedFile');
89
-            }
90
-        }
91
-    }
92
-
93
-    /**
94
-     * @throws \RuntimeException if is moved or not ok
95
-     */
96
-    private function validateActive(): void
97
-    {
98
-        if (\UPLOAD_ERR_OK !== $this->error) {
99
-            throw new \RuntimeException('Cannot retrieve stream due to upload error');
100
-        }
101
-
102
-        if ($this->moved) {
103
-            throw new \RuntimeException('Cannot retrieve stream after it has already been moved');
104
-        }
105
-    }
106
-
107
-    public function getStream(): StreamInterface
108
-    {
109
-        $this->validateActive();
110
-
111
-        if ($this->stream instanceof StreamInterface) {
112
-            return $this->stream;
113
-        }
114
-
115
-        $resource = \fopen($this->file, 'r');
116
-
117
-        return Stream::create($resource);
118
-    }
119
-
120
-    public function moveTo($targetPath): void
121
-    {
122
-        $this->validateActive();
123
-
124
-        if (!\is_string($targetPath) || '' === $targetPath) {
125
-            throw new \InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
126
-        }
127
-
128
-        if (null !== $this->file) {
129
-            $this->moved = 'cli' === \PHP_SAPI ? \rename($this->file, $targetPath) : \move_uploaded_file($this->file, $targetPath);
130
-        } else {
131
-            $stream = $this->getStream();
132
-            if ($stream->isSeekable()) {
133
-                $stream->rewind();
134
-            }
135
-
136
-            // Copy the contents of a stream into another stream until end-of-file.
137
-            $dest = Stream::create(\fopen($targetPath, 'w'));
138
-            while (!$stream->eof()) {
139
-                if (!$dest->write($stream->read(1048576))) {
140
-                    break;
141
-                }
142
-            }
143
-
144
-            $this->moved = true;
145
-        }
146
-
147
-        if (false === $this->moved) {
148
-            throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath));
149
-        }
150
-    }
151
-
152
-    public function getSize(): int
153
-    {
154
-        return $this->size;
155
-    }
156
-
157
-    public function getError(): int
158
-    {
159
-        return $this->error;
160
-    }
161
-
162
-    public function getClientFilename(): ?string
163
-    {
164
-        return $this->clientFilename;
165
-    }
166
-
167
-    public function getClientMediaType(): ?string
168
-    {
169
-        return $this->clientMediaType;
170
-    }
171
-}

+ 0
- 310
src/Nyholm/Psr7/Uri.php View File

@@ -1,310 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7;
6
-
7
-use Psr\Http\Message\UriInterface;
8
-
9
-/**
10
- * PSR-7 URI implementation.
11
- *
12
- * @author Michael Dowling
13
- * @author Tobias Schultze
14
- * @author Matthew Weier O'Phinney
15
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
16
- * @author Martijn van der Ven <martijn@vanderven.se>
17
- */
18
-final class Uri implements UriInterface
19
-{
20
-    private const SCHEMES = ['http' => 80, 'https' => 443];
21
-
22
-    private const CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~';
23
-
24
-    private const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;=';
25
-
26
-    /** @var string Uri scheme. */
27
-    private $scheme = '';
28
-
29
-    /** @var string Uri user info. */
30
-    private $userInfo = '';
31
-
32
-    /** @var string Uri host. */
33
-    private $host = '';
34
-
35
-    /** @var int|null Uri port. */
36
-    private $port;
37
-
38
-    /** @var string Uri path. */
39
-    private $path = '';
40
-
41
-    /** @var string Uri query string. */
42
-    private $query = '';
43
-
44
-    /** @var string Uri fragment. */
45
-    private $fragment = '';
46
-
47
-    public function __construct(string $uri = '')
48
-    {
49
-        if ('' !== $uri) {
50
-            if (false === $parts = \parse_url($uri)) {
51
-                throw new \InvalidArgumentException("Unable to parse URI: $uri");
52
-            }
53
-
54
-            // Apply parse_url parts to a URI.
55
-            $this->scheme = isset($parts['scheme']) ? \strtolower($parts['scheme']) : '';
56
-            $this->userInfo = $parts['user'] ?? '';
57
-            $this->host = isset($parts['host']) ? \strtolower($parts['host']) : '';
58
-            $this->port = isset($parts['port']) ? $this->filterPort($parts['port']) : null;
59
-            $this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : '';
60
-            $this->query = isset($parts['query']) ? $this->filterQueryAndFragment($parts['query']) : '';
61
-            $this->fragment = isset($parts['fragment']) ? $this->filterQueryAndFragment($parts['fragment']) : '';
62
-            if (isset($parts['pass'])) {
63
-                $this->userInfo .= ':' . $parts['pass'];
64
-            }
65
-        }
66
-    }
67
-
68
-    public function __toString(): string
69
-    {
70
-        return self::createUriString($this->scheme, $this->getAuthority(), $this->path, $this->query, $this->fragment);
71
-    }
72
-
73
-    public function getScheme(): string
74
-    {
75
-        return $this->scheme;
76
-    }
77
-
78
-    public function getAuthority(): string
79
-    {
80
-        if ('' === $this->host) {
81
-            return '';
82
-        }
83
-
84
-        $authority = $this->host;
85
-        if ('' !== $this->userInfo) {
86
-            $authority = $this->userInfo . '@' . $authority;
87
-        }
88
-
89
-        if (null !== $this->port) {
90
-            $authority .= ':' . $this->port;
91
-        }
92
-
93
-        return $authority;
94
-    }
95
-
96
-    public function getUserInfo(): string
97
-    {
98
-        return $this->userInfo;
99
-    }
100
-
101
-    public function getHost(): string
102
-    {
103
-        return $this->host;
104
-    }
105
-
106
-    public function getPort(): ?int
107
-    {
108
-        return $this->port;
109
-    }
110
-
111
-    public function getPath(): string
112
-    {
113
-        return $this->path;
114
-    }
115
-
116
-    public function getQuery(): string
117
-    {
118
-        return $this->query;
119
-    }
120
-
121
-    public function getFragment(): string
122
-    {
123
-        return $this->fragment;
124
-    }
125
-
126
-    public function withScheme($scheme): self
127
-    {
128
-        if (!\is_string($scheme)) {
129
-            throw new \InvalidArgumentException('Scheme must be a string');
130
-        }
131
-
132
-        if ($this->scheme === $scheme = \strtolower($scheme)) {
133
-            return $this;
134
-        }
135
-
136
-        $new = clone $this;
137
-        $new->scheme = $scheme;
138
-        $new->port = $new->filterPort($new->port);
139
-
140
-        return $new;
141
-    }
142
-
143
-    public function withUserInfo($user, $password = null): self
144
-    {
145
-        $info = $user;
146
-        if (null !== $password && '' !== $password) {
147
-            $info .= ':' . $password;
148
-        }
149
-
150
-        if ($this->userInfo === $info) {
151
-            return $this;
152
-        }
153
-
154
-        $new = clone $this;
155
-        $new->userInfo = $info;
156
-
157
-        return $new;
158
-    }
159
-
160
-    public function withHost($host): self
161
-    {
162
-        if (!\is_string($host)) {
163
-            throw new \InvalidArgumentException('Host must be a string');
164
-        }
165
-
166
-        if ($this->host === $host = \strtolower($host)) {
167
-            return $this;
168
-        }
169
-
170
-        $new = clone $this;
171
-        $new->host = $host;
172
-
173
-        return $new;
174
-    }
175
-
176
-    public function withPort($port): self
177
-    {
178
-        if ($this->port === $port = $this->filterPort($port)) {
179
-            return $this;
180
-        }
181
-
182
-        $new = clone $this;
183
-        $new->port = $port;
184
-
185
-        return $new;
186
-    }
187
-
188
-    public function withPath($path): self
189
-    {
190
-        if ($this->path === $path = $this->filterPath($path)) {
191
-            return $this;
192
-        }
193
-
194
-        $new = clone $this;
195
-        $new->path = $path;
196
-
197
-        return $new;
198
-    }
199
-
200
-    public function withQuery($query): self
201
-    {
202
-        if ($this->query === $query = $this->filterQueryAndFragment($query)) {
203
-            return $this;
204
-        }
205
-
206
-        $new = clone $this;
207
-        $new->query = $query;
208
-
209
-        return $new;
210
-    }
211
-
212
-    public function withFragment($fragment): self
213
-    {
214
-        if ($this->fragment === $fragment = $this->filterQueryAndFragment($fragment)) {
215
-            return $this;
216
-        }
217
-
218
-        $new = clone $this;
219
-        $new->fragment = $fragment;
220
-
221
-        return $new;
222
-    }
223
-
224
-    /**
225
-     * Create a URI string from its various parts.
226
-     */
227
-    private static function createUriString(string $scheme, string $authority, string $path, string $query, string $fragment): string
228
-    {
229
-        $uri = '';
230
-        if ('' !== $scheme) {
231
-            $uri .= $scheme . ':';
232
-        }
233
-
234
-        if ('' !== $authority) {
235
-            $uri .= '//' . $authority;
236
-        }
237
-
238
-        if ('' !== $path) {
239
-            if ('/' !== $path[0]) {
240
-                if ('' !== $authority) {
241
-                    // If the path is rootless and an authority is present, the path MUST be prefixed by "/"
242
-                    $path = '/' . $path;
243
-                }
244
-            } elseif (isset($path[1]) && '/' === $path[1]) {
245
-                if ('' === $authority) {
246
-                    // If the path is starting with more than one "/" and no authority is present, the
247
-                    // starting slashes MUST be reduced to one.
248
-                    $path = '/' . \ltrim($path, '/');
249
-                }
250
-            }
251
-
252
-            $uri .= $path;
253
-        }
254
-
255
-        if ('' !== $query) {
256
-            $uri .= '?' . $query;
257
-        }
258
-
259
-        if ('' !== $fragment) {
260
-            $uri .= '#' . $fragment;
261
-        }
262
-
263
-        return $uri;
264
-    }
265
-
266
-    /**
267
-     * Is a given port non-standard for the current scheme?
268
-     */
269
-    private static function isNonStandardPort(string $scheme, int $port): bool
270
-    {
271
-        return !isset(self::SCHEMES[$scheme]) || $port !== self::SCHEMES[$scheme];
272
-    }
273
-
274
-    private function filterPort($port): ?int
275
-    {
276
-        if (null === $port) {
277
-            return null;
278
-        }
279
-
280
-        $port = (int) $port;
281
-        if (1 > $port || 0xffff < $port) {
282
-            throw new \InvalidArgumentException(\sprintf('Invalid port: %d. Must be between 1 and 65535', $port));
283
-        }
284
-
285
-        return self::isNonStandardPort($this->scheme, $port) ? $port : null;
286
-    }
287
-
288
-    private function filterPath($path): string
289
-    {
290
-        if (!\is_string($path)) {
291
-            throw new \InvalidArgumentException('Path must be a string');
292
-        }
293
-
294
-        return \preg_replace_callback('/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $path);
295
-    }
296
-
297
-    private function filterQueryAndFragment($str): string
298
-    {
299
-        if (!\is_string($str)) {
300
-            throw new \InvalidArgumentException('Query and fragment must be a string');
301
-        }
302
-
303
-        return \preg_replace_callback('/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $str);
304
-    }
305
-
306
-    private static function rawurlencodeMatchZero(array $match): string
307
-    {
308
-        return \rawurlencode($match[0]);
309
-    }
310
-}

+ 0
- 275
src/Nyholm/Psr7Server/ServerRequestCreator.php View File

@@ -1,275 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7Server;
6
-
7
-use Psr\Http\Message\ServerRequestFactoryInterface;
8
-use Psr\Http\Message\ServerRequestInterface;
9
-use Psr\Http\Message\StreamFactoryInterface;
10
-use Psr\Http\Message\StreamInterface;
11
-use Psr\Http\Message\UploadedFileFactoryInterface;
12
-use Psr\Http\Message\UploadedFileInterface;
13
-use Psr\Http\Message\UriFactoryInterface;
14
-use Psr\Http\Message\UriInterface;
15
-
16
-/**
17
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
18
- * @author Martijn van der Ven <martijn@vanderven.se>
19
- */
20
-final class ServerRequestCreator implements ServerRequestCreatorInterface
21
-{
22
-    private $serverRequestFactory;
23
-
24
-    private $uriFactory;
25
-
26
-    private $uploadedFileFactory;
27
-
28
-    private $streamFactory;
29
-
30
-    public function __construct(
31
-        ServerRequestFactoryInterface $serverRequestFactory,
32
-        UriFactoryInterface $uriFactory,
33
-        UploadedFileFactoryInterface $uploadedFileFactory,
34
-        StreamFactoryInterface $streamFactory
35
-    ) {
36
-        $this->serverRequestFactory = $serverRequestFactory;
37
-        $this->uriFactory = $uriFactory;
38
-        $this->uploadedFileFactory = $uploadedFileFactory;
39
-        $this->streamFactory = $streamFactory;
40
-    }
41
-
42
-    /**
43
-     * {@inheritdoc}
44
-     */
45
-    public function fromGlobals(): ServerRequestInterface
46
-    {
47
-        $server = $_SERVER;
48
-        if (false === isset($server['REQUEST_METHOD'])) {
49
-            $server['REQUEST_METHOD'] = 'GET';
50
-        }
51
-
52
-        $headers = \function_exists('getallheaders') ? getallheaders() : static::getHeadersFromServer($_SERVER);
53
-
54
-        return $this->fromArrays($server, $headers, $_COOKIE, $_GET, $_POST, $_FILES, \fopen('php://input', 'r') ?: null);
55
-    }
56
-
57
-    /**
58
-     * {@inheritdoc}
59
-     */
60
-    public function fromArrays(array $server, array $headers = [], array $cookie = [], array $get = [], array $post = [], array $files = [], $body = null): ServerRequestInterface
61
-    {
62
-        $method = $this->getMethodFromEnv($server);
63
-        $uri = $this->getUriFromEnvWithHTTP($server);
64
-        $protocol = isset($server['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $server['SERVER_PROTOCOL']) : '1.1';
65
-
66
-        $serverRequest = $this->serverRequestFactory->createServerRequest($method, $uri, $server);
67
-        foreach ($headers as $name => $value) {
68
-            $serverRequest = $serverRequest->withAddedHeader($name, $value);
69
-        }
70
-
71
-        $serverRequest = $serverRequest
72
-            ->withProtocolVersion($protocol)
73
-            ->withCookieParams($cookie)
74
-            ->withQueryParams($get)
75
-            ->withParsedBody($post)
76
-            ->withUploadedFiles($this->normalizeFiles($files));
77
-
78
-        if (null === $body) {
79
-            return $serverRequest;
80
-        }
81
-
82
-        if (\is_resource($body)) {
83
-            $body = $this->streamFactory->createStreamFromResource($body);
84
-        } elseif (\is_string($body)) {
85
-            $body = $this->streamFactory->createStream($body);
86
-        } elseif (!$body instanceof StreamInterface) {
87
-            throw new \InvalidArgumentException('The $body parameter to ServerRequestCreator::fromArrays must be string, resource or StreamInterface');
88
-        }
89
-
90
-        return $serverRequest->withBody($body);
91
-    }
92
-
93
-    /**
94
-     * Implementation from Zend\Diactoros\marshalHeadersFromSapi().
95
-     */
96
-    public static function getHeadersFromServer(array $server): array
97
-    {
98
-        $headers = [];
99
-        foreach ($server as $key => $value) {
100
-            // Apache prefixes environment variables with REDIRECT_
101
-            // if they are added by rewrite rules
102
-            if (0 === \strpos($key, 'REDIRECT_')) {
103
-                $key = \substr($key, 9);
104
-
105
-                // We will not overwrite existing variables with the
106
-                // prefixed versions, though
107
-                if (\array_key_exists($key, $server)) {
108
-                    continue;
109
-                }
110
-            }
111
-
112
-            if ($value && 0 === \strpos($key, 'HTTP_')) {
113
-                $name = \strtr(\strtolower(\substr($key, 5)), '_', '-');
114
-                $headers[$name] = $value;
115
-
116
-                continue;
117
-            }
118
-
119
-            if ($value && 0 === \strpos($key, 'CONTENT_')) {
120
-                $name = 'content-'.\strtolower(\substr($key, 8));
121
-                $headers[$name] = $value;
122
-
123
-                continue;
124
-            }
125
-        }
126
-
127
-        return $headers;
128
-    }
129
-
130
-    private function getMethodFromEnv(array $environment): string
131
-    {
132
-        if (false === isset($environment['REQUEST_METHOD'])) {
133
-            throw new \InvalidArgumentException('Cannot determine HTTP method');
134
-        }
135
-
136
-        return $environment['REQUEST_METHOD'];
137
-    }
138
-
139
-    private function getUriFromEnvWithHTTP(array $environment): UriInterface
140
-    {
141
-        $uri = $this->createUriFromArray($environment);
142
-        if (empty($uri->getScheme())) {
143
-            $uri = $uri->withScheme('http');
144
-        }
145
-
146
-        return $uri;
147
-    }
148
-
149
-    /**
150
-     * Return an UploadedFile instance array.
151
-     *
152
-     * @param array $files A array which respect $_FILES structure
153
-     *
154
-     * @return UploadedFileInterface[]
155
-     *
156
-     * @throws \InvalidArgumentException for unrecognized values
157
-     */
158
-    private function normalizeFiles(array $files): array
159
-    {
160
-        $normalized = [];
161
-
162
-        foreach ($files as $key => $value) {
163
-            if ($value instanceof UploadedFileInterface) {
164
-                $normalized[$key] = $value;
165
-            } elseif (\is_array($value) && isset($value['tmp_name'])) {
166
-                $normalized[$key] = $this->createUploadedFileFromSpec($value);
167
-            } elseif (\is_array($value)) {
168
-                $normalized[$key] = $this->normalizeFiles($value);
169
-            } else {
170
-                throw new \InvalidArgumentException('Invalid value in files specification');
171
-            }
172
-        }
173
-
174
-        return $normalized;
175
-    }
176
-
177
-    /**
178
-     * Create and return an UploadedFile instance from a $_FILES specification.
179
-     *
180
-     * If the specification represents an array of values, this method will
181
-     * delegate to normalizeNestedFileSpec() and return that return value.
182
-     *
183
-     * @param array $value $_FILES struct
184
-     *
185
-     * @return array|UploadedFileInterface
186
-     */
187
-    private function createUploadedFileFromSpec(array $value)
188
-    {
189
-        if (\is_array($value['tmp_name'])) {
190
-            return $this->normalizeNestedFileSpec($value);
191
-        }
192
-
193
-        try {
194
-            $stream = $this->streamFactory->createStreamFromFile($value['tmp_name']);
195
-        } catch (\RuntimeException $e) {
196
-            $stream = $this->streamFactory->createStream();
197
-        }
198
-
199
-        return $this->uploadedFileFactory->createUploadedFile(
200
-            $stream,
201
-            (int) $value['size'],
202
-            (int) $value['error'],
203
-            $value['name'],
204
-            $value['type']
205
-        );
206
-    }
207
-
208
-    /**
209
-     * Normalize an array of file specifications.
210
-     *
211
-     * Loops through all nested files and returns a normalized array of
212
-     * UploadedFileInterface instances.
213
-     *
214
-     * @param array $files
215
-     *
216
-     * @return UploadedFileInterface[]
217
-     */
218
-    private function normalizeNestedFileSpec(array $files = []): array
219
-    {
220
-        $normalizedFiles = [];
221
-
222
-        foreach (\array_keys($files['tmp_name']) as $key) {
223
-            $spec = [
224
-                'tmp_name' => $files['tmp_name'][$key],
225
-                'size' => $files['size'][$key],
226
-                'error' => $files['error'][$key],
227
-                'name' => $files['name'][$key],
228
-                'type' => $files['type'][$key],
229
-            ];
230
-            $normalizedFiles[$key] = $this->createUploadedFileFromSpec($spec);
231
-        }
232
-
233
-        return $normalizedFiles;
234
-    }
235
-
236
-    /**
237
-     * Create a new uri from server variable.
238
-     *
239
-     * @param array $server typically $_SERVER or similar structure
240
-     */
241
-    private function createUriFromArray(array $server): UriInterface
242
-    {
243
-        $uri = $this->uriFactory->createUri('');
244
-
245
-        if (isset($server['REQUEST_SCHEME'])) {
246
-            $uri = $uri->withScheme($server['REQUEST_SCHEME']);
247
-        } elseif (isset($server['HTTPS'])) {
248
-            $uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http');
249
-        }
250
-
251
-        if (isset($server['SERVER_PORT'])) {
252
-            $uri = $uri->withPort($server['SERVER_PORT']);
253
-        }
254
-
255
-        if (isset($server['HTTP_HOST'])) {
256
-            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
257
-                $uri = $uri->withHost($matches[1])->withPort($matches[2]);
258
-            } else {
259
-                $uri = $uri->withHost($server['HTTP_HOST']);
260
-            }
261
-        } elseif (isset($server['SERVER_NAME'])) {
262
-            $uri = $uri->withHost($server['SERVER_NAME']);
263
-        }
264
-
265
-        if (isset($server['REQUEST_URI'])) {
266
-            $uri = $uri->withPath(\current(\explode('?', $server['REQUEST_URI'])));
267
-        }
268
-
269
-        if (isset($server['QUERY_STRING'])) {
270
-            $uri = $uri->withQuery($server['QUERY_STRING']);
271
-        }
272
-
273
-        return $uri;
274
-    }
275
-}

+ 0
- 58
src/Nyholm/Psr7Server/ServerRequestCreatorInterface.php View File

@@ -1,58 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7Server;
6
-
7
-use Psr\Http\Message\ServerRequestInterface;
8
-use Psr\Http\Message\StreamInterface;
9
-
10
-/**
11
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12
- * @author Martijn van der Ven <martijn@vanderven.se>
13
- */
14
-interface ServerRequestCreatorInterface
15
-{
16
-    /**
17
-     * Create a new server request from the current environment variables.
18
-     * Defaults to a GET request to minimise the risk of an \InvalidArgumentException.
19
-     * Includes the current request headers as supplied by the server through `getallheaders()`.
20
-     * If `getallheaders()` is unavailable on the current server it will fallback to its own `getHeadersFromServer()` method.
21
-     * Defaults to php://input for the request body.
22
-     *
23
-     * @throws \InvalidArgumentException if no valid method or URI can be determined
24
-     */
25
-    public function fromGlobals(): ServerRequestInterface;
26
-
27
-    /**
28
-     * Create a new server request from a set of arrays.
29
-     *
30
-     * @param array                                $server  typically $_SERVER or similar structure
31
-     * @param array                                $headers typically the output of getallheaders() or similar structure
32
-     * @param array                                $cookie  typically $_COOKIE or similar structure
33
-     * @param array                                $get     typically $_GET or similar structure
34
-     * @param array                                $post    typically $_POST or similar structure
35
-     * @param array                                $files   typically $_FILES or similar structure
36
-     * @param StreamInterface|resource|string|null $body    Typically stdIn
37
-     *
38
-     * @throws \InvalidArgumentException if no valid method or URI can be determined
39
-     */
40
-    public function fromArrays(
41
-        array $server,
42
-        array $headers = [],
43
-        array $cookie = [],
44
-        array $get = [],
45
-        array $post = [],
46
-        array $files = [],
47
-        $body = null
48
-    ): ServerRequestInterface;
49
-
50
-    /**
51
-     * Get parsed headers from ($_SERVER) array.
52
-     *
53
-     * @param array $server typically $_SERVER or similar structure
54
-     *
55
-     * @return array
56
-     */
57
-    public static function getHeadersFromServer(array $server): array;
58
-}

+ 0
- 187
src/Psr/Http/Message/MessageInterface.php View File

@@ -1,187 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-/**
6
- * HTTP messages consist of requests from a client to a server and responses
7
- * from a server to a client. This interface defines the methods common to
8
- * each.
9
- *
10
- * Messages are considered immutable; all methods that might change state MUST
11
- * be implemented such that they retain the internal state of the current
12
- * message and return an instance that contains the changed state.
13
- *
14
- * @link http://www.ietf.org/rfc/rfc7230.txt
15
- * @link http://www.ietf.org/rfc/rfc7231.txt
16
- */
17
-interface MessageInterface
18
-{
19
-    /**
20
-     * Retrieves the HTTP protocol version as a string.
21
-     *
22
-     * The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
23
-     *
24
-     * @return string HTTP protocol version.
25
-     */
26
-    public function getProtocolVersion();
27
-
28
-    /**
29
-     * Return an instance with the specified HTTP protocol version.
30
-     *
31
-     * The version string MUST contain only the HTTP version number (e.g.,
32
-     * "1.1", "1.0").
33
-     *
34
-     * This method MUST be implemented in such a way as to retain the
35
-     * immutability of the message, and MUST return an instance that has the
36
-     * new protocol version.
37
-     *
38
-     * @param string $version HTTP protocol version
39
-     * @return static
40
-     */
41
-    public function withProtocolVersion($version);
42
-
43
-    /**
44
-     * Retrieves all message header values.
45
-     *
46
-     * The keys represent the header name as it will be sent over the wire, and
47
-     * each value is an array of strings associated with the header.
48
-     *
49
-     *     // Represent the headers as a string
50
-     *     foreach ($message->getHeaders() as $name => $values) {
51
-     *         echo $name . ": " . implode(", ", $values);
52
-     *     }
53
-     *
54
-     *     // Emit headers iteratively:
55
-     *     foreach ($message->getHeaders() as $name => $values) {
56
-     *         foreach ($values as $value) {
57
-     *             header(sprintf('%s: %s', $name, $value), false);
58
-     *         }
59
-     *     }
60
-     *
61
-     * While header names are not case-sensitive, getHeaders() will preserve the
62
-     * exact case in which headers were originally specified.
63
-     *
64
-     * @return string[][] Returns an associative array of the message's headers. Each
65
-     *     key MUST be a header name, and each value MUST be an array of strings
66
-     *     for that header.
67
-     */
68
-    public function getHeaders();
69
-
70
-    /**
71
-     * Checks if a header exists by the given case-insensitive name.
72
-     *
73
-     * @param string $name Case-insensitive header field name.
74
-     * @return bool Returns true if any header names match the given header
75
-     *     name using a case-insensitive string comparison. Returns false if
76
-     *     no matching header name is found in the message.
77
-     */
78
-    public function hasHeader($name);
79
-
80
-    /**
81
-     * Retrieves a message header value by the given case-insensitive name.
82
-     *
83
-     * This method returns an array of all the header values of the given
84
-     * case-insensitive header name.
85
-     *
86
-     * If the header does not appear in the message, this method MUST return an
87
-     * empty array.
88
-     *
89
-     * @param string $name Case-insensitive header field name.
90
-     * @return string[] An array of string values as provided for the given
91
-     *    header. If the header does not appear in the message, this method MUST
92
-     *    return an empty array.
93
-     */
94
-    public function getHeader($name);
95
-
96
-    /**
97
-     * Retrieves a comma-separated string of the values for a single header.
98
-     *
99
-     * This method returns all of the header values of the given
100
-     * case-insensitive header name as a string concatenated together using
101
-     * a comma.
102
-     *
103
-     * NOTE: Not all header values may be appropriately represented using
104
-     * comma concatenation. For such headers, use getHeader() instead
105
-     * and supply your own delimiter when concatenating.
106
-     *
107
-     * If the header does not appear in the message, this method MUST return
108
-     * an empty string.
109
-     *
110
-     * @param string $name Case-insensitive header field name.
111
-     * @return string A string of values as provided for the given header
112
-     *    concatenated together using a comma. If the header does not appear in
113
-     *    the message, this method MUST return an empty string.
114
-     */
115
-    public function getHeaderLine($name);
116
-
117
-    /**
118
-     * Return an instance with the provided value replacing the specified header.
119
-     *
120
-     * While header names are case-insensitive, the casing of the header will
121
-     * be preserved by this function, and returned from getHeaders().
122
-     *
123
-     * This method MUST be implemented in such a way as to retain the
124
-     * immutability of the message, and MUST return an instance that has the
125
-     * new and/or updated header and value.
126
-     *
127
-     * @param string $name Case-insensitive header field name.
128
-     * @param string|string[] $value Header value(s).
129
-     * @return static
130
-     * @throws \InvalidArgumentException for invalid header names or values.
131
-     */
132
-    public function withHeader($name, $value);
133
-
134
-    /**
135
-     * Return an instance with the specified header appended with the given value.
136
-     *
137
-     * Existing values for the specified header will be maintained. The new
138
-     * value(s) will be appended to the existing list. If the header did not
139
-     * exist previously, it will be added.
140
-     *
141
-     * This method MUST be implemented in such a way as to retain the
142
-     * immutability of the message, and MUST return an instance that has the
143
-     * new header and/or value.
144
-     *
145
-     * @param string $name Case-insensitive header field name to add.
146
-     * @param string|string[] $value Header value(s).
147
-     * @return static
148
-     * @throws \InvalidArgumentException for invalid header names or values.
149
-     */
150
-    public function withAddedHeader($name, $value);
151
-
152
-    /**
153
-     * Return an instance without the specified header.
154
-     *
155
-     * Header resolution MUST be done without case-sensitivity.
156
-     *
157
-     * This method MUST be implemented in such a way as to retain the
158
-     * immutability of the message, and MUST return an instance that removes
159
-     * the named header.
160
-     *
161
-     * @param string $name Case-insensitive header field name to remove.
162
-     * @return static
163
-     */
164
-    public function withoutHeader($name);
165
-
166
-    /**
167
-     * Gets the body of the message.
168
-     *
169
-     * @return StreamInterface Returns the body as a stream.
170
-     */
171
-    public function getBody();
172
-
173
-    /**
174
-     * Return an instance with the specified message body.
175
-     *
176
-     * The body MUST be a StreamInterface object.
177
-     *
178
-     * This method MUST be implemented in such a way as to retain the
179
-     * immutability of the message, and MUST return a new instance that has the
180
-     * new body stream.
181
-     *
182
-     * @param StreamInterface $body Body.
183
-     * @return static
184
-     * @throws \InvalidArgumentException When the body is not valid.
185
-     */
186
-    public function withBody(StreamInterface $body);
187
-}

+ 0
- 18
src/Psr/Http/Message/RequestFactoryInterface.php View File

@@ -1,18 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-interface RequestFactoryInterface
6
-{
7
-    /**
8
-     * Create a new request.
9
-     *
10
-     * @param string $method The HTTP method associated with the request.
11
-     * @param UriInterface|string $uri The URI associated with the request. If
12
-     *     the value is a string, the factory MUST create a UriInterface
13
-     *     instance based on it.
14
-     *
15
-     * @return RequestInterface
16
-     */
17
-    public function createRequest(string $method, $uri): RequestInterface;
18
-}

+ 0
- 129
src/Psr/Http/Message/RequestInterface.php View File

@@ -1,129 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-/**
6
- * Representation of an outgoing, client-side request.
7
- *
8
- * Per the HTTP specification, this interface includes properties for
9
- * each of the following:
10
- *
11
- * - Protocol version
12
- * - HTTP method
13
- * - URI
14
- * - Headers
15
- * - Message body
16
- *
17
- * During construction, implementations MUST attempt to set the Host header from
18
- * a provided URI if no Host header is provided.
19
- *
20
- * Requests are considered immutable; all methods that might change state MUST
21
- * be implemented such that they retain the internal state of the current
22
- * message and return an instance that contains the changed state.
23
- */
24
-interface RequestInterface extends MessageInterface
25
-{
26
-    /**
27
-     * Retrieves the message's request target.
28
-     *
29
-     * Retrieves the message's request-target either as it will appear (for
30
-     * clients), as it appeared at request (for servers), or as it was
31
-     * specified for the instance (see withRequestTarget()).
32
-     *
33
-     * In most cases, this will be the origin-form of the composed URI,
34
-     * unless a value was provided to the concrete implementation (see
35
-     * withRequestTarget() below).
36
-     *
37
-     * If no URI is available, and no request-target has been specifically
38
-     * provided, this method MUST return the string "/".
39
-     *
40
-     * @return string
41
-     */
42
-    public function getRequestTarget();
43
-
44
-    /**
45
-     * Return an instance with the specific request-target.
46
-     *
47
-     * If the request needs a non-origin-form request-target — e.g., for
48
-     * specifying an absolute-form, authority-form, or asterisk-form —
49
-     * this method may be used to create an instance with the specified
50
-     * request-target, verbatim.
51
-     *
52
-     * This method MUST be implemented in such a way as to retain the
53
-     * immutability of the message, and MUST return an instance that has the
54
-     * changed request target.
55
-     *
56
-     * @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
57
-     *     request-target forms allowed in request messages)
58
-     * @param mixed $requestTarget
59
-     * @return static
60
-     */
61
-    public function withRequestTarget($requestTarget);
62
-
63
-    /**
64
-     * Retrieves the HTTP method of the request.
65
-     *
66
-     * @return string Returns the request method.
67
-     */
68
-    public function getMethod();
69
-
70
-    /**
71
-     * Return an instance with the provided HTTP method.
72
-     *
73
-     * While HTTP method names are typically all uppercase characters, HTTP
74
-     * method names are case-sensitive and thus implementations SHOULD NOT
75
-     * modify the given string.
76
-     *
77
-     * This method MUST be implemented in such a way as to retain the
78
-     * immutability of the message, and MUST return an instance that has the
79
-     * changed request method.
80
-     *
81
-     * @param string $method Case-sensitive method.
82
-     * @return static
83
-     * @throws \InvalidArgumentException for invalid HTTP methods.
84
-     */
85
-    public function withMethod($method);
86
-
87
-    /**
88
-     * Retrieves the URI instance.
89
-     *
90
-     * This method MUST return a UriInterface instance.
91
-     *
92
-     * @link http://tools.ietf.org/html/rfc3986#section-4.3
93
-     * @return UriInterface Returns a UriInterface instance
94
-     *     representing the URI of the request.
95
-     */
96
-    public function getUri();
97
-
98
-    /**
99
-     * Returns an instance with the provided URI.
100
-     *
101
-     * This method MUST update the Host header of the returned request by
102
-     * default if the URI contains a host component. If the URI does not
103
-     * contain a host component, any pre-existing Host header MUST be carried
104
-     * over to the returned request.
105
-     *
106
-     * You can opt-in to preserving the original state of the Host header by
107
-     * setting `$preserveHost` to `true`. When `$preserveHost` is set to
108
-     * `true`, this method interacts with the Host header in the following ways:
109
-     *
110
-     * - If the Host header is missing or empty, and the new URI contains
111
-     *   a host component, this method MUST update the Host header in the returned
112
-     *   request.
113
-     * - If the Host header is missing or empty, and the new URI does not contain a
114
-     *   host component, this method MUST NOT update the Host header in the returned
115
-     *   request.
116
-     * - If a Host header is present and non-empty, this method MUST NOT update
117
-     *   the Host header in the returned request.
118
-     *
119
-     * This method MUST be implemented in such a way as to retain the
120
-     * immutability of the message, and MUST return an instance that has the
121
-     * new UriInterface instance.
122
-     *
123
-     * @link http://tools.ietf.org/html/rfc3986#section-4.3
124
-     * @param UriInterface $uri New request URI to use.
125
-     * @param bool $preserveHost Preserve the original state of the Host header.
126
-     * @return static
127
-     */
128
-    public function withUri(UriInterface $uri, $preserveHost = false);
129
-}

+ 0
- 18
src/Psr/Http/Message/ResponseFactoryInterface.php View File

@@ -1,18 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-interface ResponseFactoryInterface
6
-{
7
-    /**
8
-     * Create a new response.
9
-     *
10
-     * @param int $code HTTP status code; defaults to 200
11
-     * @param string $reasonPhrase Reason phrase to associate with status code
12
-     *     in generated response; if none is provided implementations MAY use
13
-     *     the defaults as suggested in the HTTP specification.
14
-     *
15
-     * @return ResponseInterface
16
-     */
17
-    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface;
18
-}

+ 0
- 68
src/Psr/Http/Message/ResponseInterface.php View File

@@ -1,68 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-/**
6
- * Representation of an outgoing, server-side response.
7
- *
8
- * Per the HTTP specification, this interface includes properties for
9
- * each of the following:
10
- *
11
- * - Protocol version
12
- * - Status code and reason phrase
13
- * - Headers
14
- * - Message body
15
- *
16
- * Responses are considered immutable; all methods that might change state MUST
17
- * be implemented such that they retain the internal state of the current
18
- * message and return an instance that contains the changed state.
19
- */
20
-interface ResponseInterface extends MessageInterface
21
-{
22
-    /**
23
-     * Gets the response status code.
24
-     *
25
-     * The status code is a 3-digit integer result code of the server's attempt
26
-     * to understand and satisfy the request.
27
-     *
28
-     * @return int Status code.
29
-     */
30
-    public function getStatusCode();
31
-
32
-    /**
33
-     * Return an instance with the specified status code and, optionally, reason phrase.
34
-     *
35
-     * If no reason phrase is specified, implementations MAY choose to default
36
-     * to the RFC 7231 or IANA recommended reason phrase for the response's
37
-     * status code.
38
-     *
39
-     * This method MUST be implemented in such a way as to retain the
40
-     * immutability of the message, and MUST return an instance that has the
41
-     * updated status and reason phrase.
42
-     *
43
-     * @link http://tools.ietf.org/html/rfc7231#section-6
44
-     * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
45
-     * @param int $code The 3-digit integer result code to set.
46
-     * @param string $reasonPhrase The reason phrase to use with the
47
-     *     provided status code; if none is provided, implementations MAY
48
-     *     use the defaults as suggested in the HTTP specification.
49
-     * @return static
50
-     * @throws \InvalidArgumentException For invalid status code arguments.
51
-     */
52
-    public function withStatus($code, $reasonPhrase = '');
53
-
54
-    /**
55
-     * Gets the response reason phrase associated with the status code.
56
-     *
57
-     * Because a reason phrase is not a required element in a response
58
-     * status line, the reason phrase value MAY be null. Implementations MAY
59
-     * choose to return the default RFC 7231 recommended reason phrase (or those
60
-     * listed in the IANA HTTP Status Code Registry) for the response's
61
-     * status code.
62
-     *
63
-     * @link http://tools.ietf.org/html/rfc7231#section-6
64
-     * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
65
-     * @return string Reason phrase; must return an empty string if none present.
66
-     */
67
-    public function getReasonPhrase();
68
-}

+ 0
- 24
src/Psr/Http/Message/ServerRequestFactoryInterface.php View File

@@ -1,24 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-interface ServerRequestFactoryInterface
6
-{
7
-    /**
8
-     * Create a new server request.
9
-     *
10
-     * Note that server-params are taken precisely as given - no parsing/processing
11
-     * of the given values is performed, and, in particular, no attempt is made to
12
-     * determine the HTTP method or URI, which must be provided explicitly.
13
-     *
14
-     * @param string $method The HTTP method associated with the request.
15
-     * @param UriInterface|string $uri The URI associated with the request. If
16
-     *     the value is a string, the factory MUST create a UriInterface
17
-     *     instance based on it.
18
-     * @param array $serverParams Array of SAPI parameters with which to seed
19
-     *     the generated request instance.
20
-     *
21
-     * @return ServerRequestInterface
22
-     */
23
-    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface;
24
-}

+ 0
- 261
src/Psr/Http/Message/ServerRequestInterface.php View File

@@ -1,261 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-/**
6
- * Representation of an incoming, server-side HTTP request.
7
- *
8
- * Per the HTTP specification, this interface includes properties for
9
- * each of the following:
10
- *
11
- * - Protocol version
12
- * - HTTP method
13
- * - URI
14
- * - Headers
15
- * - Message body
16
- *
17
- * Additionally, it encapsulates all data as it has arrived to the
18
- * application from the CGI and/or PHP environment, including:
19
- *
20
- * - The values represented in $_SERVER.
21
- * - Any cookies provided (generally via $_COOKIE)
22
- * - Query string arguments (generally via $_GET, or as parsed via parse_str())
23
- * - Upload files, if any (as represented by $_FILES)
24
- * - Deserialized body parameters (generally from $_POST)
25
- *
26
- * $_SERVER values MUST be treated as immutable, as they represent application
27
- * state at the time of request; as such, no methods are provided to allow
28
- * modification of those values. The other values provide such methods, as they
29
- * can be restored from $_SERVER or the request body, and may need treatment
30
- * during the application (e.g., body parameters may be deserialized based on
31
- * content type).
32
- *
33
- * Additionally, this interface recognizes the utility of introspecting a
34
- * request to derive and match additional parameters (e.g., via URI path
35
- * matching, decrypting cookie values, deserializing non-form-encoded body
36
- * content, matching authorization headers to users, etc). These parameters
37
- * are stored in an "attributes" property.
38
- *
39
- * Requests are considered immutable; all methods that might change state MUST
40
- * be implemented such that they retain the internal state of the current
41
- * message and return an instance that contains the changed state.
42
- */
43
-interface ServerRequestInterface extends RequestInterface
44
-{
45
-    /**
46
-     * Retrieve server parameters.
47
-     *
48
-     * Retrieves data related to the incoming request environment,
49
-     * typically derived from PHP's $_SERVER superglobal. The data IS NOT
50
-     * REQUIRED to originate from $_SERVER.
51
-     *
52
-     * @return array
53
-     */
54
-    public function getServerParams();
55
-
56
-    /**
57
-     * Retrieve cookies.
58
-     *
59
-     * Retrieves cookies sent by the client to the server.
60
-     *
61
-     * The data MUST be compatible with the structure of the $_COOKIE
62
-     * superglobal.
63
-     *
64
-     * @return array
65
-     */
66
-    public function getCookieParams();
67
-
68
-    /**
69
-     * Return an instance with the specified cookies.
70
-     *
71
-     * The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
72
-     * be compatible with the structure of $_COOKIE. Typically, this data will
73
-     * be injected at instantiation.
74
-     *
75
-     * This method MUST NOT update the related Cookie header of the request
76
-     * instance, nor related values in the server params.
77
-     *
78
-     * This method MUST be implemented in such a way as to retain the
79
-     * immutability of the message, and MUST return an instance that has the
80
-     * updated cookie values.
81
-     *
82
-     * @param array $cookies Array of key/value pairs representing cookies.
83
-     * @return static
84
-     */
85
-    public function withCookieParams(array $cookies);
86
-
87
-    /**
88
-     * Retrieve query string arguments.
89
-     *
90
-     * Retrieves the deserialized query string arguments, if any.
91
-     *
92
-     * Note: the query params might not be in sync with the URI or server
93
-     * params. If you need to ensure you are only getting the original
94
-     * values, you may need to parse the query string from `getUri()->getQuery()`
95
-     * or from the `QUERY_STRING` server param.
96
-     *
97
-     * @return array
98
-     */
99
-    public function getQueryParams();
100
-
101
-    /**
102
-     * Return an instance with the specified query string arguments.
103
-     *
104
-     * These values SHOULD remain immutable over the course of the incoming
105
-     * request. They MAY be injected during instantiation, such as from PHP's
106
-     * $_GET superglobal, or MAY be derived from some other value such as the
107
-     * URI. In cases where the arguments are parsed from the URI, the data
108
-     * MUST be compatible with what PHP's parse_str() would return for
109
-     * purposes of how duplicate query parameters are handled, and how nested
110
-     * sets are handled.
111
-     *
112
-     * Setting query string arguments MUST NOT change the URI stored by the
113
-     * request, nor the values in the server params.
114
-     *
115
-     * This method MUST be implemented in such a way as to retain the
116
-     * immutability of the message, and MUST return an instance that has the
117
-     * updated query string arguments.
118
-     *
119
-     * @param array $query Array of query string arguments, typically from
120
-     *     $_GET.
121
-     * @return static
122
-     */
123
-    public function withQueryParams(array $query);
124
-
125
-    /**
126
-     * Retrieve normalized file upload data.
127
-     *
128
-     * This method returns upload metadata in a normalized tree, with each leaf
129
-     * an instance of Psr\Http\Message\UploadedFileInterface.
130
-     *
131
-     * These values MAY be prepared from $_FILES or the message body during
132
-     * instantiation, or MAY be injected via withUploadedFiles().
133
-     *
134
-     * @return array An array tree of UploadedFileInterface instances; an empty
135
-     *     array MUST be returned if no data is present.
136
-     */
137
-    public function getUploadedFiles();
138
-
139
-    /**
140
-     * Create a new instance with the specified uploaded files.
141
-     *
142
-     * This method MUST be implemented in such a way as to retain the
143
-     * immutability of the message, and MUST return an instance that has the
144
-     * updated body parameters.
145
-     *
146
-     * @param array $uploadedFiles An array tree of UploadedFileInterface instances.
147
-     * @return static
148
-     * @throws \InvalidArgumentException if an invalid structure is provided.
149
-     */
150
-    public function withUploadedFiles(array $uploadedFiles);
151
-
152
-    /**
153
-     * Retrieve any parameters provided in the request body.
154
-     *
155
-     * If the request Content-Type is either application/x-www-form-urlencoded
156
-     * or multipart/form-data, and the request method is POST, this method MUST
157
-     * return the contents of $_POST.
158
-     *
159
-     * Otherwise, this method may return any results of deserializing
160
-     * the request body content; as parsing returns structured content, the
161
-     * potential types MUST be arrays or objects only. A null value indicates
162
-     * the absence of body content.
163
-     *
164
-     * @return null|array|object The deserialized body parameters, if any.
165
-     *     These will typically be an array or object.
166
-     */
167
-    public function getParsedBody();
168
-
169
-    /**
170
-     * Return an instance with the specified body parameters.
171
-     *
172
-     * These MAY be injected during instantiation.
173
-     *
174
-     * If the request Content-Type is either application/x-www-form-urlencoded
175
-     * or multipart/form-data, and the request method is POST, use this method
176
-     * ONLY to inject the contents of $_POST.
177
-     *
178
-     * The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
179
-     * deserializing the request body content. Deserialization/parsing returns
180
-     * structured data, and, as such, this method ONLY accepts arrays or objects,
181
-     * or a null value if nothing was available to parse.
182
-     *
183
-     * As an example, if content negotiation determines that the request data
184
-     * is a JSON payload, this method could be used to create a request
185
-     * instance with the deserialized parameters.
186
-     *
187
-     * This method MUST be implemented in such a way as to retain the
188
-     * immutability of the message, and MUST return an instance that has the
189
-     * updated body parameters.
190
-     *
191
-     * @param null|array|object $data The deserialized body data. This will
192
-     *     typically be in an array or object.
193
-     * @return static
194
-     * @throws \InvalidArgumentException if an unsupported argument type is
195
-     *     provided.
196
-     */
197
-    public function withParsedBody($data);
198
-
199
-    /**
200
-     * Retrieve attributes derived from the request.
201
-     *
202
-     * The request "attributes" may be used to allow injection of any
203
-     * parameters derived from the request: e.g., the results of path
204
-     * match operations; the results of decrypting cookies; the results of
205
-     * deserializing non-form-encoded message bodies; etc. Attributes
206
-     * will be application and request specific, and CAN be mutable.
207
-     *
208
-     * @return array Attributes derived from the request.
209
-     */
210
-    public function getAttributes();
211
-
212
-    /**
213
-     * Retrieve a single derived request attribute.
214
-     *
215
-     * Retrieves a single derived request attribute as described in
216
-     * getAttributes(). If the attribute has not been previously set, returns
217
-     * the default value as provided.
218
-     *
219
-     * This method obviates the need for a hasAttribute() method, as it allows
220
-     * specifying a default value to return if the attribute is not found.
221
-     *
222
-     * @see getAttributes()
223
-     * @param string $name The attribute name.
224
-     * @param mixed $default Default value to return if the attribute does not exist.
225
-     * @return mixed
226
-     */
227
-    public function getAttribute($name, $default = null);
228
-
229
-    /**
230
-     * Return an instance with the specified derived request attribute.
231
-     *
232
-     * This method allows setting a single derived request attribute as
233
-     * described in getAttributes().
234
-     *
235
-     * This method MUST be implemented in such a way as to retain the
236
-     * immutability of the message, and MUST return an instance that has the
237
-     * updated attribute.
238
-     *
239
-     * @see getAttributes()
240
-     * @param string $name The attribute name.
241
-     * @param mixed $value The value of the attribute.
242
-     * @return static
243
-     */
244
-    public function withAttribute($name, $value);
245
-
246
-    /**
247
-     * Return an instance that removes the specified derived request attribute.
248
-     *
249
-     * This method allows removing a single derived request attribute as
250
-     * described in getAttributes().
251
-     *
252
-     * This method MUST be implemented in such a way as to retain the
253
-     * immutability of the message, and MUST return an instance that removes
254
-     * the attribute.
255
-     *
256
-     * @see getAttributes()
257
-     * @param string $name The attribute name.
258
-     * @return static
259
-     */
260
-    public function withoutAttribute($name);
261
-}

+ 0
- 43
src/Psr/Http/Message/StreamFactoryInterface.php View File

@@ -1,43 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-interface StreamFactoryInterface
6
-{
7
-    /**
8
-     * Create a new stream from a string.
9
-     *
10
-     * The stream SHOULD be created with a temporary resource.
11
-     *
12
-     * @param string $content String content with which to populate the stream.
13
-     *
14
-     * @return StreamInterface
15
-     */
16
-    public function createStream(string $content = ''): StreamInterface;
17
-
18
-    /**
19
-     * Create a stream from an existing file.
20
-     *
21
-     * The file MUST be opened using the given mode, which may be any mode
22
-     * supported by the `fopen` function.
23
-     *
24
-     * The `$filename` MAY be any string supported by `fopen()`.
25
-     *
26
-     * @param string $filename Filename or stream URI to use as basis of stream.
27
-     * @param string $mode Mode with which to open the underlying filename/stream.
28
-     *
29
-     * @return StreamInterface
30
-     */
31
-    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface;
32
-
33
-    /**
34
-     * Create a new stream from an existing resource.
35
-     *
36
-     * The stream MUST be readable and may be writable.
37
-     *
38
-     * @param resource $resource PHP resource to use as basis of stream.
39
-     *
40
-     * @return StreamInterface
41
-     */
42
-    public function createStreamFromResource($resource): StreamInterface;
43
-}

+ 0
- 158
src/Psr/Http/Message/StreamInterface.php View File

@@ -1,158 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-/**
6
- * Describes a data stream.
7
- *
8
- * Typically, an instance will wrap a PHP stream; this interface provides
9
- * a wrapper around the most common operations, including serialization of
10
- * the entire stream to a string.
11
- */
12
-interface StreamInterface
13
-{
14
-    /**
15
-     * Reads all data from the stream into a string, from the beginning to end.
16
-     *
17
-     * This method MUST attempt to seek to the beginning of the stream before
18
-     * reading data and read the stream until the end is reached.
19
-     *
20
-     * Warning: This could attempt to load a large amount of data into memory.
21
-     *
22
-     * This method MUST NOT raise an exception in order to conform with PHP's
23
-     * string casting operations.
24
-     *
25
-     * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
26
-     * @return string
27
-     */
28
-    public function __toString();
29
-
30
-    /**
31
-     * Closes the stream and any underlying resources.
32
-     *
33
-     * @return void
34
-     */
35
-    public function close();
36
-
37
-    /**
38
-     * Separates any underlying resources from the stream.
39
-     *
40
-     * After the stream has been detached, the stream is in an unusable state.
41
-     *
42
-     * @return resource|null Underlying PHP stream, if any
43
-     */
44
-    public function detach();
45
-
46
-    /**
47
-     * Get the size of the stream if known.
48
-     *
49
-     * @return int|null Returns the size in bytes if known, or null if unknown.
50
-     */
51
-    public function getSize();
52
-
53
-    /**
54
-     * Returns the current position of the file read/write pointer
55
-     *
56
-     * @return int Position of the file pointer
57
-     * @throws \RuntimeException on error.
58
-     */
59
-    public function tell();
60
-
61
-    /**
62
-     * Returns true if the stream is at the end of the stream.
63
-     *
64
-     * @return bool
65
-     */
66
-    public function eof();
67
-
68
-    /**
69
-     * Returns whether or not the stream is seekable.
70
-     *
71
-     * @return bool
72
-     */
73
-    public function isSeekable();
74
-
75
-    /**
76
-     * Seek to a position in the stream.
77
-     *
78
-     * @link http://www.php.net/manual/en/function.fseek.php
79
-     * @param int $offset Stream offset
80
-     * @param int $whence Specifies how the cursor position will be calculated
81
-     *     based on the seek offset. Valid values are identical to the built-in
82
-     *     PHP $whence values for `fseek()`.  SEEK_SET: Set position equal to
83
-     *     offset bytes SEEK_CUR: Set position to current location plus offset
84
-     *     SEEK_END: Set position to end-of-stream plus offset.
85
-     * @throws \RuntimeException on failure.
86
-     */
87
-    public function seek($offset, $whence = SEEK_SET);
88
-
89
-    /**
90
-     * Seek to the beginning of the stream.
91
-     *
92
-     * If the stream is not seekable, this method will raise an exception;
93
-     * otherwise, it will perform a seek(0).
94
-     *
95
-     * @see seek()
96
-     * @link http://www.php.net/manual/en/function.fseek.php
97
-     * @throws \RuntimeException on failure.
98
-     */
99
-    public function rewind();
100
-
101
-    /**
102
-     * Returns whether or not the stream is writable.
103
-     *
104
-     * @return bool
105
-     */
106
-    public function isWritable();
107
-
108
-    /**
109
-     * Write data to the stream.
110
-     *
111
-     * @param string $string The string that is to be written.
112
-     * @return int Returns the number of bytes written to the stream.
113
-     * @throws \RuntimeException on failure.
114
-     */
115
-    public function write($string);
116
-
117
-    /**
118
-     * Returns whether or not the stream is readable.
119
-     *
120
-     * @return bool
121
-     */
122
-    public function isReadable();
123
-
124
-    /**
125
-     * Read data from the stream.
126
-     *
127
-     * @param int $length Read up to $length bytes from the object and return
128
-     *     them. Fewer than $length bytes may be returned if underlying stream
129
-     *     call returns fewer bytes.
130
-     * @return string Returns the data read from the stream, or an empty string
131
-     *     if no bytes are available.
132
-     * @throws \RuntimeException if an error occurs.
133
-     */
134
-    public function read($length);
135
-
136
-    /**
137
-     * Returns the remaining contents in a string
138
-     *
139
-     * @return string
140
-     * @throws \RuntimeException if unable to read or an error occurs while
141
-     *     reading.
142
-     */
143
-    public function getContents();
144
-
145
-    /**
146
-     * Get stream metadata as an associative array or retrieve a specific key.
147
-     *
148
-     * The keys returned are identical to the keys returned from PHP's
149
-     * stream_get_meta_data() function.
150
-     *
151
-     * @link http://php.net/manual/en/function.stream-get-meta-data.php
152
-     * @param string $key Specific metadata to retrieve.
153
-     * @return array|mixed|null Returns an associative array if no key is
154
-     *     provided. Returns a specific key value if a key is provided and the
155
-     *     value is found, or null if the key is not found.
156
-     */
157
-    public function getMetadata($key = null);
158
-}

+ 0
- 34
src/Psr/Http/Message/UploadedFileFactoryInterface.php View File

@@ -1,34 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-interface UploadedFileFactoryInterface
6
-{
7
-    /**
8
-     * Create a new uploaded file.
9
-     *
10
-     * If a size is not provided it will be determined by checking the size of
11
-     * the file.
12
-     *
13
-     * @see http://php.net/manual/features.file-upload.post-method.php
14
-     * @see http://php.net/manual/features.file-upload.errors.php
15
-     *
16
-     * @param StreamInterface $stream Underlying stream representing the
17
-     *     uploaded file content.
18
-     * @param int $size in bytes
19
-     * @param int $error PHP file upload error
20
-     * @param string $clientFilename Filename as provided by the client, if any.
21
-     * @param string $clientMediaType Media type as provided by the client, if any.
22
-     *
23
-     * @return UploadedFileInterface
24
-     *
25
-     * @throws \InvalidArgumentException If the file resource is not readable.
26
-     */
27
-    public function createUploadedFile(
28
-        StreamInterface $stream,
29
-        int $size = null,
30
-        int $error = \UPLOAD_ERR_OK,
31
-        string $clientFilename = null,
32
-        string $clientMediaType = null
33
-    ): UploadedFileInterface;
34
-}

+ 0
- 123
src/Psr/Http/Message/UploadedFileInterface.php View File

@@ -1,123 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-/**
6
- * Value object representing a file uploaded through an HTTP request.
7
- *
8
- * Instances of this interface are considered immutable; all methods that
9
- * might change state MUST be implemented such that they retain the internal
10
- * state of the current instance and return an instance that contains the
11
- * changed state.
12
- */
13
-interface UploadedFileInterface
14
-{
15
-    /**
16
-     * Retrieve a stream representing the uploaded file.
17
-     *
18
-     * This method MUST return a StreamInterface instance, representing the
19
-     * uploaded file. The purpose of this method is to allow utilizing native PHP
20
-     * stream functionality to manipulate the file upload, such as
21
-     * stream_copy_to_stream() (though the result will need to be decorated in a
22
-     * native PHP stream wrapper to work with such functions).
23
-     *
24
-     * If the moveTo() method has been called previously, this method MUST raise
25
-     * an exception.
26
-     *
27
-     * @return StreamInterface Stream representation of the uploaded file.
28
-     * @throws \RuntimeException in cases when no stream is available or can be
29
-     *     created.
30
-     */
31
-    public function getStream();
32
-
33
-    /**
34
-     * Move the uploaded file to a new location.
35
-     *
36
-     * Use this method as an alternative to move_uploaded_file(). This method is
37
-     * guaranteed to work in both SAPI and non-SAPI environments.
38
-     * Implementations must determine which environment they are in, and use the
39
-     * appropriate method (move_uploaded_file(), rename(), or a stream
40
-     * operation) to perform the operation.
41
-     *
42
-     * $targetPath may be an absolute path, or a relative path. If it is a
43
-     * relative path, resolution should be the same as used by PHP's rename()
44
-     * function.
45
-     *
46
-     * The original file or stream MUST be removed on completion.
47
-     *
48
-     * If this method is called more than once, any subsequent calls MUST raise
49
-     * an exception.
50
-     *
51
-     * When used in an SAPI environment where $_FILES is populated, when writing
52
-     * files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be
53
-     * used to ensure permissions and upload status are verified correctly.
54
-     *
55
-     * If you wish to move to a stream, use getStream(), as SAPI operations
56
-     * cannot guarantee writing to stream destinations.
57
-     *
58
-     * @see http://php.net/is_uploaded_file
59
-     * @see http://php.net/move_uploaded_file
60
-     * @param string $targetPath Path to which to move the uploaded file.
61
-     * @throws \InvalidArgumentException if the $targetPath specified is invalid.
62
-     * @throws \RuntimeException on any error during the move operation, or on
63
-     *     the second or subsequent call to the method.
64
-     */
65
-    public function moveTo($targetPath);
66
-    
67
-    /**
68
-     * Retrieve the file size.
69
-     *
70
-     * Implementations SHOULD return the value stored in the "size" key of
71
-     * the file in the $_FILES array if available, as PHP calculates this based
72
-     * on the actual size transmitted.
73
-     *
74
-     * @return int|null The file size in bytes or null if unknown.
75
-     */
76
-    public function getSize();
77
-    
78
-    /**
79
-     * Retrieve the error associated with the uploaded file.
80
-     *
81
-     * The return value MUST be one of PHP's UPLOAD_ERR_XXX constants.
82
-     *
83
-     * If the file was uploaded successfully, this method MUST return
84
-     * UPLOAD_ERR_OK.
85
-     *
86
-     * Implementations SHOULD return the value stored in the "error" key of
87
-     * the file in the $_FILES array.
88
-     *
89
-     * @see http://php.net/manual/en/features.file-upload.errors.php
90
-     * @return int One of PHP's UPLOAD_ERR_XXX constants.
91
-     */
92
-    public function getError();
93
-    
94
-    /**
95
-     * Retrieve the filename sent by the client.
96
-     *
97
-     * Do not trust the value returned by this method. A client could send
98
-     * a malicious filename with the intention to corrupt or hack your
99
-     * application.
100
-     *
101
-     * Implementations SHOULD return the value stored in the "name" key of
102
-     * the file in the $_FILES array.
103
-     *
104
-     * @return string|null The filename sent by the client or null if none
105
-     *     was provided.
106
-     */
107
-    public function getClientFilename();
108
-    
109
-    /**
110
-     * Retrieve the media type sent by the client.
111
-     *
112
-     * Do not trust the value returned by this method. A client could send
113
-     * a malicious media type with the intention to corrupt or hack your
114
-     * application.
115
-     *
116
-     * Implementations SHOULD return the value stored in the "type" key of
117
-     * the file in the $_FILES array.
118
-     *
119
-     * @return string|null The media type sent by the client or null if none
120
-     *     was provided.
121
-     */
122
-    public function getClientMediaType();
123
-}

+ 0
- 17
src/Psr/Http/Message/UriFactoryInterface.php View File

@@ -1,17 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Message;
4
-
5
-interface UriFactoryInterface
6
-{
7
-    /**
8
-     * Create a new URI.
9
-     *
10
-     * @param string $uri
11
-     *
12
-     * @return UriInterface
13
-     *
14
-     * @throws \InvalidArgumentException If the given URI cannot be parsed.
15
-     */
16
-    public function createUri(string $uri = ''): UriInterface;
17
-}

+ 0
- 323
src/Psr/Http/Message/UriInterface.php View File

@@ -1,323 +0,0 @@
1
-<?php
2
-namespace Psr\Http\Message;
3
-
4
-/**
5
- * Value object representing a URI.
6
- *
7
- * This interface is meant to represent URIs according to RFC 3986 and to
8
- * provide methods for most common operations. Additional functionality for
9
- * working with URIs can be provided on top of the interface or externally.
10
- * Its primary use is for HTTP requests, but may also be used in other
11
- * contexts.
12
- *
13
- * Instances of this interface are considered immutable; all methods that
14
- * might change state MUST be implemented such that they retain the internal
15
- * state of the current instance and return an instance that contains the
16
- * changed state.
17
- *
18
- * Typically the Host header will be also be present in the request message.
19
- * For server-side requests, the scheme will typically be discoverable in the
20
- * server parameters.
21
- *
22
- * @link http://tools.ietf.org/html/rfc3986 (the URI specification)
23
- */
24
-interface UriInterface
25
-{
26
-    /**
27
-     * Retrieve the scheme component of the URI.
28
-     *
29
-     * If no scheme is present, this method MUST return an empty string.
30
-     *
31
-     * The value returned MUST be normalized to lowercase, per RFC 3986
32
-     * Section 3.1.
33
-     *
34
-     * The trailing ":" character is not part of the scheme and MUST NOT be
35
-     * added.
36
-     *
37
-     * @see https://tools.ietf.org/html/rfc3986#section-3.1
38
-     * @return string The URI scheme.
39
-     */
40
-    public function getScheme();
41
-
42
-    /**
43
-     * Retrieve the authority component of the URI.
44
-     *
45
-     * If no authority information is present, this method MUST return an empty
46
-     * string.
47
-     *
48
-     * The authority syntax of the URI is:
49
-     *
50
-     * <pre>
51
-     * [user-info@]host[:port]
52
-     * </pre>
53
-     *
54
-     * If the port component is not set or is the standard port for the current
55
-     * scheme, it SHOULD NOT be included.
56
-     *
57
-     * @see https://tools.ietf.org/html/rfc3986#section-3.2
58
-     * @return string The URI authority, in "[user-info@]host[:port]" format.
59
-     */
60
-    public function getAuthority();
61
-
62
-    /**
63
-     * Retrieve the user information component of the URI.
64
-     *
65
-     * If no user information is present, this method MUST return an empty
66
-     * string.
67
-     *
68
-     * If a user is present in the URI, this will return that value;
69
-     * additionally, if the password is also present, it will be appended to the
70
-     * user value, with a colon (":") separating the values.
71
-     *
72
-     * The trailing "@" character is not part of the user information and MUST
73
-     * NOT be added.
74
-     *
75
-     * @return string The URI user information, in "username[:password]" format.
76
-     */
77
-    public function getUserInfo();
78
-
79
-    /**
80
-     * Retrieve the host component of the URI.
81
-     *
82
-     * If no host is present, this method MUST return an empty string.
83
-     *
84
-     * The value returned MUST be normalized to lowercase, per RFC 3986
85
-     * Section 3.2.2.
86
-     *
87
-     * @see http://tools.ietf.org/html/rfc3986#section-3.2.2
88
-     * @return string The URI host.
89
-     */
90
-    public function getHost();
91
-
92
-    /**
93
-     * Retrieve the port component of the URI.
94
-     *
95
-     * If a port is present, and it is non-standard for the current scheme,
96
-     * this method MUST return it as an integer. If the port is the standard port
97
-     * used with the current scheme, this method SHOULD return null.
98
-     *
99
-     * If no port is present, and no scheme is present, this method MUST return
100
-     * a null value.
101
-     *
102
-     * If no port is present, but a scheme is present, this method MAY return
103
-     * the standard port for that scheme, but SHOULD return null.
104
-     *
105
-     * @return null|int The URI port.
106
-     */
107
-    public function getPort();
108
-
109
-    /**
110
-     * Retrieve the path component of the URI.
111
-     *
112
-     * The path can either be empty or absolute (starting with a slash) or
113
-     * rootless (not starting with a slash). Implementations MUST support all
114
-     * three syntaxes.
115
-     *
116
-     * Normally, the empty path "" and absolute path "/" are considered equal as
117
-     * defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
118
-     * do this normalization because in contexts with a trimmed base path, e.g.
119
-     * the front controller, this difference becomes significant. It's the task
120
-     * of the user to handle both "" and "/".
121
-     *
122
-     * The value returned MUST be percent-encoded, but MUST NOT double-encode
123
-     * any characters. To determine what characters to encode, please refer to
124
-     * RFC 3986, Sections 2 and 3.3.
125
-     *
126
-     * As an example, if the value should include a slash ("/") not intended as
127
-     * delimiter between path segments, that value MUST be passed in encoded
128
-     * form (e.g., "%2F") to the instance.
129
-     *
130
-     * @see https://tools.ietf.org/html/rfc3986#section-2
131
-     * @see https://tools.ietf.org/html/rfc3986#section-3.3
132
-     * @return string The URI path.
133
-     */
134
-    public function getPath();
135
-
136
-    /**
137
-     * Retrieve the query string of the URI.
138
-     *
139
-     * If no query string is present, this method MUST return an empty string.
140
-     *
141
-     * The leading "?" character is not part of the query and MUST NOT be
142
-     * added.
143
-     *
144
-     * The value returned MUST be percent-encoded, but MUST NOT double-encode
145
-     * any characters. To determine what characters to encode, please refer to
146
-     * RFC 3986, Sections 2 and 3.4.
147
-     *
148
-     * As an example, if a value in a key/value pair of the query string should
149
-     * include an ampersand ("&") not intended as a delimiter between values,
150
-     * that value MUST be passed in encoded form (e.g., "%26") to the instance.
151
-     *
152
-     * @see https://tools.ietf.org/html/rfc3986#section-2
153
-     * @see https://tools.ietf.org/html/rfc3986#section-3.4
154
-     * @return string The URI query string.
155
-     */
156
-    public function getQuery();
157
-
158
-    /**
159
-     * Retrieve the fragment component of the URI.
160
-     *
161
-     * If no fragment is present, this method MUST return an empty string.
162
-     *
163
-     * The leading "#" character is not part of the fragment and MUST NOT be
164
-     * added.
165
-     *
166
-     * The value returned MUST be percent-encoded, but MUST NOT double-encode
167
-     * any characters. To determine what characters to encode, please refer to
168
-     * RFC 3986, Sections 2 and 3.5.
169
-     *
170
-     * @see https://tools.ietf.org/html/rfc3986#section-2
171
-     * @see https://tools.ietf.org/html/rfc3986#section-3.5
172
-     * @return string The URI fragment.
173
-     */
174
-    public function getFragment();
175
-
176
-    /**
177
-     * Return an instance with the specified scheme.
178
-     *
179
-     * This method MUST retain the state of the current instance, and return
180
-     * an instance that contains the specified scheme.
181
-     *
182
-     * Implementations MUST support the schemes "http" and "https" case
183
-     * insensitively, and MAY accommodate other schemes if required.
184
-     *
185
-     * An empty scheme is equivalent to removing the scheme.
186
-     *
187
-     * @param string $scheme The scheme to use with the new instance.
188
-     * @return static A new instance with the specified scheme.
189
-     * @throws \InvalidArgumentException for invalid or unsupported schemes.
190
-     */
191
-    public function withScheme($scheme);
192
-
193
-    /**
194
-     * Return an instance with the specified user information.
195
-     *
196
-     * This method MUST retain the state of the current instance, and return
197
-     * an instance that contains the specified user information.
198
-     *
199
-     * Password is optional, but the user information MUST include the
200
-     * user; an empty string for the user is equivalent to removing user
201
-     * information.
202
-     *
203
-     * @param string $user The user name to use for authority.
204
-     * @param null|string $password The password associated with $user.
205
-     * @return static A new instance with the specified user information.
206
-     */
207
-    public function withUserInfo($user, $password = null);
208
-
209
-    /**
210
-     * Return an instance with the specified host.
211
-     *
212
-     * This method MUST retain the state of the current instance, and return
213
-     * an instance that contains the specified host.
214
-     *
215
-     * An empty host value is equivalent to removing the host.
216
-     *
217
-     * @param string $host The hostname to use with the new instance.
218
-     * @return static A new instance with the specified host.
219
-     * @throws \InvalidArgumentException for invalid hostnames.
220
-     */
221
-    public function withHost($host);
222
-
223
-    /**
224
-     * Return an instance with the specified port.
225
-     *
226
-     * This method MUST retain the state of the current instance, and return
227
-     * an instance that contains the specified port.
228
-     *
229
-     * Implementations MUST raise an exception for ports outside the
230
-     * established TCP and UDP port ranges.
231
-     *
232
-     * A null value provided for the port is equivalent to removing the port
233
-     * information.
234
-     *
235
-     * @param null|int $port The port to use with the new instance; a null value
236
-     *     removes the port information.
237
-     * @return static A new instance with the specified port.
238
-     * @throws \InvalidArgumentException for invalid ports.
239
-     */
240
-    public function withPort($port);
241
-
242
-    /**
243
-     * Return an instance with the specified path.
244
-     *
245
-     * This method MUST retain the state of the current instance, and return
246
-     * an instance that contains the specified path.
247
-     *
248
-     * The path can either be empty or absolute (starting with a slash) or
249
-     * rootless (not starting with a slash). Implementations MUST support all
250
-     * three syntaxes.
251
-     *
252
-     * If the path is intended to be domain-relative rather than path relative then
253
-     * it must begin with a slash ("/"). Paths not starting with a slash ("/")
254
-     * are assumed to be relative to some base path known to the application or
255
-     * consumer.
256
-     *
257
-     * Users can provide both encoded and decoded path characters.
258
-     * Implementations ensure the correct encoding as outlined in getPath().
259
-     *
260
-     * @param string $path The path to use with the new instance.
261
-     * @return static A new instance with the specified path.
262
-     * @throws \InvalidArgumentException for invalid paths.
263
-     */
264
-    public function withPath($path);
265
-
266
-    /**
267
-     * Return an instance with the specified query string.
268
-     *
269
-     * This method MUST retain the state of the current instance, and return
270
-     * an instance that contains the specified query string.
271
-     *
272
-     * Users can provide both encoded and decoded query characters.
273
-     * Implementations ensure the correct encoding as outlined in getQuery().
274
-     *
275
-     * An empty query string value is equivalent to removing the query string.
276
-     *
277
-     * @param string $query The query string to use with the new instance.
278
-     * @return static A new instance with the specified query string.
279
-     * @throws \InvalidArgumentException for invalid query strings.
280
-     */
281
-    public function withQuery($query);
282
-
283
-    /**
284
-     * Return an instance with the specified URI fragment.
285
-     *
286
-     * This method MUST retain the state of the current instance, and return
287
-     * an instance that contains the specified URI fragment.
288
-     *
289
-     * Users can provide both encoded and decoded fragment characters.
290
-     * Implementations ensure the correct encoding as outlined in getFragment().
291
-     *
292
-     * An empty fragment value is equivalent to removing the fragment.
293
-     *
294
-     * @param string $fragment The fragment to use with the new instance.
295
-     * @return static A new instance with the specified fragment.
296
-     */
297
-    public function withFragment($fragment);
298
-
299
-    /**
300
-     * Return the string representation as a URI reference.
301
-     *
302
-     * Depending on which components of the URI are present, the resulting
303
-     * string is either a full URI or relative reference according to RFC 3986,
304
-     * Section 4.1. The method concatenates the various components of the URI,
305
-     * using the appropriate delimiters:
306
-     *
307
-     * - If a scheme is present, it MUST be suffixed by ":".
308
-     * - If an authority is present, it MUST be prefixed by "//".
309
-     * - The path can be concatenated without delimiters. But there are two
310
-     *   cases where the path has to be adjusted to make the URI reference
311
-     *   valid as PHP does not allow to throw an exception in __toString():
312
-     *     - If the path is rootless and an authority is present, the path MUST
313
-     *       be prefixed by "/".
314
-     *     - If the path is starting with more than one "/" and no authority is
315
-     *       present, the starting slashes MUST be reduced to one.
316
-     * - If a query is present, it MUST be prefixed by "?".
317
-     * - If a fragment is present, it MUST be prefixed by "#".
318
-     *
319
-     * @see http://tools.ietf.org/html/rfc3986#section-4.1
320
-     * @return string
321
-     */
322
-    public function __toString();
323
-}

+ 0
- 25
src/Psr/Http/Server/MiddlewareInterface.php View File

@@ -1,25 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Server;
4
-
5
-use Psr\Http\Message\ResponseInterface;
6
-use Psr\Http\Message\ServerRequestInterface;
7
-
8
-/**
9
- * Participant in processing a server request and response.
10
- *
11
- * An HTTP middleware component participates in processing an HTTP message:
12
- * by acting on the request, generating the response, or forwarding the
13
- * request to a subsequent middleware and possibly acting on its response.
14
- */
15
-interface MiddlewareInterface
16
-{
17
-    /**
18
-     * Process an incoming server request.
19
-     *
20
-     * Processes an incoming server request in order to produce a response.
21
-     * If unable to produce the response itself, it may delegate to the provided
22
-     * request handler to do so.
23
-     */
24
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
25
-}

+ 0
- 22
src/Psr/Http/Server/RequestHandlerInterface.php View File

@@ -1,22 +0,0 @@
1
-<?php
2
-
3
-namespace Psr\Http\Server;
4
-
5
-use Psr\Http\Message\ResponseInterface;
6
-use Psr\Http\Message\ServerRequestInterface;
7
-
8
-/**
9
- * Handles a server request and produces a response.
10
- *
11
- * An HTTP request handler process an HTTP request in order to produce an
12
- * HTTP response.
13
- */
14
-interface RequestHandlerInterface
15
-{
16
-    /**
17
-     * Handles a request and produces a response.
18
-     *
19
-     * May call other collaborating code to generate the response.
20
-     */
21
-    public function handle(ServerRequestInterface $request): ResponseInterface;
22
-}

+ 0
- 21
src/Psr/LICENSE View File

@@ -1,21 +0,0 @@
1
-MIT License
2
-
3
-Copyright (c) 2018 PHP-FIG
4
-
5
-Permission is hereby granted, free of charge, to any person obtaining a copy
6
-of this software and associated documentation files (the "Software"), to deal
7
-in the Software without restriction, including without limitation the rights
8
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
-copies of the Software, and to permit persons to whom the Software is
10
-furnished to do so, subject to the following conditions:
11
-
12
-The above copyright notice and this permission notice shall be included in all
13
-copies or substantial portions of the Software.
14
-
15
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
-SOFTWARE.

Loading…
Cancel
Save