Skip to content

Commit f76ff6e

Browse files
committed
Don't trigger deprecations twice
1 parent e4090a9 commit f76ff6e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ class Response
186186
511 => 'Network Authentication Required', // RFC6585
187187
);
188188

189+
private static $deprecatedMethods = array('setDate', 'setExpires', 'setLastModified', 'getDate', 'getExpires', 'getLastModified');
190+
private static $deprecationsTriggered = array(
191+
__CLASS__ => true,
192+
JsonResponse::class => true,
193+
RedirectResponse::class => true,
194+
StreamedResponse::class => true,
195+
);
196+
189197
/**
190198
* Constructor.
191199
*
@@ -204,11 +212,12 @@ public function __construct($content = '', $status = 200, $headers = array())
204212

205213
// Deprecations
206214
$class = get_class($this);
207-
if (__CLASS__ === $class || 0 === strpos($class, 'Symfony\\')) {
215+
if (isset(self::$deprecationsTriggered[$class])) {
208216
return;
209217
}
210218

211-
foreach (array('setDate', 'setExpires', 'setLastModified', 'getDate', 'getExpires', 'getLastModified') as $method) {
219+
self::$deprecationsTriggered[$class] = true;
220+
foreach (self::$deprecatedMethods as $method) {
212221
$m = new \ReflectionMethod($this, $method);
213222
if (__CLASS__ !== $m->getDeclaringClass()->getName()) {
214223
@trigger_error(sprintf('Extending %s::%s() is deprecated since version 3.2 and won\'t be supported anymore in 4.0 as it will be final.', __CLASS__, $method), E_USER_DEPRECATED);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ public function testDeprecations()
863863
{
864864
ErrorAssert::assertDeprecationsAreTriggered(array(sprintf('Extending %s::setLastModified() is deprecated', Response::class), sprintf('Extending %s::getDate() is deprecated', Response::class)), function () {
865865
new ExtendedResponse();
866+
867+
// Deprecations should not be triggered twice
868+
new ExtendedResponse();
866869
});
867870
}
868871

0 commit comments

Comments
 (0)