Schedule.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace core\dict;
  12. class Schedule extends BaseDict
  13. {
  14. /**
  15. * 加载计划任务调度
  16. * @param array $data
  17. * @return array|mixed
  18. */
  19. public function load(array $data = [])
  20. {
  21. $addon = $data['addon'] ?? '';
  22. $schedule_files = [];
  23. if (empty($addon)) {
  24. $system_path = $this->getDictPath() . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
  25. if (is_file($system_path)) {
  26. $schedule_files[] = $system_path;
  27. }
  28. $addons = $this->getLocalAddons();
  29. foreach ($addons as $v) {
  30. $addon_path = $this->getAddonDictPath($v) . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
  31. if (is_file($addon_path)) {
  32. $schedule_files[] = $addon_path;
  33. }
  34. }
  35. } else {
  36. $schedule_files = [];
  37. if ($addon == 'system') {
  38. $system_path = $this->getDictPath() . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
  39. if (is_file($system_path)) {
  40. $schedule_files[] = $system_path;
  41. }
  42. } else {
  43. $addon_path = $this->getAddonDictPath($addon) . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php';
  44. if (is_file($addon_path)) {
  45. $schedule_files[] = $addon_path;
  46. }
  47. }
  48. }
  49. $schedule_files_data = $this->loadFiles($schedule_files);
  50. $schedule_data_array = [];
  51. foreach ($schedule_files_data as $file_data) {
  52. $schedule_data_array = empty($schedule_data_array) ? $file_data : array_merge($schedule_data_array, $file_data);
  53. }
  54. return $schedule_data_array;
  55. }
  56. }