Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db949ec

Browse filesBrowse files
committed
Deprecate *Response::create() methods
1 parent e0f6cdb commit db949ec
Copy full SHA for db949ec

11 files changed

+77
-4
lines changed

‎UPGRADE-5.1.md

Copy file name to clipboardExpand all lines: UPGRADE-5.1.md
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ FrameworkBundle
77
* Marked `MicroKernelTrait::configureRoutes()` as `@internal` and `@final`.
88
* Deprecated not overriding `MicroKernelTrait::configureRouting()`.
99

10+
HttpFoundation
11+
--------------
12+
13+
* Deprecate `Response::create()`, `JsonResponse::create()`,
14+
`RedirectResponse::create()`, and `StreamedResponse::create()` methods (use
15+
`__construct()` instead)
16+
1017
Routing
1118
-------
1219

‎UPGRADE-6.0.md

Copy file name to clipboardExpand all lines: UPGRADE-6.0.md
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ FrameworkBundle
77
* Removed `MicroKernelTrait::configureRoutes()`.
88
* Made `MicroKernelTrait::configureRouting()` abstract.
99

10+
HttpFoundation
11+
--------------
12+
13+
* Removed `Response::create()`, `JsonResponse::create()`,
14+
`RedirectResponse::create()`, and `StreamedResponse::create()` methods (use
15+
`__construct()` instead)
16+
1017
Routing
1118
-------
1219

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/CHANGELOG.md
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
5.1.0
5+
-----
6+
7+
* Deprecate `Response::create()`, `JsonResponse::create()`,
8+
`RedirectResponse::create()`, and `StreamedResponse::create()` methods (use
9+
`__construct()` instead)
10+
411
5.0.0
512
-----
613

‎src/Symfony/Component/HttpFoundation/JsonResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/JsonResponse.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ public function __construct($data = null, int $status = 200, array $headers = []
6363
* @param array $headers An array of response headers
6464
*
6565
* @return static
66+
*
67+
* @deprecated since Symfony 5.1, use __construct() instead.
6668
*/
6769
public static function create($data = null, int $status = 200, array $headers = [])
6870
{
71+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 5.1; use __construct() instead.', __METHOD__), E_USER_DEPRECATED);
72+
6973
return new static($data, $status, $headers);
7074
}
7175

‎src/Symfony/Component/HttpFoundation/RedirectResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/RedirectResponse.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ public function __construct(string $url, int $status = 302, array $headers = [])
5353
* @param string $url The URL to redirect to
5454
*
5555
* @return static
56+
*
57+
* @deprecated since Symfony 5.1, use __construct() instead.
5658
*/
5759
public static function create($url = '', int $status = 302, array $headers = [])
5860
{
61+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 5.1; use __construct() instead.', __METHOD__), E_USER_DEPRECATED);
62+
5963
return new static($url, $status, $headers);
6064
}
6165

‎src/Symfony/Component/HttpFoundation/Response.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Response.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ public function __construct(?string $content = '', int $status = 200, array $hea
208208
* ->setSharedMaxAge(300);
209209
*
210210
* @return static
211+
*
212+
* @deprecated since Symfony 5.1, use __construct() instead.
211213
*/
212214
public static function create(?string $content = '', int $status = 200, array $headers = [])
213215
{
216+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 5.1; use __construct() instead.', __METHOD__), E_USER_DEPRECATED);
217+
214218
return new static($content, $status, $headers);
215219
}
216220

‎src/Symfony/Component/HttpFoundation/StreamedResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/StreamedResponse.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ public function __construct(callable $callback = null, int $status = 200, array
4747
* @param callable|null $callback A valid PHP callback or null to set it later
4848
*
4949
* @return static
50+
*
51+
* @deprecated since Symfony 5.1, use __construct() instead.
5052
*/
5153
public static function create($callback = null, int $status = 200, array $headers = [])
5254
{
55+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 5.1; use __construct() instead.', __METHOD__), E_USER_DEPRECATED);
56+
5357
return new static($callback, $status, $headers);
5458
}
5559

‎src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php
+31-4Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public function testSetJson()
9090
$this->assertEquals('true', $response->getContent());
9191
}
9292

93+
/**
94+
* @group legacy
95+
*/
9396
public function testCreate()
9497
{
9598
$response = JsonResponse::create(['foo' => 'bar'], 204);
@@ -99,27 +102,39 @@ public function testCreate()
99102
$this->assertEquals(204, $response->getStatusCode());
100103
}
101104

105+
/**
106+
* @group legacy
107+
*/
102108
public function testStaticCreateEmptyJsonObject()
103109
{
104110
$response = JsonResponse::create();
105111
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
106112
$this->assertSame('{}', $response->getContent());
107113
}
108114

115+
/**
116+
* @group legacy
117+
*/
109118
public function testStaticCreateJsonArray()
110119
{
111120
$response = JsonResponse::create([0, 1, 2, 3]);
112121
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
113122
$this->assertSame('[0,1,2,3]', $response->getContent());
114123
}
115124

125+
/**
126+
* @group legacy
127+
*/
116128
public function testStaticCreateJsonObject()
117129
{
118130
$response = JsonResponse::create(['foo' => 'bar']);
119131
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
120132
$this->assertSame('{"foo":"bar"}', $response->getContent());
121133
}
122134

135+
/**
136+
* @group legacy
137+
*/
123138
public function testStaticCreateWithSimpleTypes()
124139
{
125140
$response = JsonResponse::create('foo');
@@ -140,25 +155,37 @@ public function testStaticCreateWithSimpleTypes()
140155
$this->assertSame('true', $response->getContent());
141156
}
142157

158+
/**
159+
* @group legacy
160+
*/
143161
public function testStaticCreateWithCustomStatus()
144162
{
145163
$response = JsonResponse::create([], 202);
146164
$this->assertSame(202, $response->getStatusCode());
147165
}
148166

167+
/**
168+
* @group legacy
169+
*/
149170
public function testStaticCreateAddsContentTypeHeader()
150171
{
151172
$response = JsonResponse::create();
152173
$this->assertSame('application/json', $response->headers->get('Content-Type'));
153174
}
154175

176+
/**
177+
* @group legacy
178+
*/
155179
public function testStaticCreateWithCustomHeaders()
156180
{
157181
$response = JsonResponse::create([], 200, ['ETag' => 'foo']);
158182
$this->assertSame('application/json', $response->headers->get('Content-Type'));
159183
$this->assertSame('foo', $response->headers->get('ETag'));
160184
}
161185

186+
/**
187+
* @group legacy
188+
*/
162189
public function testStaticCreateWithCustomContentType()
163190
{
164191
$headers = ['Content-Type' => 'application/vnd.acme.blog-v1+json'];
@@ -169,7 +196,7 @@ public function testStaticCreateWithCustomContentType()
169196

170197
public function testSetCallback()
171198
{
172-
$response = JsonResponse::create(['foo' => 'bar'])->setCallback('callback');
199+
$response = (new JsonResponse(['foo' => 'bar']))->setCallback('callback');
173200

174201
$this->assertEquals('/**/callback({"foo":"bar"});', $response->getContent());
175202
$this->assertEquals('text/javascript', $response->headers->get('Content-Type'));
@@ -217,7 +244,7 @@ public function testSetCallbackInvalidIdentifier()
217244
public function testSetContent()
218245
{
219246
$this->expectException('InvalidArgumentException');
220-
JsonResponse::create("\xB1\x31");
247+
new JsonResponse("\xB1\x31");
221248
}
222249

223250
public function testSetContentJsonSerializeError()
@@ -230,12 +257,12 @@ public function testSetContentJsonSerializeError()
230257

231258
$serializable = new JsonSerializableObject();
232259

233-
JsonResponse::create($serializable);
260+
new JsonResponse($serializable);
234261
}
235262

236263
public function testSetComplexCallback()
237264
{
238-
$response = JsonResponse::create(['foo' => 'bar']);
265+
$response = new JsonResponse(['foo' => 'bar']);
239266
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
240267

241268
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());

‎src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function testSetTargetUrl()
5959
$this->assertEquals('baz.beep', $response->getTargetUrl());
6060
}
6161

62+
/**
63+
* @group legacy
64+
*/
6265
public function testCreate()
6366
{
6467
$response = RedirectResponse::create('foo', 301);

‎src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
class ResponseTest extends ResponseTestCase
2222
{
23+
/**
24+
* @group legacy
25+
*/
2326
public function testCreate()
2427
{
2528
$response = Response::create('foo', 301, ['Foo' => 'bar']);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public function testGetContent()
101101
$this->assertFalse($response->getContent());
102102
}
103103

104+
/**
105+
* @group legacy
106+
*/
104107
public function testCreate()
105108
{
106109
$response = StreamedResponse::create(function () {}, 204);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.