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
Copy file name to clipboardExpand all lines: docs/basic/bean-parameters.md
+23-5Lines changed: 23 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,16 @@
2
2
3
3
Bean instances can be parameterized by a given configuration. To access the configuration add a `#[Parameter]` attribute to your Bean method.
4
4
5
-
The `#[Parameter(name: 'paramName', key: 'config.key')]` attribute requires at least the `param` (which must match a param name of the Bean method) and the `key` which will be used to look for in the configuration array.
5
+
Configuration parameters can be passed to the Bean configuration method as [named](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments)
6
+
or as positional arguments. A `Parameter` will be used as a named argument when the `name` argument is set.
6
7
7
-
In the following example the value of configuration key `configKey` gets passed to the bean configuation for the argument named `$test`.
8
-
Configuration parameters are passed to the bean configuration method using [named arguments](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments):
8
+
So `#[Parameter(name: 'argName', key: 'config.key)]` is a named parameter whereas `#[Parameter(key: 'config.key')]` is a positional parameter.
9
+
As one might expect, the order of the positional parameters matter. Therefore, the recommended way of configuring parameters is using named parameters.
10
+
Named and positional parameters can be mixed.
11
+
12
+
The `#[Parameter]` attribute requires at least `key` which will be used to look for in the configuration array.
13
+
14
+
In the following example the value of configuration key `configKey` gets passed to the Bean configuration for the argument named `$test`.
9
15
10
16
```php
11
17
<?php
@@ -19,13 +25,24 @@ use bitExpert\Disco\Helper\SampleService;
19
25
class MyConfiguration
20
26
{
21
27
#[Bean]
22
-
#[Parameter(name: 'test', key: 'configKey')]
28
+
#[Parameter(name: 'test', key: 'configKey1')]
23
29
public function mySampleService(string $test = '') : SampleService
0 commit comments