mailpoet
/
vendor
/
woocommerce
/
email-editor
/
src
/
Engine
/
Renderer
/
ContentRenderer
/
class-preset-variable-resolver.php
mailpoet
/
vendor
/
woocommerce
/
email-editor
/
src
/
Engine
/
Renderer
/
ContentRenderer
Last commit date
Layout
4 days ago
Postprocessors
11 months ago
Preprocessors
2 weeks ago
class-block-renderer.php
11 months ago
class-blocks-parser.php
11 months ago
class-content-renderer.php
4 days ago
class-preset-variable-resolver.php
3 months ago
class-process-manager.php
3 months ago
class-rendering-context.php
3 months ago
content.css
11 months ago
index.php
11 months ago
class-preset-variable-resolver.php
26 lines
| 1 | <?php |
| 2 | declare(strict_types = 1); |
| 3 | namespace Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | class Preset_Variable_Resolver { |
| 6 | private static function to_css_variable_name( string $value ): string { |
| 7 | return '--wp--' . str_replace( '|', '--', str_replace( 'var:', '', $value ) ); |
| 8 | } |
| 9 | public static function is_preset_reference( string $value ): bool { |
| 10 | return strpos( $value, 'var:preset|' ) === 0; |
| 11 | } |
| 12 | public static function resolve( string $value, array $variables_map ): string { |
| 13 | if ( empty( $variables_map ) || ! self::is_preset_reference( $value ) ) { |
| 14 | return $value; |
| 15 | } |
| 16 | $css_var_name = self::to_css_variable_name( $value ); |
| 17 | return $variables_map[ $css_var_name ] ?? $value; |
| 18 | } |
| 19 | public static function to_css_var( string $value ): string { |
| 20 | if ( ! self::is_preset_reference( $value ) ) { |
| 21 | return $value; |
| 22 | } |
| 23 | return 'var(' . self::to_css_variable_name( $value ) . ')'; |
| 24 | } |
| 25 | } |
| 26 |