vendor/pimcore/pimcore/lib/Extension/Config.php line 41

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Pimcore
  5. *
  6. * This source file is available under two different licenses:
  7. * - GNU General Public License version 3 (GPLv3)
  8. * - Pimcore Commercial License (PCL)
  9. * Full copyright and license information is available in
  10. * LICENSE.md which is distributed with this source code.
  11. *
  12. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13. * @license http://www.pimcore.org/license GPLv3 and PCL
  14. */
  15. namespace Pimcore\Extension;
  16. use Pimcore\Config as PimcoreConfig;
  17. use Pimcore\File;
  18. /**
  19. * @internal
  20. */
  21. class Config
  22. {
  23. /**
  24. * @var PimcoreConfig\Config|null
  25. */
  26. private ?PimcoreConfig\Config $config = null;
  27. /**
  28. * @var string|null
  29. */
  30. private ?string $file = null;
  31. /**
  32. * @return PimcoreConfig\Config
  33. */
  34. public function loadConfig(): PimcoreConfig\Config
  35. {
  36. if (!$this->config) {
  37. if ($this->configFileExists()) {
  38. $this->config = new PimcoreConfig\Config(include $this->locateConfigFile(), true);
  39. }
  40. if (!$this->config) {
  41. $this->config = new PimcoreConfig\Config([], true);
  42. }
  43. }
  44. return $this->config;
  45. }
  46. /**
  47. * @param PimcoreConfig\Config $config
  48. */
  49. public function saveConfig(PimcoreConfig\Config $config)
  50. {
  51. $this->config = $config;
  52. File::putPhpFile(
  53. $this->locateConfigFile(),
  54. to_php_data_file_format($config->toArray())
  55. );
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function locateConfigFile(): string
  61. {
  62. if (null === $this->file) {
  63. $this->file = PimcoreConfig::locateConfigFile('extensions.php');
  64. }
  65. return $this->file;
  66. }
  67. /**
  68. * @return bool
  69. */
  70. public function configFileExists(): bool
  71. {
  72. $file = $this->locateConfigFile();
  73. return file_exists($file);
  74. }
  75. }