vendor/contao/manager-plugin/src/Bundle/Config/BundleConfig.php line 152

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of Contao.
  5. *
  6. * (c) Leo Feyer
  7. *
  8. * @license LGPL-3.0-or-later
  9. */
  10. namespace Contao\ManagerPlugin\Bundle\Config;
  11. use Symfony\Component\HttpKernel\KernelInterface;
  12. class BundleConfig implements ConfigInterface
  13. {
  14. /**
  15. * @var string
  16. */
  17. protected $name;
  18. /**
  19. * @var array
  20. */
  21. protected $replace = [];
  22. /**
  23. * @var array
  24. */
  25. protected $loadAfter = [];
  26. /**
  27. * @var bool
  28. */
  29. protected $loadInProduction = true;
  30. /**
  31. * @var bool
  32. */
  33. protected $loadInDevelopment = true;
  34. public function __construct(string $name)
  35. {
  36. $this->name = $name;
  37. }
  38. public static function __set_state(array $properties)
  39. {
  40. $config = new static($properties['name']);
  41. $config->setReplace($properties['replace']);
  42. $config->setLoadAfter($properties['loadAfter']);
  43. $config->setLoadInProduction($properties['loadInProduction']);
  44. $config->setLoadInDevelopment($properties['loadInDevelopment']);
  45. return $config;
  46. }
  47. public static function create(string $name): self
  48. {
  49. return new static($name);
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getName(): string
  55. {
  56. return $this->name;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function getReplace(): array
  62. {
  63. return $this->replace;
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function setReplace(array $replace): self
  69. {
  70. $this->replace = $replace;
  71. sort($this->replace);
  72. return $this;
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function getLoadAfter(): array
  78. {
  79. return $this->loadAfter;
  80. }
  81. /**
  82. * {@inheritdoc}
  83. */
  84. public function setLoadAfter(array $loadAfter): self
  85. {
  86. $this->loadAfter = $loadAfter;
  87. sort($this->loadAfter);
  88. return $this;
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function loadInProduction(): bool
  94. {
  95. return $this->loadInProduction;
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function setLoadInProduction($loadInProduction): self
  101. {
  102. $this->loadInProduction = (bool) $loadInProduction;
  103. return $this;
  104. }
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function loadInDevelopment(): bool
  109. {
  110. return $this->loadInDevelopment;
  111. }
  112. /**
  113. * {@inheritdoc}
  114. */
  115. public function setLoadInDevelopment($loadInDevelopment): self
  116. {
  117. $this->loadInDevelopment = (bool) $loadInDevelopment;
  118. return $this;
  119. }
  120. /**
  121. * {@inheritdoc}
  122. */
  123. public function getBundleInstance(KernelInterface $kernel)
  124. {
  125. if (!class_exists($this->name)) {
  126. throw new \LogicException(sprintf('The Symfony bundle "%s" does not exist.', $this->name));
  127. }
  128. return new $this->name();
  129. }
  130. }