Feature #31261

Virtual objects - generate proxy classes for interfaces

Added by Christopher Hlubek almost 4 years ago.

Status:New Start date:2011-10-25
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:Object
Target version:-
PHP Version: Complexity:
Has patch:No

Description

It should be possible to declare an interface and configure an object (e.g. singleton based on a prototype with arguments) for it in Objects.yaml. Right now you have to write a factory class to have different singletons based on the same prototype object.

Example:

Objects.yaml


TYPO3\Example\MyInterface:
  scope: singleton
  className: TYPO3\Example\MyClass # <- scope: prototype
  arguments:
    1:
      value: Foo

TYPO3\Example\MyDebugInterface:
  scope: singleton
  className: TYPO3\Example\MyClass # <- scope: prototype
  arguments:
    1:
      value: Bar
  properties:
    debug:
      value: true

There should be a generated proxy class for the interface that implements the interface. Dependency injection with the interface type should work with that automatically.

I think instantiating the interface with new \TYPO3\Example\MyInterface() has not to work since it's also contra-intuitive to the default PHP behaviour. So DI or the ObjectManager must be used for that.

Also available in: Atom PDF