Sets the arguments to pass to the service constructor/factory method.
public setArguments ( array $arguments ) : |
||
$arguments | array | An array of arguments |
return | The current instance |
use Symfony\Component\DependencyInjection\Definition; // create a new definition for the UserService class $userServiceDef = new Definition(UserService::class); // set the constructor arguments for the UserService class $userServiceDef->setArguments([ new Reference('user_repository'), new Reference('mailer'), ]);
use Symfony\Component\DependencyInjection\Definition; // create a new definition for the MyLogger class $myLoggerDef = new Definition(MyLogger::class); // set the constructor argument for the MyLogger class $myLoggerDef->setArguments(['/path/to/logs']);In this example, we created a new service definition for the MyLogger class and used the setArguments method to pass in a single argument - the path to the log file. The symfony.component.dependencyinjection package library provides tools for managing dependencies and injecting services into objects in a Symfony application.
public setArguments ( array $arguments ) : |
||
$arguments | array | An array of arguments |
return | The current instance |