123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- /**
- * Initial a dependency injection container that implemented PSR-11 and return the container.
- */
- declare(strict_types=1);
- /**
- * This file is part of Hyperf.
- *
- * @link https://www.hyperf.io
- * @document https://doc.hyperf.io
- * @contact [email protected]
- * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
- */
- use Hyperf\Config\ProviderConfig;
- use Hyperf\Di\Annotation\Scanner;
- use Hyperf\Di\Container;
- use Hyperf\Di\Definition\DefinitionSource;
- use Hyperf\Utils\ApplicationContext;
- $configFromProviders = ProviderConfig::load();
- $definitions = include __DIR__ . '/dependencies.php';
- $serverDependencies = array_replace($configFromProviders['dependencies'] ?? [], $definitions['dependencies'] ?? []);
- $annotations = include __DIR__ . '/autoload/annotations.php';
- $scanDirs = $configFromProviders['scan']['paths'];
- $scanDirs = array_merge($scanDirs, $annotations['scan']['paths'] ?? []);
- $ignoreAnnotations = $annotations['scan']['ignore_annotations'] ?? ['mixin'];
- $container = new Container(new DefinitionSource($serverDependencies, $scanDirs, new Scanner($ignoreAnnotations)));
- if (! $container instanceof \Psr\Container\ContainerInterface) {
- throw new RuntimeException('The dependency injection container is invalid.');
- }
- return ApplicationContext::setContainer($container);
|