Scripts.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Intl;
  11. use Symfony\Component\Intl\Exception\MissingResourceException;
  12. /**
  13. * Gives access to script-related ICU data.
  14. *
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. * @author Roland Franssen <franssen.roland@gmail.com>
  17. */
  18. final class Scripts extends ResourceBundle
  19. {
  20. /**
  21. * @return string[]
  22. */
  23. public static function getScriptCodes(): array
  24. {
  25. return self::readEntry(['Scripts'], 'meta');
  26. }
  27. public static function exists(string $script): bool
  28. {
  29. try {
  30. self::readEntry(['Names', $script]);
  31. return true;
  32. } catch (MissingResourceException $e) {
  33. return false;
  34. }
  35. }
  36. /**
  37. * @throws MissingResourceException if the script code does not exist
  38. */
  39. public static function getName(string $script, string $displayLocale = null): string
  40. {
  41. return self::readEntry(['Names', $script], $displayLocale);
  42. }
  43. /**
  44. * @return string[]
  45. */
  46. public static function getNames($displayLocale = null): array
  47. {
  48. return self::asort(self::readEntry(['Names'], $displayLocale), $displayLocale);
  49. }
  50. protected static function getPath(): string
  51. {
  52. return Intl::getDataDirectory().'/'.Intl::SCRIPT_DIR;
  53. }
  54. }