PreInstall.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\libs;
  3. use Illuminate\Support\Env;
  4. use Illuminate\Support\Facades\Config;
  5. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  6. /**
  7. * @desc 预设文件加载
  8. * @package lc
  9. */
  10. Class PreInstall
  11. {
  12. private static $data = [];
  13. /**
  14. * @desc 获得配置
  15. * @param string $type 扩展名称
  16. * @return array|mixed
  17. */
  18. public static function config(string $type)
  19. {
  20. $id = Env::get($type . '.id', Config::get('lc.' . $type . '.id'));
  21. if (!$id) {
  22. return [];
  23. }
  24. return self::get($type, $id);
  25. }
  26. /**
  27. * @desc 获取指定配置
  28. * @param string $type 扩展名称
  29. * @param string|null $id 指定id
  30. * @return array|mixed
  31. */
  32. public static function get(string $type, string $id = null)
  33. {
  34. if (!isset($data[$type])) {
  35. self::load($type);
  36. }
  37. if (!isset(self::$data[$type])) {
  38. return [];
  39. }
  40. $data = self::$data[$type];
  41. if ($id) {
  42. return isset($data[$id]) ? $data[$id] : [];
  43. }
  44. return $data;
  45. }
  46. private static function load($type)
  47. {
  48. $file = __DIR__ . '/preinstall/' . $type . '.php';
  49. if (!file_exists($file)) {
  50. throw new FileException('SWDZ预设文件不存在:' . $file);
  51. }
  52. self::$data[$type] = include $file;
  53. }
  54. }