RegisterService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace think\initializer;
  13. use think\App;
  14. use think\service\ModelService;
  15. use think\service\PaginatorService;
  16. use think\service\ValidateService;
  17. /**
  18. * 注册系统服务
  19. */
  20. class RegisterService
  21. {
  22. protected $services = [
  23. PaginatorService::class,
  24. ValidateService::class,
  25. ModelService::class,
  26. ];
  27. public function init(App $app)
  28. {
  29. $file = $app->getRootPath() . 'vendor/services.php';
  30. $services = $this->services;
  31. if (is_file($file)) {
  32. $services = array_merge($services, include $file);
  33. }
  34. foreach ($services as $service) {
  35. if (class_exists($service)) {
  36. $app->register($service);
  37. }
  38. }
  39. }
  40. }