Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9f3ce48

Browse filesBrowse files
committed
Merge branch '4.2'
* 4.2: [Form] Fix tests Fix the configurability of CoreExtension deps in standalone usage [Cache] fix using ProxyAdapter inside TagAwareAdapter
2 parents c68ef46 + 393c6b3 commit 9f3ce48
Copy full SHA for 9f3ce48

File tree

Expand file treeCollapse file tree

7 files changed

+96
-10
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+96
-10
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ public function __construct(CacheItemPoolInterface $pool, string $namespace = ''
4444
function ($key, $innerItem) use ($defaultLifetime, $poolHash) {
4545
$item = new CacheItem();
4646
$item->key = $key;
47+
48+
if (null === $innerItem) {
49+
return $item;
50+
}
51+
4752
$item->value = $v = $innerItem->get();
4853
$item->isHit = $innerItem->isHit();
49-
$item->defaultLifetime = $defaultLifetime;
5054
$item->innerItem = $innerItem;
55+
$item->defaultLifetime = $defaultLifetime;
5156
$item->poolHash = $poolHash;
57+
5258
// Detect wrapped values that encode for their expiry and creation duration
5359
// For compactness, these values are packed in the key of an array using
5460
// magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F
@@ -202,7 +208,18 @@ private function doSave(CacheItemInterface $item, $method)
202208
if (null === $item["\0*\0expiry"] && 0 < $item["\0*\0defaultLifetime"]) {
203209
$item["\0*\0expiry"] = microtime(true) + $item["\0*\0defaultLifetime"];
204210
}
205-
$innerItem = $item["\0*\0poolHash"] === $this->poolHash ? $item["\0*\0innerItem"] : $this->pool->getItem($this->namespace.$item["\0*\0key"]);
211+
212+
if ($item["\0*\0poolHash"] === $this->poolHash && $item["\0*\0innerItem"]) {
213+
$innerItem = $item["\0*\0innerItem"];
214+
} elseif ($this->pool instanceof AdapterInterface) {
215+
// this is an optimization specific for AdapterInterface implementations
216+
// so we can save a round-trip to the backend by just creating a new item
217+
$f = $this->createCacheItem;
218+
$innerItem = $f($this->namespace.$item["\0*\0key"], null);
219+
} else {
220+
$innerItem = $this->pool->getItem($this->namespace.$item["\0*\0key"]);
221+
}
222+
206223
($this->setInnerItem)($innerItem, $item);
207224

208225
return $this->pool->$method($innerItem);

‎src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function ($key, $value, CacheItem $protoItem) {
5151
$item->value = $value;
5252
$item->defaultLifetime = $protoItem->defaultLifetime;
5353
$item->expiry = $protoItem->expiry;
54-
$item->innerItem = $protoItem->innerItem;
5554
$item->poolHash = $protoItem->poolHash;
5655

5756
return $item;
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Symfony\Component\Cache\Tests\Adapter;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Psr\Cache\CacheItemPoolInterface;
7+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
8+
use Symfony\Component\Cache\Adapter\ProxyAdapter;
9+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
10+
use Symfony\Component\Cache\Tests\Fixtures\ExternalAdapter;
11+
12+
class TagAwareAndProxyAdapterIntegrationTest extends TestCase
13+
{
14+
/**
15+
* @dataProvider dataProvider
16+
*/
17+
public function testIntegrationUsingProxiedAdapter(CacheItemPoolInterface $proxiedAdapter)
18+
{
19+
$cache = new TagAwareAdapter(new ProxyAdapter($proxiedAdapter));
20+
21+
$item = $cache->getItem('foo');
22+
$item->tag(['tag1', 'tag2']);
23+
$item->set('bar');
24+
$cache->save($item);
25+
26+
$this->assertSame('bar', $cache->getItem('foo')->get());
27+
}
28+
29+
public function dataProvider()
30+
{
31+
return [
32+
[new ArrayAdapter()],
33+
// also testing with a non-AdapterInterface implementation
34+
// because the ProxyAdapter behaves slightly different for those
35+
[new ExternalAdapter()],
36+
];
37+
}
38+
}

‎src/Symfony/Component/Form/Extension/Core/CoreExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/CoreExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function loadTypes()
7676
new Type\TimeType(),
7777
new Type\TimezoneType(),
7878
new Type\UrlType(),
79-
new Type\FileType(),
79+
new Type\FileType($this->translator),
8080
new Type\ButtonType(),
8181
new Type\SubmitType(),
8282
new Type\ResetType(),

‎src/Symfony/Component/Form/FormFactoryBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/FormFactoryBuilder.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespace Symfony\Component\Form;
1313

14+
use Symfony\Component\Form\Extension\Core\CoreExtension;
15+
1416
/**
1517
* The default implementation of FormFactoryBuilderInterface.
1618
*
1719
* @author Bernhard Schussek <bschussek@gmail.com>
1820
*/
1921
class FormFactoryBuilder implements FormFactoryBuilderInterface
2022
{
23+
private $forceCoreExtension;
24+
2125
/**
2226
* @var ResolvedFormTypeFactoryInterface
2327
*/
@@ -43,6 +47,14 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
4347
*/
4448
private $typeGuessers = [];
4549

50+
/**
51+
* @param bool $forceCoreExtension
52+
*/
53+
public function __construct($forceCoreExtension = false)
54+
{
55+
$this->forceCoreExtension = $forceCoreExtension;
56+
}
57+
4658
/**
4759
* {@inheritdoc}
4860
*/
@@ -150,6 +162,21 @@ public function getFormFactory()
150162
{
151163
$extensions = $this->extensions;
152164

165+
if ($this->forceCoreExtension) {
166+
$hasCoreExtension = false;
167+
168+
foreach ($extensions as $extension) {
169+
if ($extension instanceof CoreExtension) {
170+
$hasCoreExtension = true;
171+
break;
172+
}
173+
}
174+
175+
if (!$hasCoreExtension) {
176+
array_unshift($extensions, new CoreExtension());
177+
}
178+
}
179+
153180
if (\count($this->types) > 0 || \count($this->typeExtensions) > 0 || \count($this->typeGuessers) > 0) {
154181
if (\count($this->typeGuessers) > 1) {
155182
$typeGuesser = new FormTypeGuesserChain($this->typeGuessers);

‎src/Symfony/Component/Form/Forms.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Forms.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Extension\Core\CoreExtension;
15-
1614
/**
1715
* Entry point of the Form component.
1816
*
@@ -81,10 +79,7 @@ public static function createFormFactory(): FormFactoryInterface
8179
*/
8280
public static function createFormFactoryBuilder(): FormFactoryBuilderInterface
8381
{
84-
$builder = new FormFactoryBuilder();
85-
$builder->addExtension(new CoreExtension());
86-
87-
return $builder;
82+
return new FormFactoryBuilder(true);
8883
}
8984

9085
/**

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Component\Form\Extension\Core\CoreExtension;
1415
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
1516
use Symfony\Component\Form\NativeRequestHandler;
1617
use Symfony\Component\Form\RequestHandlerInterface;
1718
use Symfony\Component\HttpFoundation\File\File;
1819
use Symfony\Component\HttpFoundation\File\UploadedFile;
20+
use Symfony\Component\Translation\TranslatorInterface;
1921

2022
class FileTypeTest extends BaseTypeTest
2123
{
2224
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FileType';
2325

26+
protected function getExtensions()
27+
{
28+
$translator = $this->createMock(TranslatorInterface::class);
29+
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
30+
31+
return array_merge(parent::getExtensions(), [new CoreExtension(null, null, $translator)]);
32+
}
33+
2434
// https://github.com/symfony/symfony/pull/5028
2535
public function testSetData()
2636
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.