Per the comments in the initial question:
What makes this hard is how Doctrine instantiates custom data types. The Type::addType($name, $className)
method for doctrine just wants the class name, not an instance of a class. What you could do is add your custom doctrine type within your bundles extension class, then register an event listener service on on kernel.request
that has the needed dependencies and set them into your data type by calling DoctrineDBALTypes::getType($name)->setSomeDependency($dependency);
. Kinda messy though.
Good find on Matthias' article. The boot()
method of the extension class does look like a more natural place to set the dependencies.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…