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

Skip to content

Commit fa07177

Browse files
Merge branch '4.2' into 4.3
* 4.2: [Cache] Pass arg to get callback everywhere Add a missing quote in getValue() DocBlock [HttpFoundation] Fixed case-sensitive handling of cache-control header in RedirectResponse constructor. minor: ChoiceType callable deprecation after/before seems wrong
2 parents fc2a86f + 05eb388 commit fa07177

File tree

9 files changed

+35
-11
lines changed

9 files changed

+35
-11
lines changed

UPGRADE-4.0.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,17 @@ Form
297297
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed.
298298

299299
* Using callable strings as choice options in ChoiceType is not supported
300-
anymore in favor of passing PropertyPath instances.
300+
anymore.
301301

302302
Before:
303303

304304
```php
305-
'choice_value' => new PropertyPath('range'),
306305
'choice_label' => 'strtoupper',
307306
```
308307

309308
After:
310309

311310
```php
312-
'choice_value' => 'range',
313311
'choice_label' => function ($choice) {
314312
return strtoupper($choice);
315313
},

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public function get(string $key, callable $callback, float $beta = null, array &
5959

6060
// ArrayAdapter works in memory, we don't care about stampede protection
6161
if (INF === $beta || !$item->isHit()) {
62-
$this->save($item->set($callback($item)));
62+
$save = true;
63+
$this->save($item->set($callback($item, $save)));
6364
}
6465

6566
return $item->get();

src/Symfony/Component/Cache/Adapter/NullAdapter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function ($key) {
4242
*/
4343
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
4444
{
45-
return $callback(($this->createCacheItem)($key));
45+
$save = true;
46+
47+
return $callback(($this->createCacheItem)($key), $save);
4648
}
4749

4850
/**

src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public function get(string $key, callable $callback, float $beta = null, array &
103103
return $this->doGet($this, $key, $callback, $beta, $metadata);
104104
}
105105

106-
return $this->pool->get($this->getId($key), function ($innerItem) use ($key, $callback) {
106+
return $this->pool->get($this->getId($key), function ($innerItem, bool &$save) use ($key, $callback) {
107107
$item = ($this->createCacheItem)($key, $innerItem);
108-
$item->set($value = $callback($item));
108+
$item->set($value = $callback($item, $save));
109109
($this->setInnerItem)($innerItem, (array) $item);
110110

111111
return $value;

src/Symfony/Component/Cache/Adapter/TraceableAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function get(string $key, callable $callback, float $beta = null, array &
4545
}
4646

4747
$isHit = true;
48-
$callback = function (CacheItem $item) use ($callback, &$isHit) {
48+
$callback = function (CacheItem $item, bool &$save) use ($callback, &$isHit) {
4949
$isHit = $item->isHit();
5050

51-
return $callback($item);
51+
return $callback($item, $save);
5252
};
5353

5454
$event = $this->start(__FUNCTION__);

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

1414
use Cache\IntegrationTests\CachePoolTest;
15+
use PHPUnit\Framework\Assert;
16+
use Psr\Cache\CacheItemInterface;
1517
use Psr\Cache\CacheItemPoolInterface;
1618
use Symfony\Component\Cache\CacheItem;
1719
use Symfony\Component\Cache\PruneableInterface;
20+
use Symfony\Contracts\Cache\CallbackInterface;
1821

1922
abstract class AdapterTestCase extends CachePoolTest
2023
{
@@ -57,6 +60,22 @@ public function testGet()
5760
$this->assertSame($value, $item->get());
5861
}, INF));
5962
$this->assertFalse($isHit);
63+
64+
$this->assertSame($value, $cache->get('bar', new class($value) implements CallbackInterface {
65+
private $value;
66+
67+
public function __construct(int $value)
68+
{
69+
$this->value = $value;
70+
}
71+
72+
public function __invoke(CacheItemInterface $item, bool &$save)
73+
{
74+
Assert::assertSame('bar', $item->getKey());
75+
76+
return $this->value;
77+
}
78+
}));
6079
}
6180

6281
public function testRecursiveGet()

src/Symfony/Component/HttpFoundation/RedirectResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(?string $url, int $status = 302, array $headers = []
4242
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
4343
}
4444

45-
if (301 == $status && !\array_key_exists('cache-control', $headers)) {
45+
if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) {
4646
$this->headers->remove('cache-control');
4747
}
4848
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public function testCacheHeaders()
9191
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
9292
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
9393

94+
$response = new RedirectResponse('foo.bar', 301, ['Cache-Control' => 'max-age=86400']);
95+
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
96+
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
97+
9498
$response = new RedirectResponse('foo.bar', 302);
9599
$this->assertTrue($response->headers->hasCacheControlDirective('no-cache'));
96100
}

src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value);
5858
*
5959
* $propertyAccessor = PropertyAccess::createPropertyAccessor();
6060
*
61-
* echo $propertyAccessor->getValue($object, 'child.name);
61+
* echo $propertyAccessor->getValue($object, 'child.name');
6262
* // equals echo $object->getChild()->getName();
6363
*
6464
* This method first tries to find a public getter for each property in the

0 commit comments

Comments
 (0)