diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 8947744a9f..30a3805bc8 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -297,19 +297,17 @@ Form `ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed. * Using callable strings as choice options in ChoiceType is not supported - anymore in favor of passing PropertyPath instances. + anymore. Before: ```php - 'choice_value' => new PropertyPath('range'), 'choice_label' => 'strtoupper', ``` After: ```php - 'choice_value' => 'range', 'choice_label' => function ($choice) { return strtoupper($choice); }, diff --git a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php index bbb1f846e4..defa48eed9 100644 --- a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php @@ -59,7 +59,8 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter // ArrayAdapter works in memory, we don't care about stampede protection if (INF === $beta || !$item->isHit()) { - $this->save($item->set($callback($item))); + $save = true; + $this->save($item->set($callback($item, $save))); } return $item->get(); diff --git a/src/Symfony/Component/Cache/Adapter/NullAdapter.php b/src/Symfony/Component/Cache/Adapter/NullAdapter.php index f1bdd2bf71..54cd453565 100644 --- a/src/Symfony/Component/Cache/Adapter/NullAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/NullAdapter.php @@ -42,7 +42,9 @@ class NullAdapter implements AdapterInterface, CacheInterface */ public function get(string $key, callable $callback, float $beta = null, array &$metadata = null) { - return $callback(($this->createCacheItem)($key)); + $save = true; + + return $callback(($this->createCacheItem)($key), $save); } /** diff --git a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php index 8340bdf034..cf51b90d8d 100644 --- a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php @@ -103,9 +103,9 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa return $this->doGet($this, $key, $callback, $beta, $metadata); } - return $this->pool->get($this->getId($key), function ($innerItem) use ($key, $callback) { + return $this->pool->get($this->getId($key), function ($innerItem, bool &$save) use ($key, $callback) { $item = ($this->createCacheItem)($key, $innerItem); - $item->set($value = $callback($item)); + $item->set($value = $callback($item, $save)); ($this->setInnerItem)($innerItem, (array) $item); return $value; diff --git a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php index 5c294d03fd..660acf54d7 100644 --- a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php @@ -45,10 +45,10 @@ class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInt } $isHit = true; - $callback = function (CacheItem $item) use ($callback, &$isHit) { + $callback = function (CacheItem $item, bool &$save) use ($callback, &$isHit) { $isHit = $item->isHit(); - return $callback($item); + return $callback($item, $save); }; $event = $this->start(__FUNCTION__); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php index 2b66d2bea0..93318ffd48 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php @@ -12,9 +12,12 @@ namespace Symfony\Component\Cache\Tests\Adapter; use Cache\IntegrationTests\CachePoolTest; +use PHPUnit\Framework\Assert; +use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\PruneableInterface; +use Symfony\Contracts\Cache\CallbackInterface; abstract class AdapterTestCase extends CachePoolTest { @@ -57,6 +60,22 @@ abstract class AdapterTestCase extends CachePoolTest $this->assertSame($value, $item->get()); }, INF)); $this->assertFalse($isHit); + + $this->assertSame($value, $cache->get('bar', new class($value) implements CallbackInterface { + private $value; + + public function __construct(int $value) + { + $this->value = $value; + } + + public function __invoke(CacheItemInterface $item, bool &$save) + { + Assert::assertSame('bar', $item->getKey()); + + return $this->value; + } + })); } public function testRecursiveGet() diff --git a/src/Symfony/Component/HttpFoundation/RedirectResponse.php b/src/Symfony/Component/HttpFoundation/RedirectResponse.php index f685856584..8d04aa42c9 100644 --- a/src/Symfony/Component/HttpFoundation/RedirectResponse.php +++ b/src/Symfony/Component/HttpFoundation/RedirectResponse.php @@ -42,7 +42,7 @@ class RedirectResponse extends Response throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status)); } - if (301 == $status && !\array_key_exists('cache-control', $headers)) { + if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) { $this->headers->remove('cache-control'); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php index 64c3e73ee2..5f6a8ac088 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RedirectResponseTest.php @@ -91,6 +91,10 @@ class RedirectResponseTest extends TestCase $this->assertFalse($response->headers->hasCacheControlDirective('no-cache')); $this->assertTrue($response->headers->hasCacheControlDirective('max-age')); + $response = new RedirectResponse('foo.bar', 301, ['Cache-Control' => 'max-age=86400']); + $this->assertFalse($response->headers->hasCacheControlDirective('no-cache')); + $this->assertTrue($response->headers->hasCacheControlDirective('max-age')); + $response = new RedirectResponse('foo.bar', 302); $this->assertTrue($response->headers->hasCacheControlDirective('no-cache')); } diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php b/src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php index 51fa0cc76f..aa81bfc42d 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php @@ -58,7 +58,7 @@ interface PropertyAccessorInterface * * $propertyAccessor = PropertyAccess::createPropertyAccessor(); * - * echo $propertyAccessor->getValue($object, 'child.name); + * echo $propertyAccessor->getValue($object, 'child.name'); * // equals echo $object->getChild()->getName(); * * This method first tries to find a public getter for each property in the