Merge branch '5.2' into 5.x

* 5.2:
  Fix deprecations from Doctrine Annotations+Cache
This commit is contained in:
Alexander M. Turek 2021-05-17 21:55:30 +02:00
commit 497f92da09
14 changed files with 96 additions and 43 deletions

View File

@ -125,7 +125,7 @@
"cache/integration-tests": "dev-master", "cache/integration-tests": "dev-master",
"composer/package-versions-deprecated": "^1.8", "composer/package-versions-deprecated": "^1.8",
"doctrine/annotations": "^1.12", "doctrine/annotations": "^1.12",
"doctrine/cache": "~1.6", "doctrine/cache": "^1.6|^2.0",
"doctrine/collections": "~1.0", "doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1", "doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.10|^3.0", "doctrine/dbal": "^2.10|^3.0",

View File

@ -45,7 +45,6 @@
"symfony/translation": "^4.4|^5.0", "symfony/translation": "^4.4|^5.0",
"symfony/var-dumper": "^4.4|^5.0", "symfony/var-dumper": "^4.4|^5.0",
"doctrine/annotations": "^1.10.4", "doctrine/annotations": "^1.10.4",
"doctrine/cache": "~1.6",
"doctrine/collections": "~1.0", "doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1", "doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.10|^3.0", "doctrine/dbal": "^2.10|^3.0",

View File

@ -54,13 +54,10 @@ class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
} }
$annotatedClasses = include $annotatedClassPatterns; $annotatedClasses = include $annotatedClassPatterns;
$reader = class_exists(PsrCachedReader::class)
if (class_exists(PsrCachedReader::class)) { ? new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug)
// doctrine/annotations:1.13 and above : new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug)
$reader = new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug); ;
} else {
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter), $this->debug);
}
foreach ($annotatedClasses as $class) { foreach ($annotatedClasses as $class) {
if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) { if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) {

View File

@ -92,6 +92,7 @@ class UnusedTagsPass implements CompilerPassInterface
'validator.auto_mapper', 'validator.auto_mapper',
'validator.constraint_validator', 'validator.constraint_validator',
'validator.initializer', 'validator.initializer',
'workflow.definition',
]; ];
public function process(ContainerBuilder $container) public function process(ContainerBuilder $container)

View File

@ -62,14 +62,16 @@ return static function (ContainerConfigurator $container) {
param('kernel.debug'), param('kernel.debug'),
]) ])
->set('annotations.cache', DoctrineProvider::class) ->set('annotations.cache_adapter', PhpArrayAdapter::class)
->args([
inline_service(PhpArrayAdapter::class)
->factory([PhpArrayAdapter::class, 'create']) ->factory([PhpArrayAdapter::class, 'create'])
->args([ ->args([
param('kernel.cache_dir').'/annotations.php', param('kernel.cache_dir').'/annotations.php',
service('cache.annotations'), service('cache.annotations'),
]), ])
->set('annotations.cache', DoctrineProvider::class)
->args([
service('annotations.cache_adapter')
]) ])
->tag('container.hot_path') ->tag('container.hot_path')

View File

@ -44,13 +44,16 @@ class AnnotationsCacheWarmerTest extends TestCase
$this->assertFileExists($cacheFile); $this->assertFileExists($cacheFile);
// Assert cache is valid // Assert cache is valid
$psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter()); $reader = class_exists(PsrCachedReader::class)
if (class_exists(PsrCachedReader::class)) { ? new PsrCachedReader(
$reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache); $this->getReadOnlyReader(),
} else { new PhpArrayAdapter($cacheFile, new NullAdapter())
$reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache)); )
} : new CachedReader(
$this->getReadOnlyReader(),
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter()))
)
;
$refClass = new \ReflectionClass($this); $refClass = new \ReflectionClass($this);
$reader->getClassAnnotations($refClass); $reader->getClassAnnotations($refClass);
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));
@ -67,13 +70,19 @@ class AnnotationsCacheWarmerTest extends TestCase
$this->assertFileExists($cacheFile); $this->assertFileExists($cacheFile);
// Assert cache is valid // Assert cache is valid
$psr6Cache = new PhpArrayAdapter($cacheFile, new NullAdapter()); $phpArrayAdapter = new PhpArrayAdapter($cacheFile, new NullAdapter());
if (class_exists(PsrCachedReader::class)) { $reader = class_exists(PsrCachedReader::class)
$reader = new PsrCachedReader($this->getReadOnlyReader(), $psr6Cache); ? new PsrCachedReader(
} else { $this->getReadOnlyReader(),
$reader = new CachedReader($this->getReadOnlyReader(), new DoctrineProvider($psr6Cache)); $phpArrayAdapter,
} true
)
: new CachedReader(
$this->getReadOnlyReader(),
new DoctrineProvider($phpArrayAdapter),
true
)
;
$refClass = new \ReflectionClass($this); $refClass = new \ReflectionClass($this);
$reader->getClassAnnotations($refClass); $reader->getClassAnnotations($refClass);
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));

View File

@ -34,7 +34,11 @@ class AutowiringTypesTest extends AbstractWebTestCase
static::bootKernel(); static::bootKernel();
$annotationReader = self::getContainer()->get('test.autowiring_types.autowired_services')->getAnnotationReader(); $annotationReader = self::getContainer()->get('test.autowiring_types.autowired_services')->getAnnotationReader();
$this->assertInstanceOf(class_exists(PsrCachedReader::class) ? PsrCachedReader::class : CachedReader::class, $annotationReader); if (class_exists(PsrCachedReader::class)) {
$this->assertInstanceOf(PsrCachedReader::class, $annotationReader);
} else {
$this->assertInstanceOf(CachedReader::class, $annotationReader);
}
} }
public function testEventDispatcherAutowiring() public function testEventDispatcherAutowiring()

View File

@ -34,7 +34,7 @@
}, },
"require-dev": { "require-dev": {
"doctrine/annotations": "^1.10.4", "doctrine/annotations": "^1.10.4",
"doctrine/cache": "~1.0", "doctrine/cache": "^1.0|^2.0",
"doctrine/persistence": "^1.3|^2.0", "doctrine/persistence": "^1.3|^2.0",
"symfony/asset": "^5.3", "symfony/asset": "^5.3",
"symfony/browser-kit": "^4.4|^5.0", "symfony/browser-kit": "^4.4|^5.0",

View File

@ -37,7 +37,7 @@
"symfony/framework-bundle": "^5.0", "symfony/framework-bundle": "^5.0",
"symfony/web-link": "^4.4|^5.0", "symfony/web-link": "^4.4|^5.0",
"doctrine/annotations": "^1.10.4", "doctrine/annotations": "^1.10.4",
"doctrine/cache": "~1.0" "doctrine/cache": "^1.0|^2.0"
}, },
"conflict": { "conflict": {
"symfony/dependency-injection": "<5.3", "symfony/dependency-injection": "<5.3",

View File

@ -32,7 +32,7 @@
}, },
"require-dev": { "require-dev": {
"cache/integration-tests": "dev-master", "cache/integration-tests": "dev-master",
"doctrine/cache": "^1.6", "doctrine/cache": "^1.6|^2.0",
"doctrine/dbal": "^2.10|^3.0", "doctrine/dbal": "^2.10|^3.0",
"predis/predis": "^1.1", "predis/predis": "^1.1",
"psr/simple-cache": "^1.0", "psr/simple-cache": "^1.0",

View File

@ -23,7 +23,6 @@
}, },
"require-dev": { "require-dev": {
"doctrine/annotations": "^1.12", "doctrine/annotations": "^1.12",
"doctrine/cache": "~1.0",
"phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0",
"symfony/cache": "^4.4|^5.0", "symfony/cache": "^4.4|^5.0",
"symfony/config": "^4.4|^5.0", "symfony/config": "^4.4|^5.0",

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Validator\Tests; namespace Symfony\Component\Validator\Tests;
use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\Reader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
@ -99,8 +100,12 @@ class ValidatorBuilderTest extends TestCase
$r = new \ReflectionProperty(AnnotationLoader::class, 'reader'); $r = new \ReflectionProperty(AnnotationLoader::class, 'reader');
$r->setAccessible(true); $r->setAccessible(true);
if (class_exists(PsrCachedReader::class)) {
$this->assertInstanceOf(PsrCachedReader::class, $r->getValue($loaders[0]));
} else {
$this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0])); $this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0]));
} }
}
public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader() public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader()
{ {
@ -114,8 +119,12 @@ class ValidatorBuilderTest extends TestCase
$r = new \ReflectionProperty(AnnotationLoader::class, 'reader'); $r = new \ReflectionProperty(AnnotationLoader::class, 'reader');
$r->setAccessible(true); $r->setAccessible(true);
if (class_exists(PsrCachedReader::class)) {
$this->assertInstanceOf(PsrCachedReader::class, $r->getValue($loaders[0]));
} else {
$this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0])); $this->assertInstanceOf(CachedReader::class, $r->getValue($loaders[0]));
} }
}
/** /**
* @group legacy * @group legacy

View File

@ -13,11 +13,13 @@ namespace Symfony\Component\Validator;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader; use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider; use Symfony\Component\Cache\DoctrineProvider as SymfonyDoctrineProvider;
use Symfony\Component\Validator\Context\ExecutionContextFactory; use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
@ -268,11 +270,7 @@ class ValidatorBuilder
*/ */
public function addDefaultDoctrineAnnotationReader(): self public function addDefaultDoctrineAnnotationReader(): self
{ {
if (class_exists(ArrayAdapter::class)) { $this->annotationReader = $this->createAnnotationReader();
$this->annotationReader = new CachedReader(new AnnotationReader(), new DoctrineProvider(new ArrayAdapter()));
} else {
$this->annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
}
return $this; return $this;
} }
@ -425,4 +423,39 @@ class ValidatorBuilder
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers); return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
} }
private function createAnnotationReader(): Reader
{
if (!class_exists(AnnotationReader::class)) {
throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and symfony/cache to be installed.');
}
// Doctrine Annotation >= 1.13, Symfony Cache
if (class_exists(PsrCachedReader::class) && class_exists(ArrayAdapter::class)) {
return new PsrCachedReader(new AnnotationReader(), new ArrayAdapter());
}
// Doctrine Annotations < 1.13, Doctrine Cache >= 1.11, Symfony Cache
if (class_exists(CachedReader::class) && class_exists(DoctrineProvider::class) && class_exists(ArrayAdapter::class)) {
return new CachedReader(new AnnotationReader(), DoctrineProvider::wrap(new ArrayAdapter()));
}
// Doctrine Annotations < 1.13, Doctrine Cache < 1.11, Symfony Cache
if (class_exists(CachedReader::class) && !class_exists(DoctrineProvider::class) && class_exists(ArrayAdapter::class)) {
return new CachedReader(new AnnotationReader(), new SymfonyDoctrineProvider(new ArrayAdapter()));
}
// Doctrine Annotations < 1.13, Doctrine Cache < 1.11
if (class_exists(CachedReader::class) && class_exists(ArrayCache::class)) {
return new CachedReader(new AnnotationReader(), new ArrayCache());
}
// Doctrine Annotation >= 1.13, Doctrine Cache >= 2, no Symfony Cache
if (class_exists(PsrCachedReader::class)) {
throw new LogicException('Enabling annotation based constraint mapping requires the package symfony/cache to be installed.');
}
// Doctrine Annotation (<1.13 || >2), no Doctrine Cache, no Symfony Cache
throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations (>=1.13) and symfony/cache to be installed.');
}
} }

View File

@ -41,7 +41,7 @@
"symfony/property-info": "^5.3", "symfony/property-info": "^5.3",
"symfony/translation": "^4.4|^5.0", "symfony/translation": "^4.4|^5.0",
"doctrine/annotations": "^1.10.4", "doctrine/annotations": "^1.10.4",
"doctrine/cache": "~1.0", "doctrine/cache": "^1.0|^2.0",
"egulias/email-validator": "^2.1.10|^3" "egulias/email-validator": "^2.1.10|^3"
}, },
"conflict": { "conflict": {