@@ -334,19 +334,26 @@ as arguments of other services:
334
334
services :
335
335
App\Service\SomeService :
336
336
arguments :
337
- # arguments without a type are treated as strings
337
+ # string, numeric and boolean arguments can be passed " as is"
338
338
- ' Foo'
339
- # explicitly declare a string argument
340
- - !str ' Foo'
339
+ - true
340
+ - 7
341
+ - 3.14
342
+
341
343
# constants can be built-in, user-defined, or Enums
342
344
- !php/const true
343
345
- !php/const E_ALL
344
346
- !php/const PDO::FETCH_NUM
345
347
- !php/const App\Service\AnotherService::SOME_CONSTANT
346
348
- !php/const App\Config\SomeEnum::SomeCase
349
+
347
350
# when not using autowiring, you can pass service arguments explicitly
348
351
- ' @some-service-id' # the leading '@' tells this is a service ID, not a string
349
352
- ' @?some-service-id' # using '?' means to pass null if service doesn't exist
353
+
354
+ # binary contents are passed encoded as base64 strings
355
+ - !!binary VGhpcyBpcyBhIEJlbGwgY2hhciAH
356
+
350
357
# collections (arrays) can include any type of argument
351
358
-
352
359
first : !php/const true
@@ -366,20 +373,30 @@ as arguments of other services:
366
373
367
374
<services >
368
375
<service id =" App\Service\SomeService" >
369
- <!-- arguments without a type are treated as strings -->
376
+ <!-- arguments without a type can be strings or numbers -->
370
377
<argument >Foo</argument >
378
+ <argument >7</argument >
379
+ <argument >3.14</argument >
371
380
<!-- explicitly declare a string argument -->
372
381
<argument type =" string" >Foo</argument >
382
+ <!-- booleans are passed as constants -->
383
+ <argument type =" constant" >true</argument >
384
+
373
385
<!-- constants can be built-in, user-defined, or Enums -->
374
386
<argument type =" constant" >true</argument >
375
387
<argument type =" constant" >E_ALL</argument >
376
388
<argument type =" constant" >PDO::FETCH_NUM</argument >
377
389
<argument type =" constant" >App\Service\AnotherService::SOME_CONSTANT</argument >
378
390
<argument type =" constant" >App\Config\SomeEnum::SomeCase</argument >
391
+
379
392
<!-- when not using autowiring, you can pass service arguments explicitly -->
380
393
<argument type =" service"
381
394
id =" some-service-id"
382
395
on-invalid =" dependency_injection-ignore" />
396
+
397
+ <!-- binary contents are passed encoded as base64 strings -->
398
+ <argument type =" binary" >VGhpcyBpcyBhIEJlbGwgY2hhciAH</argument >
399
+
383
400
<!-- collections (arrays) can include any type of argument -->
384
401
<argument type =" collection" >
385
402
<argument key =" first" type =" constant" >true</argument >
@@ -402,18 +419,25 @@ as arguments of other services:
402
419
$services = $container->services();
403
420
404
421
$services->set(App\Service\SomeService::class)
405
- // string arguments
422
+ // string, numeric and boolean arguments can be passed "as is"
406
423
->arg(0, 'Foo')
407
- // constants: built-in, user-defined, or Enums
408
424
->arg(1, true)
409
- ->arg(2, E_ALL)
410
- ->arg(3, \PDO::FETCH_NUM)
411
- ->arg(4, \App\Service\AnotherService::SOME_CONSTANT)
412
- ->arg(5, \App\Config\SomeEnum::SomeCase)
413
- // explicit service reference with on-invalid behavior
414
- ->arg(6, new Reference('some-service-id', Reference::IGNORE_ON_INVALID_REFERENCE))
425
+ ->arg(2, 7)
426
+ ->arg(3, 3.14)
427
+
428
+ // constants: built-in, user-defined, or Enums
429
+ ->arg(4, E_ALL)
430
+ ->arg(5, \PDO::FETCH_NUM)
431
+ ->arg(6, \App\Service\AnotherService::SOME_CONSTANT)
432
+ ->arg(7, \App\Config\SomeEnum::SomeCase)
433
+
434
+ // when not using autowiring, you can pass service arguments explicitly
435
+ ->arg(8, service('some-service-id')) # fails if service doesn't exist
436
+ # passes null if service doesn't exist
437
+ ->arg(9, new Reference('some-service-id', Reference::IGNORE_ON_INVALID_REFERENCE))
438
+
415
439
// collection with mixed argument types
416
- ->arg(7 , [
440
+ ->arg(10 , [
417
441
'first' => true,
418
442
'second' => 'Foo',
419
443
]);
0 commit comments