[TASK] Deprecate usage of @inject with non-public properties 18/54618/7
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Sat, 11 Nov 2017 13:53:26 +0000 (14:53 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Tue, 14 Nov 2017 06:42:23 +0000 (07:42 +0100)
When using private or protected properties for Dependency Injection
via `@inject`, Extbase needs to use the object reflection API to
make these properties settable from the outside, which is quite
slow and cannot be cached in any way. Therefore property injection
should only work for public properties.

Releases: master
Resolves: #82975
Change-Id: Ia9c6eb48c34c46634e626f7cd97a2e743a6aba7b
Reviewed-on: https://review.typo3.org/54618
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-82975-DeprecateUsageOfInjectWithNonPublicProperties.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Reflection/ClassSchema.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-82975-DeprecateUsageOfInjectWithNonPublicProperties.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-82975-DeprecateUsageOfInjectWithNonPublicProperties.rst
new file mode 100644 (file)
index 0000000..cd0bd3d
--- /dev/null
@@ -0,0 +1,58 @@
+.. include:: ../../Includes.txt
+
+===========================================================================
+Deprecation: #82975 - Deprecate usage of @inject with non-public properties
+===========================================================================
+
+See :issue:`82975`
+
+Description
+===========
+
+When using private or protected properties for Dependency Injection via :php:`@inject`, Extbase needs to
+use the object reflection API to make these properties settable from the outside,
+which is quite slow and cannot be cached in any way. Therefore property injection should
+only work for public properties.
+
+
+Impact
+======
+
+Using :php:`@inject` with a non-public property will trigger a deprecation warning and will
+not work any longer in TYPO3 version 10.
+
+
+Affected Installations
+======================
+
+All installations, that use property injection via :php:`@inject` with non-public properties
+
+
+Migration
+=========
+
+You have the following options to migrate:
+
+ - Introduce an explicit :php:`inject*()` method (e.g. :php:`injectMyProperty()`)
+ - Use constructor injection
+ - Make the property public (think about whether this is desired in terms of software design)
+
+
+An inject method would look like this:
+
+.. code-block:: php
+
+   /**
+    * @var MyFancyProperty $myFancyProperty
+    */
+   private $myFancyProperty;
+
+   /**
+    * @param MyFancyProperty $myFancyProperty
+    */
+   public function injectMyFancyProperty(MyFancyProperty $myFancyProperty): void
+   {
+      $this->myFancyProperty = $myFancyProperty;
+   }
+
+.. index:: PHP-API, ext:extbase, NotScanned
index 5806386..fc36ebd 100644 (file)
@@ -194,6 +194,13 @@ class ClassSchema
                     $this->properties[$propertyName]['annotations']['type'] = ltrim($varValues[0], '\\');
                     $this->properties[$propertyName]['annotations']['dependency'] = ltrim($varValues[0], '\\');
 
+                    if (!$reflectionProperty->isPublic()) {
+                        trigger_error(
+                            'Using @inject with non-public properties is deprecated since TYPO3 v9.0 and will stop working in TYPO3 v10.0.',
+                            E_USER_DEPRECATED
+                        );
+                    }
+
                     $this->injectProperties[] = $propertyName;
                 } catch (\Exception $e) {
                 }