DeprecateTrait.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 DeprecateTrait
  13. {
  14. /**
  15. * Whether this definition is deprecated, that means it should not be called anymore.
  16. *
  17. * @param string $package The name of the composer package that is triggering the deprecation
  18. * @param string $version The version of the package that introduced the deprecation
  19. * @param string $message The deprecation message to use
  20. *
  21. * @return $this
  22. *
  23. * @throws InvalidArgumentException when the message template is invalid
  24. */
  25. final public function deprecate(/* string $package, string $version, string $message */): self
  26. {
  27. $args = \func_get_args();
  28. $package = $version = $message = '';
  29. if (\func_num_args() < 3) {
  30. trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);
  31. $message = (string) ($args[0] ?? null);
  32. } else {
  33. $package = (string) $args[0];
  34. $version = (string) $args[1];
  35. $message = (string) $args[2];
  36. }
  37. $this->definition->setDeprecated($package, $version, $message);
  38. return $this;
  39. }
  40. }