ContainerFactory.php 784 B

12345678910111213141516171819202122232425262728293031323334
  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\Pimple;
  12. use Hyperf\Context\ApplicationContext;
  13. use Pimple;
  14. class ContainerFactory
  15. {
  16. public function __construct(protected array $providers = [])
  17. {
  18. }
  19. public function __invoke()
  20. {
  21. $container = new Container(new Pimple\Container());
  22. foreach ($this->providers as $provider) {
  23. /** @var ProviderInterface $instance */
  24. $instance = new $provider();
  25. $instance->register($container);
  26. }
  27. return ApplicationContext::setContainer($container);
  28. }
  29. }