container.php 755 B

1234567891011121314151617181920212223242526
  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://doc.hyperf.io
  8. * @contact [email protected]
  9. * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
  10. */
  11. use Hyperf\Di\Container;
  12. use Hyperf\Di\Definition\DefinitionSourceFactory;
  13. use Hyperf\Utils\ApplicationContext;
  14. use Psr\Container\ContainerInterface;
  15. /**
  16. * Initial a dependency injection container that implemented PSR-11 and return the container.
  17. */
  18. $container = new Container((new DefinitionSourceFactory(true))());
  19. if (! $container instanceof ContainerInterface) {
  20. throw new RuntimeException('The dependency injection container is invalid.');
  21. }
  22. return ApplicationContext::setContainer($container);