diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst new file mode 100644 index 0000000000000000000000000000000000000000..2b9deca4fbb923cbdb4e818b367db4ee7515a8f9 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst @@ -0,0 +1,32 @@ +.. include:: ../../Includes.txt + +=============================================================================== +Deprecation: #83078 - Replace @lazy with @TYPO3\CMS\Extbase\Annotation\ORM\Lazy +=============================================================================== + +See :issue:`83078` + +Description +=========== + +The `@lazy` annotation has been deprecated and must be replaced with the doctrine annotation `@TYPO3\CMS\Extbase\Annotation\ORM\Lazy`. + + +Impact +====== + +From version 9.0 on, `@lazy` is deprecated and will be removed in version 10. + + +Affected Installations +====================== + +All extensions that use `@lazy` + + +Migration +========= + +Use `@TYPO3\CMS\Extbase\Annotation\ORM\Lazy` instead. + +.. index:: PHP-API, ext:extbase, FullyScanned diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst new file mode 100644 index 0000000000000000000000000000000000000000..21b2382abeb0ef4dc863a3799711aeedb488b9e2 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst @@ -0,0 +1,62 @@ +.. include:: ../../Includes.txt + +=========================================================================== +Feature: #83078 - Replace @lazy with @TYPO3\CMS\Extbase\Annotation\ORM\Lazy +=========================================================================== + +See :issue:`83078` + +Description +=========== + +As a successor to the `@lazy` annotation, the doctrine annotation `@TYPO3\CMS\Extbase\Annotation\ORM\Lazy` has been introduced. + +Example: + +.. code-block:: php + + /** + * @TYPO3\CMS\Extbase\Annotation\ORM\Lazy + * @var Foo + */ + public $property; + +Doctrine annotations are actual defined classes, therefore you can also use the annotation with a use statement. + +Example: + +.. code-block:: php + + use TYPO3\CMS\Extbase\Annotation\ORM\Lazy; + +.. code-block:: php + + /** + * @Lazy + * @var Foo + */ + public $property; + +Used annotations can also be aliased which the core will most likely be using a lot in the future. + +Example: + +.. code-block:: php + + use TYPO3\CMS\Extbase\Annotation as Extbase; + +.. code-block:: php + + /** + * @Extbase\ORM\Lazy + * @var Foo + */ + public $property; + + +Impact +====== + +In 9.x there is no actual impact. Both the simple `@lazy` and `@TYPO3\CMS\Extbase\Annotation\ORM\Lazy` can be used side by side. However, `@lazy` is deprecated in 9.x and will be removed in version 10. + +.. index:: PHP-API, ext:extbase, FullyScanned diff --git a/typo3/sysext/extbase/Classes/Annotation/ORM/Lazy.php b/typo3/sysext/extbase/Classes/Annotation/ORM/Lazy.php new file mode 100644 index 0000000000000000000000000000000000000000..2924c020e0d36f126289400ea944558f8506120e --- /dev/null +++ b/typo3/sysext/extbase/Classes/Annotation/ORM/Lazy.php @@ -0,0 +1,25 @@ +<?php +declare(strict_types=1); + +namespace TYPO3\CMS\Extbase\Annotation\ORM; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * @Annotation + * @Target({"PROPERTY"}) + */ +class Lazy +{ +} diff --git a/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php b/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php index 6bd69959f702c307e36eeb8413960d389228d744..7d2180414784dfe42cc5a9e6562ff34323842de6 100644 --- a/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php +++ b/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php @@ -18,6 +18,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\ClassNamingUtility; use TYPO3\CMS\Extbase\Annotation\Inject; +use TYPO3\CMS\Extbase\Annotation\ORM\Lazy; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractValueObject; use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility; @@ -170,12 +171,24 @@ class ClassSchema } $this->properties[$propertyName]['annotations']['inject'] = false; - $this->properties[$propertyName]['annotations']['lazy'] = $docCommentParser->isTaggedWith('lazy'); + $this->properties[$propertyName]['annotations']['lazy'] = false; $this->properties[$propertyName]['annotations']['transient'] = $docCommentParser->isTaggedWith('transient'); $this->properties[$propertyName]['annotations']['type'] = null; $this->properties[$propertyName]['annotations']['cascade'] = null; $this->properties[$propertyName]['annotations']['dependency'] = null; + if (($annotation = $annotationReader->getPropertyAnnotation($reflectionProperty, Lazy::class)) instanceof Lazy) { + $this->properties[$propertyName]['annotations']['lazy'] = true; + } + + if ($docCommentParser->isTaggedWith('lazy')) { + $this->properties[$propertyName]['annotations']['lazy'] = true; + trigger_error( + 'Tagging properties with @lazy is deprecated and will be removed in TYPO3 v10.0.', + E_USER_DEPRECATED + ); + } + if ($propertyName !== 'settings' && ($annotation = $annotationReader->getPropertyAnnotation($reflectionProperty, Inject::class)) instanceof Inject ) { diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php b/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php index b596f49725d38f575bc9730e514c5e05967437a8..cd266a52e95aa256b8d85de18d9094543f17df37 100644 --- a/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php @@ -178,6 +178,12 @@ class ClassSchemaTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase static::assertArrayHasKey('injectFoo', $injectMethods); } + public function testClassSchemaDetectsPropertiesWithLazyAnnotation() + { + $classSchema = new ClassSchema(Fixture\DummyClassWithLazyDoctrineAnnotation::class); + static::assertTrue($classSchema->getProperty('propertyWithLazyAnnotation')['annotations']['lazy']); + } + public function testClassSchemaDetectsStaticMethods() { $classSchema = new ClassSchema(Fixture\DummyClassWithAllTypesOfMethods::class); diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithLazyDoctrineAnnotation.php b/typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithLazyDoctrineAnnotation.php new file mode 100644 index 0000000000000000000000000000000000000000..89324ee9643193a15e28cf64bb6f20a80362ed1a --- /dev/null +++ b/typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithLazyDoctrineAnnotation.php @@ -0,0 +1,30 @@ +<?php +declare(strict_types=1); + +namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Extbase\Annotation as Extbase; + +/** + * Fixture class with @TYPO3\CMS\Extbase\Annotation\ORM\Lazy annotation + */ +class DummyClassWithLazyDoctrineAnnotation +{ + /** + * @Extbase\ORM\Lazy + */ + public $propertyWithLazyAnnotation; +} diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php index 756822ed970db6a25e41dc37d9151be4c8120b06..85bacb2b60fa9acf67c506d3bde90f1fa0be6962 100644 --- a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php +++ b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php @@ -32,4 +32,10 @@ class ClassSchemaTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase $injectProperties = $classSchema->getInjectProperties(); static::assertArrayHasKey('propertyWithInjectAnnotation', $injectProperties); } + + public function testClassSchemaDetectsLazyProperties() + { + $classSchema = new ClassSchema(Fixture\DummyClassWithLazyProperty::class); + static::assertTrue($classSchema->getProperty('propertyWithLazyAnnotation')['annotations']['lazy']); + } } diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithLazyProperty.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithLazyProperty.php new file mode 100644 index 0000000000000000000000000000000000000000..3b37c568df72b4e4493b94597317c67b8ad2c00e --- /dev/null +++ b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithLazyProperty.php @@ -0,0 +1,28 @@ +<?php +declare(strict_types=1); + +namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * Dummy class with @lazy annotation + */ +class DummyClassWithLazyProperty +{ + /** + * @lazy + */ + public $propertyWithLazyAnnotation; +} diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php index 3ececbceb61b2564ecbde074f1542af0ea8d832d..663646d679c53c00e3b69157ce5db36deeceeb59 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php @@ -6,4 +6,10 @@ return [ 'Deprecation-82869-ReplaceInjectWithTYPO3CMSExtbaseAnnotationInject.rst', ], ], + '@lazy' => [ + 'restFiles' => [ + 'Feature-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst', + 'Deprecation-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst', + ], + ], ];