vendor/twig/twig/src/DeprecatedCallableInfo.php line 65

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  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 Twig;
  11. /**
  12. * @author Fabien Potencier <fabien@symfony.com>
  13. */
  14. final class DeprecatedCallableInfo
  15. {
  16. private string $type;
  17. private string $name;
  18. public function __construct(
  19. private string $package,
  20. private string $version,
  21. private ?string $altName = null,
  22. private ?string $altPackage = null,
  23. private ?string $altVersion = null,
  24. ) {
  25. }
  26. public function setType(string $type): void
  27. {
  28. $this->type = $type;
  29. }
  30. public function setName(string $name): void
  31. {
  32. $this->name = $name;
  33. }
  34. public function triggerDeprecation(?string $file = null, ?int $line = null): void
  35. {
  36. $message = \sprintf('Twig %s "%s" is deprecated', ucfirst($this->type), $this->name);
  37. if ($this->altName) {
  38. $message .= \sprintf('; use "%s"', $this->altName);
  39. if ($this->altPackage) {
  40. $message .= \sprintf(' from the "%s" package', $this->altPackage);
  41. }
  42. if ($this->altVersion) {
  43. $message .= \sprintf(' (available since version %s)', $this->altVersion);
  44. }
  45. $message .= ' instead';
  46. }
  47. if ($file) {
  48. $message .= \sprintf(' in %s', $file);
  49. if ($line) {
  50. $message .= \sprintf(' at line %d', $line);
  51. }
  52. }
  53. $message .= '.';
  54. trigger_deprecation($this->package, $this->version, $message);
  55. }
  56. }