CallTrait.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
  11. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  12. trait CallTrait
  13. {
  14. /**
  15. * Adds a method to call after service initialization.
  16. *
  17. * @param string $method The method name to call
  18. * @param array $arguments An array of arguments to pass to the method call
  19. * @param bool $returnsClone Whether the call returns the service instance or not
  20. *
  21. * @return $this
  22. *
  23. * @throws InvalidArgumentException on empty $method param
  24. */
  25. final public function call(string $method, array $arguments = [], bool $returnsClone = false): self
  26. {
  27. $this->definition->addMethodCall($method, static::processValue($arguments, true), $returnsClone);
  28. return $this;
  29. }
  30. }