Просмотр файла app/Factories/ContainerFactory.php

Размер файла: 1.28Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Factories;
  6.  
  7. use DI\Container;
  8. use Psr\Container\ContainerInterface;
  9.  
  10. /**
  11. * Container Factory.
  12. */
  13. class ContainerFactory extends Container
  14. {
  15. protected static ?ContainerInterface $instance = null;
  16.  
  17. /**
  18. * Create the shared instance of the container.
  19. *
  20. * @return ContainerInterface
  21. */
  22. public static function createInstance(): ContainerInterface
  23. {
  24. $container = require __DIR__ . '/../../app/container.php';
  25.  
  26. return static::$instance = $container;
  27. }
  28.  
  29. /**
  30. * Get the globally available instance of the container
  31. *
  32. * @return ContainerInterface
  33. */
  34. public static function getInstance(): ContainerInterface
  35. {
  36. if (static::$instance === null) {
  37. static::$instance = static::createInstance();
  38. }
  39.  
  40. return static::$instance;
  41. }
  42.  
  43. /**
  44. * Get container.
  45. *
  46. * @return ContainerInterface|Container The container
  47. */
  48. /*public function createInstance(): ContainerInterface
  49. {
  50. $containerBuilder = new ContainerBuilder();
  51.  
  52. // Set up settings
  53. $containerBuilder->addDefinitions(__DIR__ . '/../../config/container.php');
  54.  
  55. // Build PHP-DI Container instance
  56. return $containerBuilder->build();
  57. }*/
  58. }