Skip to content

Commit 8ca490b

Browse files
bug #24626 streamed response should return $this (DQNEO)
This PR was squashed before being merged into the 2.7 branch (closes #24626). Discussion ---------- streamed response should return $this | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | may be yes? | Deprecations? | no | Tests pass? | yes | License | MIT --- `sendHeaders()` and `sendContent()` should return $this, as in the parent class. related PRs: #2935 #20289 Commits ------- 058fb84 streamed response should return $this
2 parents 2fc9b57 + 058fb84 commit 8ca490b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Symfony/Component/HttpFoundation/StreamedResponse.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public function setCallback($callback)
8383
public function sendHeaders()
8484
{
8585
if ($this->headersSent) {
86-
return;
86+
return $this;
8787
}
8888

8989
$this->headersSent = true;
9090

91-
parent::sendHeaders();
91+
return parent::sendHeaders();
9292
}
9393

9494
/**
@@ -99,7 +99,7 @@ public function sendHeaders()
9999
public function sendContent()
100100
{
101101
if ($this->streamed) {
102-
return;
102+
return $this;
103103
}
104104

105105
$this->streamed = true;
@@ -109,6 +109,8 @@ public function sendContent()
109109
}
110110

111111
call_user_func($this->callback);
112+
113+
return $this;
112114
}
113115

114116
/**

src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,15 @@ public function testCreate()
121121
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
122122
$this->assertEquals(204, $response->getStatusCode());
123123
}
124+
125+
public function testReturnThis()
126+
{
127+
$response = new StreamedResponse(function () {});
128+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
129+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
130+
131+
$response = new StreamedResponse(function () {});
132+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
133+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
134+
}
124135
}

0 commit comments

Comments
 (0)