Flow builds for most classes a proxy for Dependency injection, lazy loading, etc it does this by creating a new file in the Code Cache that contains the contents of the original class appended with the suffix "_Original" and a class with the name of the real className that inherits from that, in this class is some magic for dependency injection, aop and lazy loading. For example:
Given we have a class named \My\Package\Foo
Then Flow will create a file called My_Package_Foo.php
This file contains the code of the class "\My\Package\Foo" with a className suffix "_Original" -> \My\Package\Foo_Original
This file also contains di, aop, and lazyloading code in the generated "\My\Package\Foo" class that inherits from \My\Package\Foo_Original
We could use this mechanism, to enable users to "Inject" whole classes in between the generated and the original class like this:
Objects.yaml
'\My\Package\Foo'
inject:
-
className: \Some\Package\FooExtension
position: start
This would trigger the ProxyBuilder to create an extension chain like this:
<?php
namespace \My\Package;
class Foo_Original {
// Code from the original classname
}
namespace \Some\Package;
class FooExtension extends \My\Package\Foo_Original {
}
namespace \My\Package;
class Foo extends Foo_Original extends \Some\Package\FooExtension {
// Generated by the ProxyBuilder containing di, aop, etc
}
Instead of this:
what about this: