Skip to content

Commit d73c9aa

Browse files
committed
RequestFactory::createHttpRequest() renamed to fromGlobals()
To be consistent with future ResponseFactory::fromGlobals()
1 parent 4142c4b commit d73c9aa

22 files changed

+82
-74
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ And then we let the factory generate a new `httpRequest` and we store it in a sy
146146

147147
```php
148148
// $container is a system container
149-
$container->addService('httpRequest', $requestFactory->createHttpRequest());
149+
$container->addService('httpRequest', $requestFactory->fromGlobals());
150150
```
151151

152152

src/Bridges/HttpDI/HttpExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function loadConfiguration()
5656
->addSetup('setProxy', [$config->proxy]);
5757

5858
$builder->addDefinition($this->prefix('request'))
59-
->setFactory('@Nette\Http\RequestFactory::createHttpRequest');
59+
->setFactory('@Nette\Http\RequestFactory::fromGlobals');
6060

6161
$response = $builder->addDefinition($this->prefix('response'))
6262
->setFactory(Nette\Http\Response::class);

src/Http/RequestFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function setProxy($proxy)
6060
/**
6161
* Returns new Request instance, using values from superglobals.
6262
*/
63-
public function createHttpRequest(): Request
63+
public function fromGlobals(): Request
6464
{
6565
$url = new Url;
6666
$this->getServer($url);
@@ -345,4 +345,11 @@ private function useNonstandardProxy(Url $url, &$remoteAddr, &$remoteHost): void
345345
}
346346
}
347347
}
348+
349+
350+
/** @deprecated */
351+
public function createHttpRequest(): Request
352+
{
353+
return $this->fromGlobals();
354+
}
348355
}

tests/Http/Request.files.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ $_FILES = [
100100
];
101101

102102
$factory = new Http\RequestFactory;
103-
$request = $factory->createHttpRequest();
103+
$request = $factory->fromGlobals();
104104

105105
Assert::type(Nette\Http\FileUpload::class, $request->files['file1']);
106106
Assert::type(Nette\Http\FileUpload::class, $request->files['file2'][2]);

tests/Http/Request.files2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $_FILES = [
2525
];
2626

2727
$factory = new Http\RequestFactory;
28-
$request = $factory->createHttpRequest();
28+
$request = $factory->fromGlobals();
2929

3030
Assert::type('array', $request->files['files']);
3131
Assert::count(1, $request->files['files']);

tests/Http/Request.invalidEncoding.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $_FILES = [
6868
test(function () { // unfiltered data
6969
$factory = new Http\RequestFactory;
7070
$factory->setBinary();
71-
$request = $factory->createHttpRequest();
71+
$request = $factory->fromGlobals();
7272

7373
Assert::same($request->getQuery('invalid'), INVALID);
7474
Assert::same($request->getQuery('control'), CONTROL_CHARACTERS);
@@ -96,7 +96,7 @@ test(function () { // unfiltered data
9696

9797
test(function () { // filtered data
9898
$factory = new Http\RequestFactory;
99-
$request = $factory->createHttpRequest();
99+
$request = $factory->fromGlobals();
100100

101101
Assert::same('', $request->getQuery('invalid'));
102102
Assert::same('ABC', $request->getQuery('control'));

tests/Http/Request.request.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test(function () {
2828
$factory = new Http\RequestFactory;
2929
$factory->urlFilters['path'] = ['#%20#' => ''];
3030
$factory->urlFilters['url'] = ['#[.,)]\z#' => ''];
31-
$request = $factory->createHttpRequest();
31+
$request = $factory->fromGlobals();
3232

3333
Assert::same('GET', $request->getMethod());
3434
Assert::true($request->isSecured());
@@ -59,7 +59,7 @@ test(function () {
5959
$factory = new Http\RequestFactory;
6060
$factory->urlFilters['path'] = [];
6161
$factory->urlFilters['url'] = [];
62-
$request = $factory->createHttpRequest();
62+
$request = $factory->fromGlobals();
6363

6464
Assert::same('https', $request->getUrl()->scheme);
6565
Assert::same('', $request->getUrl()->user);

tests/Http/RequestFactory.host.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,39 @@ $_SERVER = [
1717
'HTTP_HOST' => 'localhost',
1818
];
1919
$factory = new RequestFactory;
20-
Assert::same('http://localhost/', (string) $factory->createHttpRequest()->getUrl());
20+
Assert::same('http://localhost/', (string) $factory->fromGlobals()->getUrl());
2121

2222

2323
$_SERVER = [
2424
'HTTP_HOST' => 'www-x.nette.org',
2525
];
2626
$factory = new RequestFactory;
27-
Assert::same('http://www-x.nette.org/', (string) $factory->createHttpRequest()->getUrl());
27+
Assert::same('http://www-x.nette.org/', (string) $factory->fromGlobals()->getUrl());
2828

2929

3030
$_SERVER = [
3131
'HTTP_HOST' => '192.168.0.1:8080',
3232
];
3333
$factory = new RequestFactory;
34-
Assert::same('http://192.168.0.1:8080/', (string) $factory->createHttpRequest()->getUrl());
34+
Assert::same('http://192.168.0.1:8080/', (string) $factory->fromGlobals()->getUrl());
3535

3636

3737
$_SERVER = [
3838
'HTTP_HOST' => '[::1aF]:8080',
3939
];
4040
$factory = new RequestFactory;
41-
Assert::same('http://[::1af]:8080/', (string) $factory->createHttpRequest()->getUrl());
41+
Assert::same('http://[::1af]:8080/', (string) $factory->fromGlobals()->getUrl());
4242

4343

4444
$_SERVER = [
4545
'HTTP_HOST' => "a.cz\n",
4646
];
4747
$factory = new RequestFactory;
48-
Assert::same('http:/', (string) $factory->createHttpRequest()->getUrl());
48+
Assert::same('http:/', (string) $factory->fromGlobals()->getUrl());
4949

5050

5151
$_SERVER = [
5252
'HTTP_HOST' => 'AB',
5353
];
5454
$factory = new RequestFactory;
55-
Assert::same('http://ab/', (string) $factory->createHttpRequest()->getUrl());
55+
Assert::same('http://ab/', (string) $factory->fromGlobals()->getUrl());

tests/Http/RequestFactory.method.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ $_SERVER = [
1818
'HTTP_X_HTTP_METHOD_OVERRIDE' => 'PATCH',
1919
];
2020
$factory = new RequestFactory;
21-
Assert::same('GET', $factory->createHttpRequest()->getMethod());
21+
Assert::same('GET', $factory->fromGlobals()->getMethod());
2222

2323

2424
$_SERVER = [
2525
'REQUEST_METHOD' => 'POST',
2626
'HTTP_X_HTTP_METHOD_OVERRIDE' => 'PATCH',
2727
];
2828
$factory = new RequestFactory;
29-
Assert::same('PATCH', $factory->createHttpRequest()->getMethod());
29+
Assert::same('PATCH', $factory->fromGlobals()->getMethod());
3030

3131

3232
$_SERVER = [
3333
'REQUEST_METHOD' => 'POST',
3434
'HTTP_X_HTTP_METHOD_OVERRIDE' => ' *',
3535
];
3636
$factory = new RequestFactory;
37-
Assert::same('POST', $factory->createHttpRequest()->getMethod());
37+
Assert::same('POST', $factory->fromGlobals()->getMethod());

tests/Http/RequestFactory.port.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RequestFactoryPortTest extends Tester\TestCase
2020
$_SERVER = $server;
2121

2222
$factory = new Nette\Http\RequestFactory;
23-
Assert::same($expectedPort, $factory->createHttpRequest()->getUrl()->getPort());
23+
Assert::same($expectedPort, $factory->fromGlobals()->getUrl()->getPort());
2424
}
2525

2626

@@ -61,7 +61,7 @@ class RequestFactoryPortTest extends Tester\TestCase
6161

6262
$factory = new Nette\Http\RequestFactory;
6363
$factory->setProxy(['10.0.0.1']);
64-
Assert::same($expectedPort, $factory->createHttpRequest()->getUrl()->getPort());
64+
Assert::same($expectedPort, $factory->fromGlobals()->getUrl()->getPort());
6565
}
6666

6767

0 commit comments

Comments
 (0)