EnvironmentFactory.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App;
  7. use Magento\Framework\App\ObjectManager\Environment\Compiled;
  8. use Magento\Framework\App\ObjectManager\Environment\Developer;
  9. use Magento\Framework\App\ObjectManager\ConfigLoader;
  10. use Magento\Framework\ObjectManager\RelationsInterface;
  11. use Magento\Framework\ObjectManager\DefinitionInterface;
  12. class EnvironmentFactory
  13. {
  14. /**
  15. * @var RelationsInterface
  16. */
  17. private $relations;
  18. /**
  19. * @var DefinitionInterface
  20. */
  21. private $definitions;
  22. /**
  23. * @param RelationsInterface $relations
  24. * @param DefinitionInterface $definitions
  25. */
  26. public function __construct(
  27. RelationsInterface $relations,
  28. DefinitionInterface $definitions
  29. ) {
  30. $this->relations = $relations;
  31. $this->definitions = $definitions;
  32. }
  33. /**
  34. * Create Environment object
  35. *
  36. * @return EnvironmentInterface
  37. */
  38. public function createEnvironment()
  39. {
  40. switch ($this->getMode()) {
  41. case Compiled::MODE:
  42. return new Compiled($this);
  43. break;
  44. default:
  45. return new Developer($this);
  46. }
  47. }
  48. /**
  49. * Determinate running mode
  50. *
  51. * @return string
  52. */
  53. private function getMode()
  54. {
  55. if (file_exists(ConfigLoader\Compiled::getFilePath(Area::AREA_GLOBAL))) {
  56. return Compiled::MODE;
  57. }
  58. return Developer::MODE;
  59. }
  60. /**
  61. * Returns definitions
  62. *
  63. * @return DefinitionInterface
  64. */
  65. public function getDefinitions()
  66. {
  67. return $this->definitions;
  68. }
  69. /**
  70. * Returns relations
  71. *
  72. * @return RelationsInterface
  73. */
  74. public function getRelations()
  75. {
  76. return $this->relations;
  77. }
  78. }