* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShop\Module\PsxDesign\Builder; if (!defined('_PS_VERSION_')) { exit; } use PrestaShop\Module\PsxDesign\DTO\ThemeConfiguration\Color\PsxDesignColorConfiguration; class ColorsStylesheetBuilder { public function __construct() { } /** * @param PsxDesignColorConfiguration[]|null $colors * * @return string */ public function buildCssSelectorStylesheetString(?array $colors): string { if (!$colors) { return ''; } $stylesheetString = ''; foreach ($colors as $color) { $properties = $color->getProperties(); // We do not want to create bad stylesheet if no property is provided if (!$properties) { continue; } $stylesheetString .= $color->getVariableName() . '{'; foreach ($properties as $property) { $stylesheetString .= $property . ':' . $color->getValue() . ';'; } $stylesheetString .= '}'; } return $stylesheetString; } /** * @param PsxDesignColorConfiguration[]|null $colors * * @return string */ public function buildCssVariableStylesheetString(?array $colors): string { if (!$colors) { return ''; } $stylesheetString = ':root{'; foreach ($colors as $color) { $stylesheetString .= $color->getVariableName() . ':' . $color->getValue() . ';'; } return $stylesheetString . '}'; } /** * @param PsxDesignColorConfiguration[]|null $colors * * @return string */ public function buildScssVariableStylesheetString(?array $colors): string { if (!$colors) { return ''; } $stylesheetString = ''; foreach ($colors as $color) { $stylesheetString .= $color->getVariableName() . ':' . $color->getValue() . ';'; } return $stylesheetString; } }