Merge branch '3.1'
* 3.1: fixed typo [HttpCache] fix: do not cache OPTIONS request fixed CS Prevent infinite loop in PropertyMetadata
This commit is contained in:
commit
ac3eb5d91f
@ -1492,6 +1492,16 @@ class Request
|
||||
return in_array($this->getMethod(), array('HEAD', 'GET', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'PURGE'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the method is cacheable or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMethodCacheable()
|
||||
{
|
||||
return in_array($this->getMethod(), array('GET', 'HEAD'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request body content.
|
||||
*
|
||||
|
@ -2013,6 +2013,32 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodCacheableProvider
|
||||
*/
|
||||
public function testMethodCacheable($method, $chacheable)
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setMethod($method);
|
||||
$this->assertEquals($chacheable, $request->isMethodCacheable());
|
||||
}
|
||||
|
||||
public function methodCacheableProvider()
|
||||
{
|
||||
return array(
|
||||
array('HEAD', true),
|
||||
array('GET', true),
|
||||
array('POST', false),
|
||||
array('PUT', false),
|
||||
array('PATCH', false),
|
||||
array('DELETE', false),
|
||||
array('PURGE', false),
|
||||
array('OPTIONS', false),
|
||||
array('TRACE', false),
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RequestContentProxy extends Request
|
||||
|
@ -184,7 +184,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
|
||||
if (!$request->isMethodSafe()) {
|
||||
$response = $this->invalidate($request, $catch);
|
||||
} elseif ($request->headers->has('expect')) {
|
||||
} elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
|
||||
$response = $this->pass($request, $catch);
|
||||
} else {
|
||||
$response = $this->lookup($request, $catch);
|
||||
|
@ -1261,6 +1261,21 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertNull($this->response->getETag());
|
||||
$this->assertNull($this->response->getLastModified());
|
||||
}
|
||||
|
||||
public function testDoesNotCacheOptionsRequest()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'get');
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'options');
|
||||
$this->request('OPTIONS', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertSame('get', $this->response->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
class TestKernel implements HttpKernelInterface
|
||||
|
@ -18,7 +18,7 @@
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"symfony/event-dispatcher": "~2.8|~3.0",
|
||||
"symfony/http-foundation": "~2.8.8|~3.0.8|~3.1.2|~3.2",
|
||||
"symfony/http-foundation": "~2.8.13|~3.0.8|~3.1.2|~3.2",
|
||||
"symfony/debug": "~2.8|~3.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
|
@ -58,8 +58,14 @@ class PropertyMetadata extends MemberMetadata
|
||||
*/
|
||||
protected function newReflectionMember($objectOrClassName)
|
||||
{
|
||||
$originalClass = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);
|
||||
|
||||
while (!property_exists($objectOrClassName, $this->getName())) {
|
||||
$objectOrClassName = get_parent_class($objectOrClassName);
|
||||
|
||||
if (false === $objectOrClassName) {
|
||||
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s".', $this->getName(), $originalClass));
|
||||
}
|
||||
}
|
||||
|
||||
$member = new \ReflectionProperty($objectOrClassName, $this->getName());
|
||||
|
@ -42,4 +42,14 @@ class PropertyMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($metadata->isPublic($entity));
|
||||
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromRemovedProperty()
|
||||
{
|
||||
$entity = new Entity('foobar');
|
||||
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
|
||||
$metadata->name = 'test';
|
||||
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
$metadata->getPropertyValue($entity);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user