Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0ed0cb

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fixed typo [HttpCache] fix: do not cache OPTIONS request fixed CS Prevent infinite loop in PropertyMetadata
2 parents 7108c37 + f76e77f commit c0ed0cb

File tree

7 files changed

+69
-2
lines changed

7 files changed

+69
-2
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,16 @@ public function isMethodSafe()
14791479
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
14801480
}
14811481

1482+
/**
1483+
* Checks whether the method is cacheable or not.
1484+
*
1485+
* @return bool
1486+
*/
1487+
public function isMethodCacheable()
1488+
{
1489+
return in_array($this->getMethod(), array('GET', 'HEAD'));
1490+
}
1491+
14821492
/**
14831493
* Returns the request body content.
14841494
*

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,32 @@ public function methodSafeProvider()
19481948
array('CONNECT', false),
19491949
);
19501950
}
1951+
1952+
/**
1953+
* @dataProvider methodCacheableProvider
1954+
*/
1955+
public function testMethodCacheable($method, $chacheable)
1956+
{
1957+
$request = new Request();
1958+
$request->setMethod($method);
1959+
$this->assertEquals($chacheable, $request->isMethodCacheable());
1960+
}
1961+
1962+
public function methodCacheableProvider()
1963+
{
1964+
return array(
1965+
array('HEAD', true),
1966+
array('GET', true),
1967+
array('POST', false),
1968+
array('PUT', false),
1969+
array('PATCH', false),
1970+
array('DELETE', false),
1971+
array('PURGE', false),
1972+
array('OPTIONS', false),
1973+
array('TRACE', false),
1974+
array('CONNECT', false),
1975+
);
1976+
}
19511977
}
19521978

19531979
class RequestContentProxy extends Request

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
204204

205205
if (!$request->isMethodSafe()) {
206206
$response = $this->invalidate($request, $catch);
207-
} elseif ($request->headers->has('expect')) {
207+
} elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
208208
$response = $this->pass($request, $catch);
209209
} else {
210210
$response = $this->lookup($request, $catch);

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,21 @@ public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
12641264
$this->assertNull($this->response->getETag());
12651265
$this->assertNull($this->response->getLastModified());
12661266
}
1267+
1268+
public function testDoesNotCacheOptionsRequest()
1269+
{
1270+
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'get');
1271+
$this->request('GET', '/');
1272+
$this->assertHttpKernelIsCalled();
1273+
1274+
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'options');
1275+
$this->request('OPTIONS', '/');
1276+
$this->assertHttpKernelIsCalled();
1277+
1278+
$this->request('GET', '/');
1279+
$this->assertHttpKernelIsNotCalled();
1280+
$this->assertSame('get', $this->response->getContent());
1281+
}
12671282
}
12681283

12691284
class TestKernel implements HttpKernelInterface

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.3.9",
2020
"symfony/event-dispatcher": "~2.6,>=2.6.7|~3.0.0",
21-
"symfony/http-foundation": "~2.7.15|~2.8.8|~3.0.8",
21+
"symfony/http-foundation": "~2.7.20|~2.8.13|~3.0.8",
2222
"symfony/debug": "~2.6,>=2.6.2",
2323
"psr/log": "~1.0"
2424
},

src/Symfony/Component/Validator/Mapping/PropertyMetadata.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ public function getPropertyValue($object)
5858
*/
5959
protected function newReflectionMember($objectOrClassName)
6060
{
61+
$originalClass = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);
62+
6163
while (!property_exists($objectOrClassName, $this->getName())) {
6264
$objectOrClassName = get_parent_class($objectOrClassName);
65+
66+
if (false === $objectOrClassName) {
67+
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s".', $this->getName(), $originalClass));
68+
}
6369
}
6470

6571
$member = new \ReflectionProperty($objectOrClassName, $this->getName());

src/Symfony/Component/Validator/Tests/Mapping/PropertyMetadataTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ public function testGetPropertyValueFromOverriddenPrivateProperty()
4242
$this->assertTrue($metadata->isPublic($entity));
4343
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
4444
}
45+
46+
public function testGetPropertyValueFromRemovedProperty()
47+
{
48+
$entity = new Entity('foobar');
49+
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
50+
$metadata->name = 'test';
51+
52+
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
53+
$metadata->getPropertyValue($entity);
54+
}
4555
}

0 commit comments

Comments
 (0)