moduleService.php 886 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\common\service;
  3. use ba\module\Server;
  4. use think\Service;
  5. use think\facade\Event;
  6. class moduleService extends Service
  7. {
  8. public function register()
  9. {
  10. $this->moduleAppInit();
  11. }
  12. public function moduleAppInit()
  13. {
  14. $installed = Server::installedList(root_path() . 'modules' . DIRECTORY_SEPARATOR);
  15. foreach ($installed as $item) {
  16. if ($item['state'] != 1) {
  17. continue;
  18. }
  19. $moduleClass = Server::getClass($item['uid']);
  20. if (class_exists($moduleClass)) {
  21. if (method_exists($moduleClass, 'AppInit')) {
  22. Event::listen('AppInit', function () use ($moduleClass) {
  23. $handle = new $moduleClass();
  24. $handle->AppInit();
  25. });
  26. }
  27. }
  28. }
  29. }
  30. }