WidgetsConfig.php 780 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace app\frontend\widgets;
  3. use app\common\helpers\Cache;
  4. class WidgetsConfig
  5. {
  6. private static $config;
  7. public static function getConfig(string $type) :array
  8. {
  9. if (!isset(static::$config)) {
  10. static::$config = Cache::remember('frontend_widget_config',86400,function () {
  11. $plugins = app('plugins')->getEnabledPlugins();
  12. static::$config = [];
  13. foreach ($plugins as $plugin) {
  14. foreach ($plugin->app()->getFrontendWidgetConfig() as $key => $item) {
  15. array_set(static::$config, $key, $item);
  16. }
  17. }
  18. return static::$config;
  19. });
  20. }
  21. return static::$config[$type] ?? [];
  22. }
  23. }