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",
"composer/package-versions-deprecated": "^1.8",
"doctrine/annotations": "^1.12",
"doctrine/cache": "~1.6",
"doctrine/cache": "^1.6|^2.0",
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.10|^3.0",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,11 @@ class AutowiringTypesTest extends AbstractWebTestCase
static::bootKernel();
$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()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,11 +13,13 @@ namespace Symfony\Component\Validator;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Psr\Cache\CacheItemPoolInterface;
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\Exception\ValidatorException;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
@ -268,11 +270,7 @@ class ValidatorBuilder
*/
public function addDefaultDoctrineAnnotationReader(): self
{
if (class_exists(ArrayAdapter::class)) {
$this->annotationReader = new CachedReader(new AnnotationReader(), new DoctrineProvider(new ArrayAdapter()));
} else {
$this->annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
}
$this->annotationReader = $this->createAnnotationReader();
return $this;
}
@ -425,4 +423,39 @@ class ValidatorBuilder
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/translation": "^4.4|^5.0",
"doctrine/annotations": "^1.10.4",
"doctrine/cache": "~1.0",
"doctrine/cache": "^1.0|^2.0",
"egulias/email-validator": "^2.1.10|^3"
},
"conflict": {