You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it's not possible to use autowiring on a class with:
untyped constructor parameters
typed constructor parameters where the type isn't configured (implicitly, any scalar)
Thanks to Attribute support in PHP 8, I think it should be possible to define and support attributes that enable this. An example of how this may look:
This should also work in (relatively rare) situations where a class needs a non-standard definition is needed:
class MySpecialConnection
{
publicfunction__construct(#[Value('otherPDO')] PDO$pdo) { ... }
}
// defsreturn [
PDO::class => function ($c) {
// ...
},
'otherPDO' => function ($c): PDO {
// ...
},
// BEFORE: cannot autowire, or the first PDO definition will be used
MySpecialConnection::class => function ($c) {
returnnewMySpecialConnection($c->get('otherPDO'));
},
// AFTER: correct value is configured by the parameter attribute
MySpecialConnection::class,
];
Looking at the config definitions in a relatively large project, the majority of those with non-autowired definitions via closures are to provide specific values from the container without additional logic required.
The text was updated successfully, but these errors were encountered:
Currently, it's not possible to use autowiring on a class with:
Thanks to Attribute support in PHP 8, I think it should be possible to define and support attributes that enable this. An example of how this may look:
This should also work in (relatively rare) situations where a class needs a non-standard definition is needed:
Looking at the config definitions in a relatively large project, the majority of those with non-autowired definitions via closures are to provide specific values from the container without additional logic required.
The text was updated successfully, but these errors were encountered: