SignalMap.php 906 B

123456789101112131415161718192021222324252627282930313233343536
  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\Console\SignalRegistry;
  11. /**
  12. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  13. */
  14. class SignalMap
  15. {
  16. private static array $map;
  17. public static function getSignalName(int $signal): ?string
  18. {
  19. if (!\extension_loaded('pcntl')) {
  20. return null;
  21. }
  22. if (!isset(self::$map)) {
  23. $r = new \ReflectionExtension('pcntl');
  24. $c = $r->getConstants();
  25. $map = array_filter($c, fn ($k) => str_starts_with($k, 'SIG') && !str_starts_with($k, 'SIG_'), \ARRAY_FILTER_USE_KEY);
  26. self::$map = array_flip($map);
  27. }
  28. return self::$map[$signal] ?? null;
  29. }
  30. }