ConfigTrait.php 736 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\System\Trait;
  4. use SixShop\System\ExtensionManager;
  5. trait ConfigTrait
  6. {
  7. public function __construct(private readonly ExtensionManager $extensionManager, private array $options = [])
  8. {
  9. }
  10. public function getConfig(string $key = null): mixed
  11. {
  12. if (empty($this->options)) {
  13. if (!method_exists($this, 'getExtensionID')) {
  14. return [];
  15. }
  16. $this->options = $this->extensionManager->getExtensionConfig($this->getExtensionID());
  17. }
  18. return $key ? ($this->options[$key] ?? null) : $this->options;
  19. }
  20. public function __get(string $name): mixed
  21. {
  22. return $this->getConfig($name);
  23. }
  24. }