Skip to content

Commit 6ff757c

Browse files
committed
1 parent 248da06 commit 6ff757c

24 files changed

+125
-1811
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"ext-json":"*",
3232
"ext-simplexml":"*",
3333
"ext-zlib":"*",
34+
"chillerlan/php-http-message-utils": "^1.0",
3435
"chillerlan/php-settings-container":"^2.1",
3536
"fig/http-message-util":"^1.1.5",
3637
"psr/http-client":"^1.0",

src/Psr17/factory_helpers.php

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
namespace chillerlan\HTTP\Psr17;
1010

11-
use Psr\Http\Message\{
12-
ServerRequestFactoryInterface, ServerRequestInterface, StreamInterface, UriInterface, UriFactoryInterface
13-
};
14-
use chillerlan\HTTP\Psr7\{File, Stream};
11+
use Psr\Http\Message\StreamInterface;
12+
use chillerlan\HTTP\Psr7\Stream;
1513
use InvalidArgumentException;
1614

17-
use function explode, function_exists, getallheaders, is_scalar, method_exists, substr;
15+
use function is_scalar, method_exists;
1816

1917
const PSR17_INCLUDES = true;
2018

@@ -47,87 +45,6 @@
4745
'wb' => true,
4846
];
4947

50-
/**
51-
* Return a ServerRequest populated with superglobals:
52-
* $_GET
53-
* $_POST
54-
* $_COOKIE
55-
* $_FILES
56-
* $_SERVER
57-
*/
58-
function create_server_request_from_globals(
59-
ServerRequestFactoryInterface $serverRequestFactory,
60-
UriFactoryInterface $uriFactory
61-
):ServerRequestInterface{
62-
63-
$serverRequest = $serverRequestFactory->createServerRequest(
64-
$_SERVER['REQUEST_METHOD'] ?? 'GET',
65-
create_uri_from_globals($uriFactory),
66-
$_SERVER
67-
);
68-
69-
if(function_exists('getallheaders')){
70-
foreach(getallheaders() ?: [] as $name => $value){
71-
$serverRequest = $serverRequest->withHeader($name, $value);
72-
}
73-
}
74-
75-
return $serverRequest
76-
->withProtocolVersion(isset($_SERVER['SERVER_PROTOCOL']) ? substr($_SERVER['SERVER_PROTOCOL'], 5) : '1.1')
77-
->withCookieParams($_COOKIE)
78-
->withQueryParams($_GET)
79-
->withParsedBody($_POST)
80-
->withUploadedFiles(File::normalize($_FILES))
81-
;
82-
}
83-
84-
/**
85-
* Create a Uri populated with values from $_SERVER.
86-
*/
87-
function create_uri_from_globals(UriFactoryInterface $uriFactory):UriInterface{
88-
$hasPort = false;
89-
$hasQuery = false;
90-
91-
$uri = $uriFactory->createUri()
92-
->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http');
93-
94-
if(isset($_SERVER['HTTP_HOST'])){
95-
$hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']);
96-
$uri = $uri->withHost($hostHeaderParts[0]);
97-
98-
if(isset($hostHeaderParts[1])){
99-
$hasPort = true;
100-
$uri = $uri->withPort($hostHeaderParts[1]);
101-
}
102-
}
103-
elseif(isset($_SERVER['SERVER_NAME'])){
104-
$uri = $uri->withHost($_SERVER['SERVER_NAME']);
105-
}
106-
elseif(isset($_SERVER['SERVER_ADDR'])){
107-
$uri = $uri->withHost($_SERVER['SERVER_ADDR']);
108-
}
109-
110-
if(!$hasPort && isset($_SERVER['SERVER_PORT'])){
111-
$uri = $uri->withPort($_SERVER['SERVER_PORT']);
112-
}
113-
114-
if(isset($_SERVER['REQUEST_URI'])){
115-
$requestUriParts = explode('?', $_SERVER['REQUEST_URI']);
116-
$uri = $uri->withPath($requestUriParts[0]);
117-
118-
if(isset($requestUriParts[1])){
119-
$hasQuery = true;
120-
$uri = $uri->withQuery($requestUriParts[1]);
121-
}
122-
}
123-
124-
if(!$hasQuery && isset($_SERVER['QUERY_STRING'])){
125-
$uri = $uri->withQuery($_SERVER['QUERY_STRING']);
126-
}
127-
128-
return $uri;
129-
}
130-
13148
/**
13249
* Create a new writable stream from a string.
13350
*

src/Psr18/LoggingClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
1818
use Throwable;
1919

20-
use function chillerlan\HTTP\Psr7\message_to_string;
20+
use function chillerlan\HTTP\Utils\message_to_string;
2121
use function get_class;
2222

2323
/**

src/Psr7/File.php

Lines changed: 0 additions & 206 deletions
This file was deleted.

0 commit comments

Comments
 (0)