I have an easy one (I think).
I have a Silex application...I created a service services.yml file, with my services with their arguments. Of coruse, arguments can be instance of another classes:
services:
Service:
class: App\Services\xxxxxService
arguments:
- App\Lib\Parser\JsonParser
- xxxxxx
So, in my init application, I have this piece of code:
$services = $this['config']['services'];
foreach ($services as $name => $service) {
$className = $service['class'];
$args = array_map(function ($arg) {
if(class_exists($arg)){
return new $arg;
} else {
return $arg;
}
}, $service['arguments']);
$args = implode(',', $args);
$this[$name] = new $className($this, $args);
}
This code gives me the error:
Catchable fatal error: Object of class App\Lib\Parser\JsonParser could not be converted to string in /app/src/Application.php on line 252
My goal is to have $this[$name] = new $className($this, $args[0], $args[1] ....) , but I cant use implode function.
Any ideas???
Thank you in advance!!
M.