src/CSSJanus.php
public static function transform($css, $options = array(), $transformEdgeInUrl = false) {
		if (!is_array($options)) {
			$options = array(
				'transformDirInUrl' => (bool)$options,
				'transformEdgeInUrl' => (bool)$transformEdgeInUrl,
			);
		}

		// Defaults
		$options += array(
			'transformDirInUrl' => false,
			'transformEdgeInUrl' => false,
		);

		// We wrap tokens in ` , not ~ like the original implementation does.
		// This was done because ` is not a legal character in CSS and can only
		// occur in URLs, where we escape it to %60 before inserting our tokens.
		$css = str_replace('`', '%60', $css);

		self::buildPatterns();

		// Tokenize single line rules with /* @noflip */
		$noFlipSingle = new CSSJanusTokenizer(self::$patterns['noflip_single'], '`NOFLIP_SINGLE`');
		$css = $noFlipSingle->tokenize($css);

		// Tokenize class rules with /* @noflip */
		$noFlipClass = new CSSJanusTokenizer(self::$patterns['noflip_class'], '`NOFLIP_CLASS`');
		$css = $noFlipClass->tokenize($css);

		// Tokenize comments
		$comments = new CSSJanusTokenizer(self::$patterns['comment'], '`C`');
		$css = $comments->tokenize($css);

		// LTR->RTL fixes start here
		$css = self::fixDirection($css);
		if ($options['transformDirInUrl']) {
			$css = self::fixLtrRtlInURL($css);
		}

		if ($options['transformEdgeInUrl']) {
			$css = self::fixLeftRightInURL($css);
		}
		$css = self::fixLeftAndRight($css);
		$css = self::fixCursorProperties($css);
		$css = self::fixFourPartNotation($css);
		$css = self::fixBorderRadius($css);
		$css = self::fixBackgroundPosition($css);
		$css = self::fixShadows($css);
		$css = self::fixTranslate($css);

		// Detokenize stuff we tokenized before
		$css = $comments->detokenize($css);
		$css = $noFlipClass->detokenize($css);
		$css = $noFlipSingle->detokenize($css);

		return $css;
	}
public static function transform($css, $options = array(), $transformEdgeInUrl = false) {
		if (!is_array($options)) {
			$options = array(
				'transformDirInUrl' => (bool)$options,
				'transformEdgeInUrl' => (bool)$transformEdgeInUrl,
			);
		}

		// Defaults
		$options += array(
			'transformDirInUrl' => false,
			'transformEdgeInUrl' => false,
		);

		// We wrap tokens in ` , not ~ like the original implementation does.
		// This was done because ` is not a legal character in CSS and can only
		// occur in URLs, where we escape it to %60 before inserting our tokens.
		$css = str_replace('`', '%60', $css);

		self::buildPatterns();

		// Tokenize single line rules with /* @noflip */
		$noFlipSingle = new CSSJanusTokenizer(self::$patterns['noflip_single'], '`NOFLIP_SINGLE`');
		$css = $noFlipSingle->tokenize($css);

		// Tokenize class rules with /* @noflip */
		$noFlipClass = new CSSJanusTokenizer(self::$patterns['noflip_class'], '`NOFLIP_CLASS`');
		$css = $noFlipClass->tokenize($css);

		// Tokenize comments
		$comments = new CSSJanusTokenizer(self::$patterns['comment'], '`C`');
		$css = $comments->tokenize($css);

		// LTR->RTL fixes start here
		$css = self::fixDirection($css);
		if ($options['transformDirInUrl']) {
			$css = self::fixLtrRtlInURL($css);
		}

		if ($options['transformEdgeInUrl']) {
			$css = self::fixLeftRightInURL($css);
		}
		$css = self::fixLeftAndRight($css);
		$css = self::fixCursorProperties($css);
		$css = self::fixFourPartNotation($css);
		$css = self::fixBorderRadius($css);
		$css = self::fixBackgroundPosition($css);
		$css = self::fixShadows($css);
		$css = self::fixTranslate($css);

		// Detokenize stuff we tokenized before
		$css = $comments->detokenize($css);
		$css = $noFlipClass->detokenize($css);
		$css = $noFlipSingle->detokenize($css);

		return $css;
	}
public static function transform ( $ css , $ options = array ( ) , $ transformEdgeInUrl = false ) { if ( ! is_array ( $ options ) ) { $ options = array ( 'transformDirInUrl' => ( bool ) $ options , 'transformEdgeInUrl' => ( bool ) $ transformEdgeInUrl , ) ; } // Defaults $ options += array ( 'transformDirInUrl' => false , 'transformEdgeInUrl' => false , ) ; // We wrap tokens in ` , not ~ like the original implementation does. // This was done because ` is not a legal character in CSS and can only // occur in URLs, where we escape it to %60 before inserting our tokens. $ css = str_replace ( '`' , '%60' , $ css ) ; self :: buildPatterns ( ) ; // Tokenize single line rules with /* @noflip */ $ noFlipSingle = new CSSJanusTokenizer ( self :: $ patterns [ 'noflip_single' ] , '`NOFLIP_SINGLE`' ) ; $ css = $ noFlipSingle -> tokenize ( $ css ) ; // Tokenize class rules with /* @noflip */ $ noFlipClass = new CSSJanusTokenizer ( self :: $ patterns [ 'noflip_class' ] , '`NOFLIP_CLASS`' ) ; $ css = $ noFlipClass -> tokenize ( $ css ) ; // Tokenize comments $ comments = new CSSJanusTokenizer ( self :: $ patterns [ 'comment' ] , '`C`' ) ; $ css = $ comments -> tokenize ( $ css ) ; // LTR->RTL fixes start here $ css = self :: fixDirection ( $ css ) ; if ( $ options [ 'transformDirInUrl' ] ) { $ css = self :: fixLtrRtlInURL ( $ css ) ; } if ( $ options [ 'transformEdgeInUrl' ] ) { $ css = self :: fixLeftRightInURL ( $ css ) ; } $ css = self :: fixLeftAndRight ( $ css ) ; $ css = self :: fixCursorProperties ( $ css ) ; $ css = self :: fixFourPartNotation ( $ css ) ; $ css = self :: fixBorderRadius ( $ css ) ; $ css = self :: fixBackgroundPosition ( $ css ) ; $ css = self :: fixShadows ( $ css ) ; $ css = self :: fixTranslate ( $ css ) ; // Detokenize stuff we tokenized before $ css = $ comments -> detokenize ( $ css ) ; $ css = $ noFlipClass -> detokenize ( $ css ) ; $ css = $ noFlipSingle -> detokenize ( $ css ) ; return $ css ; }
Transform an LTR stylesheet to RTL
@param string $css Stylesheet to transform
@param array|bool $options Options array or value of transformDirInUrl option (back-compat)
@param bool $options['transformDirInUrl'] Transform directions in URLs (ltr/rtl). Default: false.
@param bool $options['transformEdgeInUrl'] Transform edges in URLs (left/right). Default: false.
@param bool $transformEdgeInUrl [optional] For back-compat
@return string Transformed stylesheet
Transform an LTR stylesheet to RTL