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
@@ -221,6 +222,46 @@ Once the services have been tagged, you may easily resolve them all via the `tag
221
222
return new ReportAggregator($app->tagged('reports'));
222
223
});
223
224
225
+
226
+
<aname="binding-tags"></a>
227
+
### Binding Tags
228
+
229
+
If a class needs an array of instances or a variadic constructor argument, you can instruct the container to resolve that dependency with tagged services.
230
+
231
+
To bind services tagged as "reports" to a primitive (`array`) constructor argument named `$reports`:
232
+
233
+
class ReportAggregator
234
+
{
235
+
/** @var Report[] */
236
+
public $reports;
237
+
238
+
public function __construct(array $reports)
239
+
{
240
+
$this->reports = $reports;
241
+
}
242
+
}
243
+
244
+
$this->app->when(ReportAggregator::class)
245
+
->needs('$reports')
246
+
->giveTagged('reports');
247
+
248
+
To bind services tagged as "reports" to a variadic constructor argument typed `Report`:
0 commit comments