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
-`Container::getDelegate(string $class)` to retrieve a registered delegate container by type
18
+
19
+
### Fixed
20
+
- Interface-to-concrete definitions now correctly resolve through the concrete's own registered definition instead of bypassing it via direct reflection (#275, #278)
21
+
-`Definition::resolveClass()` now throws `ContainerException` with actionable guidance when a class has unsatisfied constructor dependencies, instead of a raw `ArgumentCountError`
17
22
18
23
### Deprecated
19
24
-`Container::inflector()` - use `Container::afterResolve()` or the event system instead. Will be removed in v6.0.
**Note:** The reflection container, by default, will resolve what you are requesting every time you request it.
80
+
**Note:** The reflection container, by default, will resolve what you are requesting every time you request it. Auto-wiring only applies to classes that have **not** been registered as explicit definitions. If you register a class with `add()` or `addShared()`, you must provide its constructor arguments explicitly using `addArgument()` or a callable.
81
81
82
82
If you would like the reflection container to cache resolutions and pull from that cache if available, you can enable it to do so as below.
When a class has constructor parameters that cannot be auto-wired (such as scalar values), you can pass them directly to the `ReflectionContainer`. Arguments are matched by parameter name.
164
+
165
+
~~~php
166
+
<?php
167
+
168
+
namespace Acme;
169
+
170
+
class ApiClient
171
+
{
172
+
public function __construct(
173
+
public readonly HttpClient $http,
174
+
public readonly string $apiKey,
175
+
public readonly int $timeout
176
+
) {}
177
+
}
178
+
179
+
$container = new League\Container\Container();
180
+
181
+
$container->delegate(
182
+
new League\Container\ReflectionContainer()
183
+
);
184
+
185
+
// Retrieve the ReflectionContainer delegate and pass runtime arguments
// HttpClient is auto-wired, apiKey and timeout are provided
193
+
~~~
194
+
195
+
Arguments must use the parameter name as the array key. Auto-wirable dependencies (type-hinted objects) are resolved automatically; only non-auto-wirable parameters need to be provided.
196
+
161
197
**Note:** The reflection container, by default, will resolve what you are requesting every time you request it.
Now that the delegate has been registered, if a service cannot be resolved via the primary container, it will resort to the `has` and `get` methods of the delegates to resolve the requested service.
41
41
42
+
### Retrieving a Delegate
42
43
44
+
If you need to access a registered delegate later, use the `getDelegate` method with the delegate's class name.
This is useful when you need to call delegate-specific methods that are not part of the PSR-11 interface, such as passing runtime arguments to `ReflectionContainer::get()` (see [Auto Wiring](/unstable/auto-wiring/)).
0 commit comments