Skip to content

Commit bb5b3dc

Browse files
Krinklejdforrester
authored andcommitted
Factor out internal TOKEN_TMP and TOKEN_COMMENT constants
In preparation for v2.0.0 update, which makes use of TOKEN_COMMENT in a pattern, but the PHP port did not yet have this constant factored out. Also, whilst at it, change the token from `C` to `COMMENT` to align with the reference implementation.
1 parent f338049 commit bb5b3dc

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/CSSJanus.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
* from left-to-right (LTR) to right-to-left (RTL).
2828
*/
2929
class CSSJanus {
30+
private const TOKEN_TMP = '`TMP`';
31+
private const TOKEN_COMMENT = '`COMMENT`';
32+
3033
// Patterns defined as null are built dynamically by buildPatterns()
3134
private static $patterns = array(
3235
'tmpToken' => '`TMP`',
@@ -171,7 +174,7 @@ public static function transform($css, $options = array(), $transformEdgeInUrl =
171174
$css = $noFlipClass->tokenize($css);
172175

173176
// Tokenize comments
174-
$comments = new CSSJanusTokenizer(self::$patterns['comment'], '`C`');
177+
$comments = new CSSJanusTokenizer(self::$patterns['comment'], self::TOKEN_COMMENT);
175178
$css = $comments->tokenize($css);
176179

177180
// LTR->RTL fixes start here
@@ -214,11 +217,11 @@ public static function transform($css, $options = array(), $transformEdgeInUrl =
214217
private static function fixDirection($css) {
215218
$css = preg_replace(
216219
self::$patterns['direction_ltr'],
217-
'$1' . self::$patterns['tmpToken'],
220+
'$1' . self::TOKEN_TMP,
218221
$css
219222
);
220223
$css = preg_replace(self::$patterns['direction_rtl'], '$1ltr', $css);
221-
$css = str_replace(self::$patterns['tmpToken'], 'rtl', $css);
224+
$css = str_replace(self::TOKEN_TMP, 'rtl', $css);
222225

223226
return $css;
224227
}
@@ -229,9 +232,9 @@ private static function fixDirection($css) {
229232
* @return string
230233
*/
231234
private static function fixLtrRtlInURL($css) {
232-
$css = preg_replace(self::$patterns['ltr_in_url'], self::$patterns['tmpToken'], $css);
235+
$css = preg_replace(self::$patterns['ltr_in_url'], self::TOKEN_TMP, $css);
233236
$css = preg_replace(self::$patterns['rtl_in_url'], 'ltr', $css);
234-
$css = str_replace(self::$patterns['tmpToken'], 'rtl', $css);
237+
$css = str_replace(self::TOKEN_TMP, 'rtl', $css);
235238

236239
return $css;
237240
}
@@ -242,9 +245,9 @@ private static function fixLtrRtlInURL($css) {
242245
* @return string
243246
*/
244247
private static function fixLeftRightInURL($css) {
245-
$css = preg_replace(self::$patterns['left_in_url'], self::$patterns['tmpToken'], $css);
248+
$css = preg_replace(self::$patterns['left_in_url'], self::TOKEN_TMP, $css);
246249
$css = preg_replace(self::$patterns['right_in_url'], 'left', $css);
247-
$css = str_replace(self::$patterns['tmpToken'], 'right', $css);
250+
$css = str_replace(self::TOKEN_TMP, 'right', $css);
248251

249252
return $css;
250253
}
@@ -255,9 +258,9 @@ private static function fixLeftRightInURL($css) {
255258
* @return string
256259
*/
257260
private static function fixLeftAndRight($css) {
258-
$css = preg_replace(self::$patterns['left'], self::$patterns['tmpToken'], $css);
261+
$css = preg_replace(self::$patterns['left'], self::TOKEN_TMP, $css);
259262
$css = preg_replace(self::$patterns['right'], 'left', $css);
260-
$css = str_replace(self::$patterns['tmpToken'], 'right', $css);
263+
$css = str_replace(self::TOKEN_TMP, 'right', $css);
261264

262265
return $css;
263266
}
@@ -270,11 +273,11 @@ private static function fixLeftAndRight($css) {
270273
private static function fixCursorProperties($css) {
271274
$css = preg_replace(
272275
self::$patterns['cursor_east'],
273-
'$1' . self::$patterns['tmpToken'],
276+
'$1' . self::TOKEN_TMP,
274277
$css
275278
);
276279
$css = preg_replace(self::$patterns['cursor_west'], '$1e-resize', $css);
277-
$css = str_replace(self::$patterns['tmpToken'], 'w-resize', $css);
280+
$css = str_replace(self::TOKEN_TMP, 'w-resize', $css);
278281

279282
return $css;
280283
}

0 commit comments

Comments
 (0)