Skip to content

Commit dd815e5

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

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Symfony/Component/HttpFoundation/Response.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ 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+
ApacheRequest::class => true,
193+
BinaryFileResponse::class => true,
194+
JsonResponse::class => true,
195+
RedirectResponse::class => true,
196+
StreamedResponse::class => true,
197+
);
198+
189199
/**
190200
* Constructor.
191201
*
@@ -204,11 +214,12 @@ public function __construct($content = '', $status = 200, $headers = array())
204214

205215
// Deprecations
206216
$class = get_class($this);
207-
if (__CLASS__ === $class || 0 === strpos($class, 'Symfony\\')) {
217+
if (isset(self::$deprecationsTriggered[$class])) {
208218
return;
209219
}
210220

211-
foreach (array('setDate', 'setExpires', 'setLastModified', 'getDate', 'getExpires', 'getLastModified') as $method) {
221+
self::$deprecationsTriggered[$class] = true;
222+
foreach (self::$deprecatedMethods as $method) {
212223
$m = new \ReflectionMethod($this, $method);
213224
if (__CLASS__ !== $m->getDeclaringClass()->getName()) {
214225
@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

+3
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)