BootstrapIconCollector.php 611 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Tools\View\Icon\Collector;
  3. use RuntimeException;
  4. /**
  5. * Using e.g. "bootstrap-icons" npm package.
  6. */
  7. class BootstrapIconCollector {
  8. /**
  9. * @param string $filePath
  10. *
  11. * @return array<string>
  12. */
  13. public static function collect(string $filePath): array {
  14. $content = file_get_contents($filePath);
  15. if ($content === false) {
  16. throw new RuntimeException('Cannot read file: ' . $filePath);
  17. }
  18. $array = json_decode($content, true);
  19. if (!$array) {
  20. throw new RuntimeException('Cannot parse JSON: ' . $filePath);
  21. }
  22. /** @var array<string> */
  23. return array_keys($array);
  24. }
  25. }