custom/plugins/BstCatalogMode6/src/Struct/ConfigData.php line 16

Open in your IDE?
  1. <?php
  2. /**
  3.  * NOTICE OF LICENSE
  4.  *
  5.  * @copyright  Copyright (c) 01.03.2020 brainstation GbR
  6.  * @author     Mike Becker<[email protected]>
  7.  */
  8. declare(strict_types=1);
  9. namespace BstCatalogMode6\Struct;
  10. use Shopware\Core\Framework\Struct\Struct;
  11. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  12. use Shopware\Core\System\SystemConfig\SystemConfigService;
  13. class ConfigData extends Struct
  14. {
  15.     const CONFIG_NAMESPACE 'BstCatalogMode6.config.';
  16.     /**
  17.      * @var array
  18.      */
  19.     protected $config = [];
  20.     /**
  21.      * StorefrontPageData constructor.
  22.      * @param array $pluginConfig
  23.      */
  24.     public function __construct(SystemConfigService $systemConfigServiceSalesChannelContext $context)
  25.     {
  26.         $pluginConfig $systemConfigService->getDomain(self::CONFIG_NAMESPACE$context->getSalesChannel()->getId(), true);
  27.         foreach ($pluginConfig as $configKey => $value)
  28.         {
  29.             $key str_replace(self::CONFIG_NAMESPACE''$configKey);
  30.             $this->config[$key] = $value;
  31.         }
  32.     }
  33.     /**
  34.      * @return mixed
  35.      */
  36.     public function getConfig() : array
  37.     {
  38.         return $this->config;
  39.     }
  40.     /**
  41.      * @param array $config
  42.      */
  43.     public function setConfig(array $config): void
  44.     {
  45.         $this->config $config;
  46.     }
  47.     /**
  48.      * @param $name
  49.      * @return bool|mixed
  50.      */
  51.     public function __get($name)
  52.     {
  53.         $config $this->getConfig();
  54.         if (array_key_exists($name$config)) {
  55.             return $config[$name];
  56.         }
  57.         return false;
  58.     }
  59.     /**
  60.      * @param $name
  61.      * @param $value
  62.      * @return $this
  63.      */
  64.     public function __set($name$value)
  65.     {
  66.         $config $this->getConfig();
  67.         $config[$name] = $value;
  68.         $this->setConfig($config);
  69.         return $this;
  70.     }
  71. }