← All changes
|
modules/atomic-widgets/css-converter/shorthand-expander-base.php
+34
-1
4.2.0-beta1
→
trunk
View file →
| @@ -23,6 +23,39 @@ | ||
| 23 | 23 | |
| 24 | 24 | return in_array( $property, $this->get_supported_properties(), true ); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - abstract public function expand( array $rule ): array; | |
| 27 | + public function expand( array $rule ): array { | |
| 28 | + if ( null === $rule['value'] ) { | |
| 29 | + return $this->expand_null( $rule ); | |
| 30 | + } | |
| 31 | + | |
| 32 | + return $this->do_expand( $rule ); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Override to fan out null resets to all longhand properties. | |
| 37 | + * Default: re-emit the same property with a null value (covers simple renamers). | |
| 38 | + * | |
| 39 | + * @return array<int, array{property: string, value: null, declaration: string}> | |
| 40 | + */ | |
| 41 | + protected function expand_null( array $rule ): array { | |
| 42 | + return [ $this->null_rule( $rule['property'] ) ]; | |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @return array{property: string, value: null, declaration: string} | |
| 47 | + */ | |
| 48 | + protected function null_rule( string $property ): array { | |
| 49 | + return [ | |
| 50 | + 'property' => $property, | |
| 51 | + 'value' => null, | |
| 52 | + 'declaration' => $property . ': ', | |
| 53 | + ]; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @param array{property: string, value: string} $rule A rule with a guaranteed non-null value. | |
| 58 | + * @return array<int, array{property: string, value: string, declaration: string}> | |
| 59 | + */ | |
| 60 | + abstract protected function do_expand( array $rule ): array; | |
| 28 | 61 | } |