| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- declare(strict_types=1);
- namespace SixShop\System\Trait;
- use SixShop\System\ExtensionManager;
- trait ConfigTrait
- {
- public function __construct(private readonly ExtensionManager $extensionManager, private array $options = [])
- {
- }
- public function getConfig(string $key = null): mixed
- {
- if (empty($this->options)) {
- if (!method_exists($this, 'getExtensionID')) {
- return [];
- }
- $this->options = $this->extensionManager->getExtensionConfig($this->getExtensionID());
- if (method_exists($this, 'getOptions')) {
- $this->options = array_merge($this->options, $this->getOptions());
- }
- }
- return $key ? ($this->options[$key] ?? null) : $this->options;
- }
- public function __get(string $name): mixed
- {
- return $this->getConfig($name);
- }
- public function __isset(string $name): bool
- {
- return $this->getConfig($name) !== null;
- }
- }
|