Skip to content

Commit

Permalink
minor #36379 Fix constant accessor (driesvints)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 5.1-dev branch.

Discussion
----------

Fix constant accessor

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Because HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES is private, using static will fail for any classes extending the Response class. HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES is already properly using self a bit lower so we should do the same thing here.

Introduced in #35748

Commits
-------

633ff5b Fix constant accessor
  • Loading branch information
fabpot committed Apr 8, 2020
2 parents 2d6327f + 633ff5b commit aa44db0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -949,7 +949,7 @@ public function setEtag(string $etag = null, bool $weak = false): object
*/
public function setCache(array $options): object
{
if ($diff = array_diff(array_keys($options), array_keys(static::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES))) {
if ($diff = array_diff(array_keys($options), array_keys(self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES))) {
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', $diff)));
}

Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Expand Up @@ -672,6 +672,12 @@ public function testSetCache()

$this->assertFalse($response->headers->hasCacheControlDirective(str_replace('_', '-', $directive)));
}

$response = new DefaultResponse();

$options = ['etag' => '"whatever"'];
$response->setCache($options);
$this->assertSame($response->getEtag(), '"whatever"');
}

public function testSendContent()
Expand Down

0 comments on commit aa44db0

Please sign in to comment.