Finder.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * This file is part of the iconify.design libraries.
  4. *
  5. * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
  6. *
  7. * @license MIT
  8. *
  9. * For the full copyright and license information, please view the license.txt
  10. * file that is available in this file's directory.
  11. */
  12. namespace Iconify\IconsJSON;
  13. class Finder
  14. {
  15. /**
  16. * Get root directory of this package
  17. *
  18. * @return string
  19. */
  20. public static function rootDir()
  21. {
  22. return dirname(dirname(__FILE__));
  23. }
  24. /**
  25. * Return path to json file
  26. *
  27. * @param string $name Collection name
  28. * @return string Path to collection json file
  29. */
  30. public static function locate($name)
  31. {
  32. return dirname(dirname(__FILE__)) . '/json/' . $name . '.json';
  33. }
  34. /**
  35. * Get list of collections
  36. *
  37. * @return array|null
  38. */
  39. public static function collections()
  40. {
  41. $filename = dirname(dirname(__FILE__)) . '/collections.json';
  42. $data = @file_get_contents($filename);
  43. if (!is_string($data)) {
  44. return null;
  45. }
  46. $data = @json_decode($data, true);
  47. return is_array($data) ? $data : null;
  48. }
  49. }