@darrion.kuhn
To inject an array of parameters in a Symfony service, you can follow these steps:
1 2 3 4 5 6 |
# services.yaml parameters: my_array_parameter: - value1 - value2 - value3 |
1 2 3 4 5 |
# services.yaml services: AppServiceMyService: arguments: - '%my_array_parameter%' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// src/Service/MyService.php namespace AppService; class MyService { private $myArray; public function __construct(array $myArray) { $this->myArray = $myArray; } // ... } |
Note: If you want to inject the array parameter into a non-service class, you can use the container
service to retrieve the values from the container.
1
|
$myArray = $container->getParameter('my_array_parameter'); |
Make sure to replace AppServiceMyService
and my_array_parameter
with your own service class and parameter name accordingly.