DefinitionSourceFactory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Di\Definition;
  12. use Hyperf\Config\ProviderConfig;
  13. use Hyperf\Di\Exception\Exception;
  14. class DefinitionSourceFactory
  15. {
  16. public function __invoke(): DefinitionSource
  17. {
  18. if (! defined('BASE_PATH')) {
  19. throw new Exception('BASE_PATH is not defined.');
  20. }
  21. $configFromProviders = [];
  22. if (class_exists(ProviderConfig::class)) {
  23. $configFromProviders = ProviderConfig::load();
  24. }
  25. $serverDependencies = $configFromProviders['dependencies'] ?? [];
  26. $dependenciesPath = BASE_PATH . '/config/autoload/dependencies.php';
  27. if (file_exists($dependenciesPath)) {
  28. $definitions = include $dependenciesPath;
  29. $serverDependencies = array_replace($serverDependencies, $definitions ?? []);
  30. }
  31. return new DefinitionSource($serverDependencies);
  32. }
  33. }