custom/plugins/PickwareErpStarter/vendor/pickware/shopware-extensions-bundle/src/Mail/SystemConfigServiceDecorator.php line 135

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\ShopwareExtensionsBundle\Mail;
  11. use Closure;
  12. use Shopware\Core\Framework\Bundle;
  13. use Shopware\Core\System\SystemConfig\SystemConfigService;
  14. /**
  15.  * To avoid unwanted side effects when disabling mail delivery (because the state is saved in DB)
  16.  * we need this Decorator to override the 'core.mailerSettings.disableDelivery' on request level.
  17.  * Use this Decorator in combination with the following Service:
  18.  * @see MailSendSuppressionService
  19.  */
  20. class SystemConfigServiceDecorator extends SystemConfigService
  21. {
  22.     /**
  23.      * In Shopware in src/Core/Framework/Test/TestCaseBase/SystemConfigTestBehaviour.php in
  24.      * versions <= 6.4.9.0, there is direct access to $configs: `$property = $reflection->getProperty('configs');`.
  25.      * This is why we have to declare the property, even though we do not use it, as otherwise
  26.      * tests that include src/Core/Framework/Test/TestCaseBase/IntegrationTestBehaviour.php will fail.
  27.      */
  28.     public $configs = [];
  29.     /**
  30.      * The pickware key is just saved in the current request.
  31.      */
  32.     public const PICKWARE_DISABLE_MAIL_DELIVERY 'PickwareShopwareExtensionsBundle.mailerSettings.disableDelivery';
  33.     /**
  34.      * When the user asks for the setting of 'core.mailerSettings.disableDelivery' the decorator
  35.      * checks state against the pickware custom property ($disableMailDelivery) and the original key (from database).
  36.      */
  37.     private const SHOPWARE_DISABLE_MAIL_DELIVERY 'core.mailerSettings.disableDelivery';
  38.     private SystemConfigService $decoratedSystemConfigService;
  39.     private bool $disableMailDelivery false;
  40.     public function __construct(SystemConfigService $decoratedSystemConfigService)
  41.     {
  42.         $this->decoratedSystemConfigService $decoratedSystemConfigService;
  43.     }
  44.     public function get(string $key, ?string $salesChannelId null)
  45.     {
  46.         // For 'core.mailerSettings.disableDelivery' check pickware custom override property and then shopware setting.
  47.         if ($key === self::SHOPWARE_DISABLE_MAIL_DELIVERY) {
  48.             return $this->disableMailDelivery || $this->decoratedSystemConfigService->get($key$salesChannelId);
  49.         }
  50.         return $this->decoratedSystemConfigService->get($key$salesChannelId);
  51.     }
  52.     public function getString(string $key, ?string $salesChannelId null): string
  53.     {
  54.         return $this->decoratedSystemConfigService->getString($key$salesChannelId);
  55.     }
  56.     public function getInt(string $key, ?string $salesChannelId null): int
  57.     {
  58.         return $this->decoratedSystemConfigService->getInt($key$salesChannelId);
  59.     }
  60.     public function getFloat(string $key, ?string $salesChannelId null): float
  61.     {
  62.         return $this->decoratedSystemConfigService->getFloat($key$salesChannelId);
  63.     }
  64.     public function getBool(string $key, ?string $salesChannelId null): bool
  65.     {
  66.         // For 'core.mailerSettings.disableDelivery' check pickware custom override property and then shopware setting.
  67.         if ($key === self::SHOPWARE_DISABLE_MAIL_DELIVERY) {
  68.             return $this->disableMailDelivery || $this->decoratedSystemConfigService->getBool($key$salesChannelId);
  69.         }
  70.         return $this->decoratedSystemConfigService->getBool($key$salesChannelId);
  71.     }
  72.     public function all(?string $salesChannelId null): array
  73.     {
  74.         return $this->decoratedSystemConfigService->all($salesChannelId);
  75.     }
  76.     public function getDomain(string $domain, ?string $salesChannelId nullbool $inherit false): array
  77.     {
  78.         return $this->decoratedSystemConfigService->getDomain($domain$salesChannelId$inherit);
  79.     }
  80.     public function set(string $key$value, ?string $salesChannelId null): void
  81.     {
  82.         // The pickware key is not saved in the database! The key is scoped to the request.
  83.         if ($key === self::PICKWARE_DISABLE_MAIL_DELIVERY) {
  84.             $this->disableMailDelivery = (bool) $value;
  85.             return;
  86.         }
  87.         $this->decoratedSystemConfigService->set($key$value$salesChannelId);
  88.     }
  89.     public function delete(string $key, ?string $salesChannel null): void
  90.     {
  91.         $this->decoratedSystemConfigService->delete($key$salesChannel);
  92.     }
  93.     public function savePluginConfiguration(Bundle $bundlebool $override false): void
  94.     {
  95.         $this->decoratedSystemConfigService->savePluginConfiguration($bundle$override);
  96.     }
  97.     public function saveConfig(array $configstring $prefixbool $override): void
  98.     {
  99.         $this->decoratedSystemConfigService->saveConfig($config$prefix$override);
  100.     }
  101.     public function deletePluginConfiguration(Bundle $bundle): void
  102.     {
  103.         $this->decoratedSystemConfigService->deletePluginConfiguration($bundle);
  104.     }
  105.     public function deleteExtensionConfiguration(string $extensionName, array $config): void
  106.     {
  107.         $this->decoratedSystemConfigService->deleteExtensionConfiguration($extensionName$config);
  108.     }
  109.     public function trace(string $keyClosure $param)
  110.     {
  111.         return $this->decoratedSystemConfigService->trace($key$param);
  112.     }
  113.     public function getTrace(string $key): array
  114.     {
  115.         return $this->decoratedSystemConfigService->getTrace($key);
  116.     }
  117. }