Symfony\Component\DependencyInjection\Definition::addMethodCall PHP Method

addMethodCall() public method

Adds a method to call after service initialization.
public addMethodCall ( string $method, array $arguments = [] ) : Definition
$method string The method name to call
$arguments array An array of arguments to pass to the method call
return Definition The current instance
    public function addMethodCall($method, array $arguments = array())
    {
        if (empty($method)) {
            throw new InvalidArgumentException(sprintf('Method name cannot be empty.'));
        }
        $this->calls[] = array($method, $arguments);

        return $this;
    }

Usage Example

 /**
  * @param string                                                    $name
  * @param array                                                     $config
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder   $container
  *
  * @return \Symfony\Component\DependencyInjection\Reference
  */
 private function getConnectionReference($name, array $config, ContainerBuilder $container)
 {
     if (isset($config['connection_id'])) {
         return new Reference($config['connection_id']);
     }
     $host = $config['host'];
     $port = $config['port'];
     $connClass = '%doctrine_cache.redis.connection.class%';
     $connId = sprintf('doctrine_cache.services.%s_redis.connection', $name);
     $connDef = new Definition($connClass);
     $connParams = array($host, $port);
     if (isset($config['timeout'])) {
         $connParams[] = $config['timeout'];
     }
     $connDef->setPublic(false);
     $connDef->addMethodCall('connect', $connParams);
     if (isset($config['password'])) {
         $password = $config['password'];
         $connDef->addMethodCall('auth', array($password));
     }
     if (isset($config['database'])) {
         $database = (int) $config['database'];
         $connDef->addMethodCall('select', array($database));
     }
     $container->setDefinition($connId, $connDef);
     return new Reference($connId);
 }
All Usage Examples Of Symfony\Component\DependencyInjection\Definition::addMethodCall