Skip to content

Commit 75446eb

Browse files
committed
Rename master request to main request
1 parent 7365c36 commit 75446eb

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ CHANGELOG
88
* Calling `Request::getSession()` when there is no available session throws a `SessionNotFoundException`
99
* Add the `RequestStack::getSession` method
1010
* Deprecate the `NamespacedAttributeBag` class
11-
* added `ResponseFormatSame` PHPUnit constraint
11+
* Add `ResponseFormatSame` PHPUnit constraint
12+
* Deprecate the `RequestStack::getMasterRequest()` method and add `getMainRequest()` as replacement
1213

1314
5.2.0
1415
-----

RequestStack.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ public function getCurrentRequest()
6565
}
6666

6767
/**
68-
* Gets the master Request.
68+
* Gets the main request.
6969
*
70-
* Be warned that making your code aware of the master request
70+
* Be warned that making your code aware of the main request
7171
* might make it un-compatible with other features of your framework
7272
* like ESI support.
73-
*
74-
* @return Request|null
7573
*/
76-
public function getMasterRequest()
74+
public function getMainRequest(): ?Request
7775
{
7876
if (!$this->requests) {
7977
return null;
@@ -82,14 +80,28 @@ public function getMasterRequest()
8280
return $this->requests[0];
8381
}
8482

83+
/**
84+
* Gets the master request.
85+
*
86+
* @return Request|null
87+
*
88+
* @deprecated since symfony/http-foundation 5.3, use getMainRequest() instead
89+
*/
90+
public function getMasterRequest()
91+
{
92+
trigger_deprecation('symfony/http-foundation', '5.3', '"%s()" is deprecated, use "getMainRequest()" instead.', __METHOD__);
93+
94+
return $this->getMainRequest();
95+
}
96+
8597
/**
8698
* Returns the parent request of the current.
8799
*
88100
* Be warned that making your code aware of the parent request
89101
* might make it un-compatible with other features of your framework
90102
* like ESI support.
91103
*
92-
* If current Request is the master request, it returns null.
104+
* If current Request is the main request, it returns null.
93105
*
94106
* @return Request|null
95107
*/

Session/SessionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public function __construct(RequestStack $requestStack, SessionStorageFactoryInt
3535

3636
public function createSession(): SessionInterface
3737
{
38-
return new Session($this->storageFactory->createStorage($this->requestStack->getMasterRequest()), null, null, $this->usageReporter);
38+
return new Session($this->storageFactory->createStorage($this->requestStack->getMainRequest()), null, null, $this->usageReporter);
3939
}
4040
}

Tests/RequestStackTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
namespace Symfony\Component\HttpFoundation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\RequestStack;
1718

1819
class RequestStackTest extends TestCase
1920
{
21+
use ExpectDeprecationTrait;
22+
2023
public function testGetCurrentRequest()
2124
{
2225
$requestStack = new RequestStack();
@@ -33,6 +36,23 @@ public function testGetCurrentRequest()
3336
$this->assertNull($requestStack->pop());
3437
}
3538

39+
public function testGetMainRequest()
40+
{
41+
$requestStack = new RequestStack();
42+
$this->assertNull($requestStack->getMainRequest());
43+
44+
$mainRequest = Request::create('/foo');
45+
$subRequest = Request::create('/bar');
46+
47+
$requestStack->push($mainRequest);
48+
$requestStack->push($subRequest);
49+
50+
$this->assertSame($mainRequest, $requestStack->getMainRequest());
51+
}
52+
53+
/**
54+
* @group legacy
55+
*/
3656
public function testGetMasterRequest()
3757
{
3858
$requestStack = new RequestStack();
@@ -44,6 +64,7 @@ public function testGetMasterRequest()
4464
$requestStack->push($masterRequest);
4565
$requestStack->push($subRequest);
4666

67+
$this->expectDeprecation('Since symfony/http-foundation 5.3: "Symfony\Component\HttpFoundation\RequestStack::getMasterRequest()" is deprecated, use "getMainRequest()" instead.');
4768
$this->assertSame($masterRequest, $requestStack->getMasterRequest());
4869
}
4970

@@ -52,15 +73,15 @@ public function testGetParentRequest()
5273
$requestStack = new RequestStack();
5374
$this->assertNull($requestStack->getParentRequest());
5475

55-
$masterRequest = Request::create('/foo');
76+
$mainRequest = Request::create('/foo');
5677

57-
$requestStack->push($masterRequest);
78+
$requestStack->push($mainRequest);
5879
$this->assertNull($requestStack->getParentRequest());
5980

6081
$firstSubRequest = Request::create('/bar');
6182

6283
$requestStack->push($firstSubRequest);
63-
$this->assertSame($masterRequest, $requestStack->getParentRequest());
84+
$this->assertSame($mainRequest, $requestStack->getParentRequest());
6485

6586
$secondSubRequest = Request::create('/baz');
6687

UrlHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getAbsoluteUrl(string $path): string
3535
return $path;
3636
}
3737

38-
if (null === $request = $this->requestStack->getMasterRequest()) {
38+
if (null === $request = $this->requestStack->getMainRequest()) {
3939
return $this->getAbsoluteUrlFromContext($path);
4040
}
4141

@@ -64,7 +64,7 @@ public function getRelativePath(string $path): string
6464
return $path;
6565
}
6666

67-
if (null === $request = $this->requestStack->getMasterRequest()) {
67+
if (null === $request = $this->requestStack->getMainRequest()) {
6868
return $path;
6969
}
7070

0 commit comments

Comments
 (0)