Task #84112

Epic #83968: PSR-11 Initiative

Add support for service providers

Added by Benjamin Franzke over 1 year ago. Updated 4 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
System/Bootstrap/Configuration
Start date:
2018-03-02
Due date:
% Done:

100%

TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Sprint Focus:

Associated revisions

Revision 0cf8053e (diff)
Added by Benjamin Franzke 4 months ago

[FEATURE] Add symfony dependency injection for core and extbase

This feature is a combined approach using two containers/concepts:

1) symfony/dependency-injection (now exposed as official TYPO3 API):
Supports: autoconfiguration, autowiring using Service.{yaml,php}
files

2) service providers (fork of the experimental interfaces in
container-interop/service-provider, sometimes called PSR-11+)
Supports: factory-style configuration using plain php code
provided for internal use and possible future public use.

1) Symfony dependency injection is provided to be used by extensions
and throughout the TYPO3 core for (auto)wiring of services (classes).
Extensions can control symfony's dependency injection use a file
located in Configuration/Services.yaml, if they need more flexibility
they may also use Configuration/Services.php which can
use symfony's ContainerConfigurator or ContainerBuilder.

2) Service providers are used (within TYPO3 core) to provide
dependency injection for services used in the install tool which require
failsafe boot. This is based on container-interop/service-provider.
container-interop/service-provider is supposed to become a PSR but is
still marked experimental, therefore this commit adds an implementation
to TYPO3 provided for internal use only – it is not public API.
We do still include it (as @interal fork) right now, to adapt to this
upcoming PSR from the very beginning, in order to actually push the
development of this proposal forward.

Service providers in failsafe mode are consumed by a simplistic,
non-compiled container.
Symfony's container is too slow when running uncached (as the compilation,
recursive directory lookups and autowiring needs to be performed on every
invocation). We do not want caching for recovery maintenance tasks
which would not be able to recover from scenarios with broken caches.

Services that are configured through service providers, are both available
in the non compiled install tool container and in the symfony container.
They do not need to be defined twice. The two "worlds" are bridged
using a ServiceProviderCompilerPass which creates symfony DI definitions
from service-provider factories. The code is a derivative of the code from
the (outdated) symfony bundle
thecodingmachine/service-provider-bridge-bundle.

Features
-------- * inject* methods are now supported for all classes (not just Extbase)
It is suggested to use constructor based injection, this feature
is available to provide maximum compatibility to the old Extbase DI. * Autoconfiguration based on interface implementation.
(current) autoconfigured interface are:
SingletonInterface, MiddlewareInterface, RequestHandlerInterface,
LoggerAwareInterface, ControllerInterface, ViewHelperInterface
(we expect more to follow in subsequent commits)

Included adaptions
------------------
In order to demonstrate and to be able to verify the features of this
patch, some classes are adapted to use or support dependency injection: * RedirectHandler/RedirectService autowired/autoconfigured * Application classes and their dependencies are manually wired in
service providers. This is required as the application runs in fail-
safe mode when there is no configuration available (first install) * MiddlewareStack is composed in service providers and injected
as a RequestHandler into the Http\Application classes (in order to
prevent injecting the Container, which would be an anti pattern). * Middleware configuration is treated as service (like a registry),
and retrieval is provided through service providers (the service
providers default to the existing middleware configuration format) * The Middleware dispatcher now first tries to retrieve classes from
the PSR-11 container, falling back to makeInstance if not available * Dependency Injection using symfony for all core Extbase Controllers * A Services.yaml is added for each core extension which contains
classes that are used in frontend/backend context * A LateBoot service is added for install tool

DI vs ext_localconf – loading order, legacy makeInstance support
----------------------------------------------------------------
Dependency Injection containers solve most of the tasks that
ext_localconf.php and GeneralUtility::makeInstance solve for Singletons:
Service configuration and instance management.

(Symfony) DI could therefore be used to replace both in the long run.
Both are doing similar tasks when talking about Singletons:
They create and configure services that are stored and shared in a
central memory storage (container for DI, GU::$singletonInstances for
our legacy TYPO3 case). That means they both actually conflict right
now – in terms of: Who is responsible for creating a class?

We've made a decision to connect these both: GeneralUtility::makeInstance
will offload instantiation to the Container if the class is a) available
and b) no runtime constructor arguments have been passed to makeInstance
(which symfony DI doesn't support).

The DI container itself does provides backwards compatibility to XCLASSES
and class aliases use a new internal helper method makeInstanceForDi.

ext_localconf's main design flaw is the mixture of initialization
and configuration composition without assurance that all configuration
is available before a configuration-dependent class is instantiated.
Proper DI first reads all configuration and then performs all service
injections on demand and pre calculated using a dependency tree – and
therefore always in proper sequence.

What we don't want (+ reasons)
------------------------------- * Symfony Bundles
pro: provide a defined way for container configuration)
con: Requires the Symfony HTTP kernel which is not compatible with PSR7 * Usage of Symfony\DependencyInjection\ExtensionInterface
con: It is not useful as it cannot add new compiler passes * Handling of prototypes that need dependency injection and a way to
to get custom constructor arguments passed (individual per class)
While symfony DI can handle prototypes (called 'shared: false'), it
does not support passing constructor arguments like the Extbase object
manager does. We'll advocate to using a factory pattern for those
prototypes instead. * Circular dependencies: This is not supported by symfony DI and isn't
possible with service providers either

Future changes (left out for brevity)
-------------------------------------

  • (cli) Build tool to warmup DI cache/state during deployment
  • Adaptions to (all) core dispatchers to prefer a PSR-11
    container over GeneralUtility::makeInstance

Dependency changes
------------------
composer require symfony/dependency-injection:^4.1 symfony/config:^4.1

Releases: master
Resolves: #88689
Resolves: #84112
Change-Id: I8efd817066b528a5953c56fdd027cb94b2bb8eb3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255
Tested-by: Tobi Kretschmann <>
Tested-by: Jörg Bösche <>
Tested-by: Alexander Schnitzler <>
Tested-by: TYPO3com <>
Tested-by: Benjamin Franzke <>
Reviewed-by: Tobi Kretschmann <>
Reviewed-by: Jörg Bösche <>
Reviewed-by: Alexander Schnitzler <>
Reviewed-by: Benjamin Franzke <>

History

#1 Updated by Gerrit Code Review over 1 year ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#2 Updated by Gerrit Code Review over 1 year ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#3 Updated by Gerrit Code Review over 1 year ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#4 Updated by Gerrit Code Review over 1 year ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#5 Updated by Gerrit Code Review over 1 year ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#6 Updated by Gerrit Code Review over 1 year ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#7 Updated by Gerrit Code Review over 1 year ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#8 Updated by Gerrit Code Review over 1 year ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#9 Updated by Benni Mack over 1 year ago

  • Target version changed from 9.2 to 9.3

Won't make it in 9.2, but moved it to 9.3 scope

#10 Updated by Gerrit Code Review over 1 year ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#11 Updated by Susanne Moog over 1 year ago

  • Target version changed from 9.3 to 9.4

#12 Updated by Benni Mack about 1 year ago

  • Target version changed from 9.4 to Candidate for Major Version

#13 Updated by Gerrit Code Review about 1 year ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#14 Updated by Gerrit Code Review about 1 year ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#15 Updated by Gerrit Code Review about 1 year ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56068

#16 Updated by Gerrit Code Review about 1 year ago

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#17 Updated by Gerrit Code Review about 1 year ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#18 Updated by Gerrit Code Review about 1 year ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#19 Updated by Gerrit Code Review about 1 year ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#20 Updated by Gerrit Code Review about 1 year ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#21 Updated by Gerrit Code Review about 1 year ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#22 Updated by Gerrit Code Review about 1 year ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#23 Updated by Gerrit Code Review about 1 year ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#24 Updated by Gerrit Code Review about 1 year ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#25 Updated by Gerrit Code Review about 1 year ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#26 Updated by Gerrit Code Review about 1 year ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#27 Updated by Gerrit Code Review about 1 year ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#28 Updated by Gerrit Code Review about 1 year ago

Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#29 Updated by Gerrit Code Review about 1 year ago

Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#30 Updated by Gerrit Code Review about 1 year ago

Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#31 Updated by Gerrit Code Review about 1 year ago

Patch set 16 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#32 Updated by Gerrit Code Review about 1 year ago

Patch set 17 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#33 Updated by Gerrit Code Review about 1 year ago

Patch set 18 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#34 Updated by Gerrit Code Review about 1 year ago

Patch set 19 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#35 Updated by Gerrit Code Review 11 months ago

Patch set 20 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#36 Updated by Gerrit Code Review 11 months ago

Patch set 21 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#37 Updated by Gerrit Code Review 10 months ago

Patch set 22 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#38 Updated by Gerrit Code Review 10 months ago

Patch set 23 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#39 Updated by Gerrit Code Review 10 months ago

Patch set 24 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#40 Updated by Gerrit Code Review 10 months ago

Patch set 25 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#41 Updated by Gerrit Code Review 10 months ago

Patch set 26 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#42 Updated by Gerrit Code Review 10 months ago

Patch set 27 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#43 Updated by Gerrit Code Review 10 months ago

Patch set 28 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#44 Updated by Gerrit Code Review 10 months ago

Patch set 29 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#45 Updated by Gerrit Code Review 10 months ago

Patch set 30 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#46 Updated by Gerrit Code Review 10 months ago

Patch set 31 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#47 Updated by Gerrit Code Review 10 months ago

Patch set 32 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#48 Updated by Gerrit Code Review 9 months ago

Patch set 33 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#49 Updated by Gerrit Code Review 9 months ago

Patch set 34 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#50 Updated by Gerrit Code Review 9 months ago

Patch set 35 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#51 Updated by Gerrit Code Review 9 months ago

Patch set 36 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#52 Updated by Gerrit Code Review 9 months ago

Patch set 37 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#53 Updated by Gerrit Code Review 9 months ago

Patch set 38 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#54 Updated by Gerrit Code Review 9 months ago

Patch set 39 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#55 Updated by Gerrit Code Review 9 months ago

Patch set 40 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#56 Updated by Gerrit Code Review 9 months ago

Patch set 41 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#57 Updated by Gerrit Code Review 9 months ago

Patch set 42 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#58 Updated by Gerrit Code Review 9 months ago

Patch set 43 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#59 Updated by Gerrit Code Review 9 months ago

Patch set 44 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#60 Updated by Gerrit Code Review 9 months ago

Patch set 45 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#61 Updated by Gerrit Code Review 9 months ago

Patch set 46 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#62 Updated by Gerrit Code Review 9 months ago

Patch set 47 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#63 Updated by Gerrit Code Review 9 months ago

Patch set 48 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#64 Updated by Gerrit Code Review 9 months ago

Patch set 49 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58255

#65 Updated by Gerrit Code Review 9 months ago

Patch set 50 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#66 Updated by Gerrit Code Review 9 months ago

Patch set 51 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#67 Updated by Gerrit Code Review 9 months ago

Patch set 52 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#68 Updated by Gerrit Code Review 9 months ago

Patch set 53 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#69 Updated by Gerrit Code Review 9 months ago

Patch set 54 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#70 Updated by Gerrit Code Review 9 months ago

Patch set 55 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#71 Updated by Gerrit Code Review 5 months ago

Patch set 56 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#72 Updated by Gerrit Code Review 5 months ago

Patch set 57 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#73 Updated by Gerrit Code Review 5 months ago

Patch set 58 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#74 Updated by Gerrit Code Review 5 months ago

Patch set 59 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#75 Updated by Gerrit Code Review 5 months ago

Patch set 60 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#76 Updated by Benjamin Franzke 4 months ago

  • Parent task set to #83968

#77 Updated by Gerrit Code Review 4 months ago

Patch set 61 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#78 Updated by Gerrit Code Review 4 months ago

Patch set 62 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#79 Updated by Gerrit Code Review 4 months ago

Patch set 63 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#80 Updated by Gerrit Code Review 4 months ago

Patch set 64 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#81 Updated by Gerrit Code Review 4 months ago

Patch set 65 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#82 Updated by Gerrit Code Review 4 months ago

Patch set 66 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#83 Updated by Gerrit Code Review 4 months ago

Patch set 67 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#84 Updated by Gerrit Code Review 4 months ago

Patch set 68 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#85 Updated by Gerrit Code Review 4 months ago

Patch set 69 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#86 Updated by Gerrit Code Review 4 months ago

Patch set 70 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58255

#87 Updated by Benjamin Franzke 4 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#88 Updated by Benni Mack 4 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF