* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\Module\PsxDesign\Factory\ThemeConfiguration; if (!defined('_PS_VERSION_')) { exit; } use Hook; use PrestaShop\Module\PsxDesign\DTO\ThemeConfiguration\PsxDesignThemeConfiguration; class AbstractThemeConfigurationFactory { /** * @var PsxDesignThemeConfiguration|null */ protected $configurations; /** * @var string */ protected $themeName; protected function __construct(string $themeName) { $this->themeName = $themeName; $this->setThemeConfigurations($themeName); } /** * @param string $themeName * * @return void */ protected function setThemeConfigurations(string $themeName): void { if ($this->configurations) { return; } $configurations = Hook::exec('actionThemeConfiguration', [], null, true); foreach ($configurations as $config) { if (isset($config['theme']) && $config['theme'] === $themeName) { $this->configurations = PsxDesignThemeConfiguration::createFromThemeConfiguration($config); } } } /** * @param string $themeName * * @return void */ protected function setNewTheme(string $themeName): void { $this->themeName = $themeName; $this->refreshHook(); } /** * @return void */ private function refreshHook(): void { $this->configurations = null; $this->setThemeConfigurations($this->themeName); } }