Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc0a26bc

Browse files
committed
[HttpFoundation] Deprecate extending some methods
1 parent2bc54e0 commitc0a26bc

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

‎UPGRADE-3.2.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ FrameworkBundle
4141
* The service`serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now
4242
be automatically used when available.
4343

44+
HttpFoundation
45+
---------------
46+
47+
* Extending the following methods of`Response`
48+
is deprecated (these methods will be`final` in 4.0):
49+
50+
-`setDate`/`getDate`
51+
-`setExpires`/`getExpires`
52+
-`setLastModified`/`getLastModified`
53+
-`setProtocolVersion`/`getProtocolVersion`
54+
-`setStatusCode`/`getStatusCode`
55+
-`setCharset`/`getCharset`
56+
-`setPrivate`/`setPublic`
57+
-`getAge`
58+
-`getMaxAge`/`setMaxAge`
59+
-`setSharedMaxAge`
60+
-`getTtl`/`setTtl`
61+
-`setClientTtl`
62+
-`getEtag`/`setEtag`
63+
-`hasVary`/`getVary`/`setVary`
64+
-`isInvalid`/`isSuccessful`/`isRedirection`/`isClientError`/`isServerError`
65+
-`isOk`/`isForbidden`/`isNotFound`/`isRedirect`/`isEmpty`
66+
4467
Validator
4568
---------
4669

‎UPGRADE-4.0.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,29 @@ FrameworkBundle
121121
* The`Controller::getUser()` method has been removed in favor of the ability
122122
to typehint the security user object in the action.
123123

124+
HttpFoundation
125+
---------------
126+
127+
* Extending the following methods of`Response`
128+
is no longer possible (these methods are now`final`):
129+
130+
-`setDate`/`getDate`
131+
-`setExpires`/`getExpires`
132+
-`setLastModified`/`getLastModified`
133+
-`setProtocolVersion`/`getProtocolVersion`
134+
-`setStatusCode`/`getStatusCode`
135+
-`setCharset`/`getCharset`
136+
-`setPrivate`/`setPublic`
137+
-`getAge`
138+
-`getMaxAge`/`setMaxAge`
139+
-`setSharedMaxAge`
140+
-`getTtl`/`setTtl`
141+
-`setClientTtl`
142+
-`getEtag`/`setEtag`
143+
-`hasVary`/`getVary`/`setVary`
144+
-`isInvalid`/`isSuccessful`/`isRedirection`/`isClientError`/`isServerError`
145+
-`isOk`/`isForbidden`/`isNotFound`/`isRedirect`/`isEmpty`
146+
124147
HttpKernel
125148
----------
126149

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

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

189+
privatestatic$deprecatedMethods =array(
190+
'setDate','getDate',
191+
'setExpires','getExpires',
192+
'setLastModified','getLastModified',
193+
'setProtocolVersion','getProtocolVersion',
194+
'setStatusCode','getStatusCode',
195+
'setCharset','getCharset',
196+
'setPrivate','setPublic',
197+
'getAge','getMaxAge','setMaxAge','setSharedMaxAge',
198+
'getTtl','setTtl','setClientTtl',
199+
'getEtag','setEtag',
200+
'hasVary','getVary','setVary',
201+
'isInvalid','isSuccessful','isRedirection',
202+
'isClientError','isOk','isForbidden',
203+
'isNotFound','isRedirect','isEmpty',
204+
);
205+
privatestatic$deprecationsTriggered =array(
206+
__CLASS__ =>true,
207+
BinaryFileResponse::class =>true,
208+
JsonResponse::class =>true,
209+
RedirectResponse::class =>true,
210+
StreamedResponse::class =>true,
211+
);
212+
189213
/**
190214
* Constructor.
191215
*
@@ -201,6 +225,23 @@ public function __construct($content = '', $status = 200, $headers = array())
201225
$this->setContent($content);
202226
$this->setStatusCode($status);
203227
$this->setProtocolVersion('1.0');
228+
229+
// Deprecations
230+
$class =get_class($this);
231+
if ($thisinstanceof \PHPUnit_Framework_MockObject_MockObject ||$thisinstanceof \Prophecy\Doubler\DoubleInterface) {
232+
$class =get_parent_class($class);
233+
}
234+
if (isset(self::$deprecationsTriggered[$class])) {
235+
return;
236+
}
237+
238+
self::$deprecationsTriggered[$class] =true;
239+
foreach (self::$deprecatedMethodsas$method) {
240+
$r =new \ReflectionMethod($class,$method);
241+
if (__CLASS__ !==$r->getDeclaringClass()->getName()) {
242+
@trigger_error(sprintf('Extending %s::%s() in %s is deprecated since version 3.2 and won\'t be supported anymore in 4.0 as it will be final.',__CLASS__,$method,$class),E_USER_DEPRECATED);
243+
}
244+
}
204245
}
205246

206247
/**

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespaceSymfony\Component\HttpFoundation\Tests;
1313

14+
useResponse\DefaultResponse;
15+
useResponse\ExtendedResponse;
16+
useSymfony\Bridge\PhpUnit\ErrorAssert;
1417
useSymfony\Component\HttpFoundation\Request;
1518
useSymfony\Component\HttpFoundation\Response;
1619

@@ -843,6 +846,34 @@ public function testSettersAreChainable()
843846
}
844847
}
845848

849+
/**
850+
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
851+
*/
852+
publicfunctiontestNoDeprecations()
853+
{
854+
ErrorAssert::assertDeprecationsAreTriggered(array(),function () {
855+
newDefaultResponse();
856+
$this->getMock(Response::class);
857+
});
858+
}
859+
860+
/**
861+
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
862+
*/
863+
publicfunctiontestDeprecations()
864+
{
865+
$deprecationMessages =array();
866+
foreach (array('getDate','setLastModified')as$method) {
867+
$deprecationMessages[] =sprintf('Extending %s::%s() in Response\ExtendedResponse is deprecated', Response::class,$method);
868+
}
869+
ErrorAssert::assertDeprecationsAreTriggered($deprecationMessages,function () {
870+
newExtendedResponse();
871+
872+
// Deprecations should not be triggered twice
873+
newExtendedResponse();
874+
});
875+
}
876+
846877
publicfunctionvalidContentProvider()
847878
{
848879
returnarray(
@@ -891,3 +922,22 @@ public function __toString()
891922
return'Foo';
892923
}
893924
}
925+
926+
namespaceResponse;
927+
928+
useSymfony\Component\HttpFoundation\Response;
929+
930+
class DefaultResponseextends Response
931+
{
932+
}
933+
934+
class ExtendedResponseextends Response
935+
{
936+
publicfunctionsetLastModified(\DateTime$date =null)
937+
{
938+
}
939+
940+
publicfunctiongetDate()
941+
{
942+
}
943+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp