diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index 3cb34ea912..bf1c2172ec 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -20,8 +20,11 @@ namespace Symfony\Component\HttpFoundation; */ class ResponseHeaderBag extends HeaderBag { - const COOKIES_FLAT = 'flat'; - const COOKIES_ARRAY = 'array'; + const COOKIES_FLAT = 'flat'; + const COOKIES_ARRAY = 'array'; + + const DISPOSITION_ATTACHMENT = 'attachment'; + const DISPOSITION_INLINE = 'inline'; protected $computedCacheControl = array(); protected $cookies = array(); @@ -216,6 +219,10 @@ class ResponseHeaderBag extends HeaderBag */ public function makeDisposition($disposition, $filename, $filenameFallback = '') { + if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) { + throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE)); + } + if (!$filenameFallback) { $filenameFallback = $filename; } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/ResponseHeaderBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/ResponseHeaderBagTest.php index 9f5ff2fc81..7bff0cb9c8 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/ResponseHeaderBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/ResponseHeaderBagTest.php @@ -119,6 +119,16 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase $this->assertFalse(isset($cookies['foo.bar'])); } + /** + * @expectedException \InvalidArgumentException + */ + public function testMakeDispositionInvalidDisposition() + { + $headers = new ResponseHeaderBag(); + + $headers->makeDisposition('invalid', 'foo.html'); + } + /** * @dataProvider provideMakeDisposition */