[FEATURE] Replace @lazy with @Extbase\ORM\Lazy 47/54747/6
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Fri, 24 Nov 2017 12:38:51 +0000 (13:38 +0100)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Mon, 27 Nov 2017 15:00:52 +0000 (16:00 +0100)
This patch introduces the "TYPO3\CMS\Extbase\Annotation\ORM\Lazy"
annotation that replaces the @lazy annotation which is
deprecated from now on.

Releases: master
Resolves: #83078
Change-Id: Ic90ee3acf220288824d506c8ed63979e1236e583
Reviewed-on: https://review.typo3.org/54747
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Annotation/ORM/Lazy.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Reflection/ClassSchema.php
typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php
typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithLazyDoctrineAnnotation.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithLazyProperty.php [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php

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 (file)
index 0000000..2b9deca
--- /dev/null
@@ -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 (file)
index 0000000..21b2382
--- /dev/null
@@ -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 (file)
index 0000000..2924c02
--- /dev/null
@@ -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
+{
+}
index 6bd6995..7d21804 100644 (file)
@@ -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
             ) {
index b596f49..cd266a5 100644 (file)
@@ -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 (file)
index 0000000..89324ee
--- /dev/null
@@ -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;
+}
index 756822e..85bacb2 100644 (file)
@@ -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 (file)
index 0000000..3b37c56
--- /dev/null
@@ -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;
+}
index 3ececbc..663646d 100644 (file)
@@ -6,4 +6,10 @@ return [
             'Deprecation-82869-ReplaceInjectWithTYPO3CMSExtbaseAnnotationInject.rst',
         ],
     ],
+    '@lazy' => [
+        'restFiles' => [
+            'Feature-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst',
+            'Deprecation-83078-ReplaceLazyWithTYPO3CMSExtbaseAnnotationORMLazy.rst',
+        ],
+    ],
 ];