Merge branch '4.2'
* 4.2: [Form] Fix tests Fix the configurability of CoreExtension deps in standalone usage [Cache] fix using ProxyAdapter inside TagAwareAdapter
This commit is contained in:
commit
9f3ce4832b
|
@ -44,11 +44,17 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
|
|||
function ($key, $innerItem) use ($defaultLifetime, $poolHash) {
|
||||
$item = new CacheItem();
|
||||
$item->key = $key;
|
||||
|
||||
if (null === $innerItem) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
$item->value = $v = $innerItem->get();
|
||||
$item->isHit = $innerItem->isHit();
|
||||
$item->defaultLifetime = $defaultLifetime;
|
||||
$item->innerItem = $innerItem;
|
||||
$item->defaultLifetime = $defaultLifetime;
|
||||
$item->poolHash = $poolHash;
|
||||
|
||||
// Detect wrapped values that encode for their expiry and creation duration
|
||||
// For compactness, these values are packed in the key of an array using
|
||||
// magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F
|
||||
|
@ -202,7 +208,18 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
|
|||
if (null === $item["\0*\0expiry"] && 0 < $item["\0*\0defaultLifetime"]) {
|
||||
$item["\0*\0expiry"] = microtime(true) + $item["\0*\0defaultLifetime"];
|
||||
}
|
||||
$innerItem = $item["\0*\0poolHash"] === $this->poolHash ? $item["\0*\0innerItem"] : $this->pool->getItem($this->namespace.$item["\0*\0key"]);
|
||||
|
||||
if ($item["\0*\0poolHash"] === $this->poolHash && $item["\0*\0innerItem"]) {
|
||||
$innerItem = $item["\0*\0innerItem"];
|
||||
} elseif ($this->pool instanceof AdapterInterface) {
|
||||
// this is an optimization specific for AdapterInterface implementations
|
||||
// so we can save a round-trip to the backend by just creating a new item
|
||||
$f = $this->createCacheItem;
|
||||
$innerItem = $f($this->namespace.$item["\0*\0key"], null);
|
||||
} else {
|
||||
$innerItem = $this->pool->getItem($this->namespace.$item["\0*\0key"]);
|
||||
}
|
||||
|
||||
($this->setInnerItem)($innerItem, $item);
|
||||
|
||||
return $this->pool->$method($innerItem);
|
||||
|
|
|
@ -51,7 +51,6 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
|
|||
$item->value = $value;
|
||||
$item->defaultLifetime = $protoItem->defaultLifetime;
|
||||
$item->expiry = $protoItem->expiry;
|
||||
$item->innerItem = $protoItem->innerItem;
|
||||
$item->poolHash = $protoItem->poolHash;
|
||||
|
||||
return $item;
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\Cache\Tests\Adapter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||
use Symfony\Component\Cache\Tests\Fixtures\ExternalAdapter;
|
||||
|
||||
class TagAwareAndProxyAdapterIntegrationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testIntegrationUsingProxiedAdapter(CacheItemPoolInterface $proxiedAdapter)
|
||||
{
|
||||
$cache = new TagAwareAdapter(new ProxyAdapter($proxiedAdapter));
|
||||
|
||||
$item = $cache->getItem('foo');
|
||||
$item->tag(['tag1', 'tag2']);
|
||||
$item->set('bar');
|
||||
$cache->save($item);
|
||||
|
||||
$this->assertSame('bar', $cache->getItem('foo')->get());
|
||||
}
|
||||
|
||||
public function dataProvider()
|
||||
{
|
||||
return [
|
||||
[new ArrayAdapter()],
|
||||
// also testing with a non-AdapterInterface implementation
|
||||
// because the ProxyAdapter behaves slightly different for those
|
||||
[new ExternalAdapter()],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ class CoreExtension extends AbstractExtension
|
|||
new Type\TimeType(),
|
||||
new Type\TimezoneType(),
|
||||
new Type\UrlType(),
|
||||
new Type\FileType(),
|
||||
new Type\FileType($this->translator),
|
||||
new Type\ButtonType(),
|
||||
new Type\SubmitType(),
|
||||
new Type\ResetType(),
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
|
||||
/**
|
||||
* The default implementation of FormFactoryBuilderInterface.
|
||||
*
|
||||
|
@ -18,6 +20,8 @@ namespace Symfony\Component\Form;
|
|||
*/
|
||||
class FormFactoryBuilder implements FormFactoryBuilderInterface
|
||||
{
|
||||
private $forceCoreExtension;
|
||||
|
||||
/**
|
||||
* @var ResolvedFormTypeFactoryInterface
|
||||
*/
|
||||
|
@ -43,6 +47,14 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
|
|||
*/
|
||||
private $typeGuessers = [];
|
||||
|
||||
/**
|
||||
* @param bool $forceCoreExtension
|
||||
*/
|
||||
public function __construct($forceCoreExtension = false)
|
||||
{
|
||||
$this->forceCoreExtension = $forceCoreExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -150,6 +162,21 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
|
|||
{
|
||||
$extensions = $this->extensions;
|
||||
|
||||
if ($this->forceCoreExtension) {
|
||||
$hasCoreExtension = false;
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if ($extension instanceof CoreExtension) {
|
||||
$hasCoreExtension = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasCoreExtension) {
|
||||
array_unshift($extensions, new CoreExtension());
|
||||
}
|
||||
}
|
||||
|
||||
if (\count($this->types) > 0 || \count($this->typeExtensions) > 0 || \count($this->typeGuessers) > 0) {
|
||||
if (\count($this->typeGuessers) > 1) {
|
||||
$typeGuesser = new FormTypeGuesserChain($this->typeGuessers);
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
|
||||
/**
|
||||
* Entry point of the Form component.
|
||||
*
|
||||
|
@ -81,10 +79,7 @@ final class Forms
|
|||
*/
|
||||
public static function createFormFactoryBuilder(): FormFactoryBuilderInterface
|
||||
{
|
||||
$builder = new FormFactoryBuilder();
|
||||
$builder->addExtension(new CoreExtension());
|
||||
|
||||
return $builder;
|
||||
return new FormFactoryBuilder(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,16 +11,26 @@
|
|||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
||||
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
|
||||
use Symfony\Component\Form\NativeRequestHandler;
|
||||
use Symfony\Component\Form\RequestHandlerInterface;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class FileTypeTest extends BaseTypeTest
|
||||
{
|
||||
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FileType';
|
||||
|
||||
protected function getExtensions()
|
||||
{
|
||||
$translator = $this->createMock(TranslatorInterface::class);
|
||||
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
|
||||
|
||||
return array_merge(parent::getExtensions(), [new CoreExtension(null, null, $translator)]);
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/pull/5028
|
||||
public function testSetData()
|
||||
{
|
||||
|
|
Reference in New Issue