Make TypeFactory injectable
brotkrueml opened this issue · comments
The TypeFactory
has a static method createType()
by now, which [creates the correct type model class. It was introduced to ease the creation of types independent from the namespace of that class and to avoid adjustments when a type is moved from pending to core section. But this approach has some drawbacks:
- It is hard to test the classes which use this factory (for example, when using fixture types)
- The factory cannot be overridden/injected (which is useful in some cases).
- As the factory is not instantiated, dependencies (which may be needed some day) cannot be injected.
For these reasons the TypeFactory is adjusted:
- The
TypeFactory
must be injected via DI. (This way the constructor arguments are not part of the API.) - It implements a non-static method
create()
which returns the given type (like the oldcreateType
static method). - The
createType()
method is marked as deprecated and triggers a deprecation notice on usage. - The examples in the documentation are adjusted.
- The
createType()
method is listed in the deprecation chapter and will likely be removed in version 4.0.0. - A deprecation entry in the changelog is added.
This was inspired by a discussion in TYPO3 Slack.