src/FS/File/CSS/Relocator.php
public static function rewrite($css, $currentDir, $docRoot = null, $symlinks = array())
	{
		self::$_docRoot = self::_realpath(
			$docRoot ? $docRoot : $_SERVER['DOCUMENT_ROOT']
		);
		self::$_currentDir = self::_realpath($currentDir);
		self::$_symlinks = array();

		// normalize symlinks
		foreach ($symlinks as $link => $target) {
			$link = ($link === '//')
				? self::$_docRoot
				: str_replace('//', self::$_docRoot . '/', $link);
			$link = strtr($link, '/', DIRECTORY_SEPARATOR);
			self::$_symlinks[$link] = self::_realpath($target);
		}

		self::$debugText .= "docRoot    : " . self::$_docRoot . "\n"
						  . "currentDir : " . self::$_currentDir . "\n";
		if (self::$_symlinks) {
			self::$debugText .= "symlinks : " . var_export(self::$_symlinks, 1) . "\n";
		}
		self::$debugText .= "\n";

		$css = self::_trimUrls($css);

		// rewrite
		$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
			,array(self::$className, '_processUriCB'), $css);
		$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
			,array(self::$className, '_processUriCB'), $css);

		return $css;
	}
public static function rewrite($css, $currentDir, $docRoot = null, $symlinks = array())
	{
		self::$_docRoot = self::_realpath(
			$docRoot ? $docRoot : $_SERVER['DOCUMENT_ROOT']
		);
		self::$_currentDir = self::_realpath($currentDir);
		self::$_symlinks = array();

		// normalize symlinks
		foreach ($symlinks as $link => $target) {
			$link = ($link === '//')
				? self::$_docRoot
				: str_replace('//', self::$_docRoot . '/', $link);
			$link = strtr($link, '/', DIRECTORY_SEPARATOR);
			self::$_symlinks[$link] = self::_realpath($target);
		}

		self::$debugText .= "docRoot    : " . self::$_docRoot . "\n"
						  . "currentDir : " . self::$_currentDir . "\n";
		if (self::$_symlinks) {
			self::$debugText .= "symlinks : " . var_export(self::$_symlinks, 1) . "\n";
		}
		self::$debugText .= "\n";

		$css = self::_trimUrls($css);

		// rewrite
		$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
			,array(self::$className, '_processUriCB'), $css);
		$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
			,array(self::$className, '_processUriCB'), $css);

		return $css;
	}
public static function rewrite ( $ css , $ currentDir , $ docRoot = null , $ symlinks = array ( ) ) { self :: $ _docRoot = self :: _realpath ( $ docRoot ? $ docRoot : $ _SERVER [ 'DOCUMENT_ROOT' ] ) ; self :: $ _currentDir = self :: _realpath ( $ currentDir ) ; self :: $ _symlinks = array ( ) ; // normalize symlinks foreach ( $ symlinks as $ link => $ target ) { $ link = ( $ link === '//' ) ? self :: $ _docRoot : str_replace ( '//' , self :: $ _docRoot . '/' , $ link ) ; $ link = strtr ( $ link , '/' , DIRECTORY_SEPARATOR ) ; self :: $ _symlinks [ $ link ] = self :: _realpath ( $ target ) ; } self :: $ debugText .= "docRoot    : " . self :: $ _docRoot . "\n" . "currentDir : " . self :: $ _currentDir . "\n" ; if ( self :: $ _symlinks ) { self :: $ debugText .= "symlinks : " . var_export ( self :: $ _symlinks , 1 ) . "\n" ; } self :: $ debugText .= "\n" ; $ css = self :: _trimUrls ( $ css ) ; // rewrite $ css = preg_replace_callback ( '/@import\\s+([\'"])(.*?)[\'"]/' , array ( self :: $ className , '_processUriCB' ) , $ css ) ; $ css = preg_replace_callback ( '/url\\(\\s*([^\\)\\s]+)\\s*\\)/' , array ( self :: $ className , '_processUriCB' ) , $ css ) ; return $ css ; }
In CSS content, rewrite file relative URIs as root relative

@param		string		$css
@param		string		$currentDir		The directory of the current CSS file.
@param		string		$docRoot		The document root of the web site in which the CSS file resides (default = $_SERVER['DOCUMENT_ROOT']).
@param		array		$symlinks		If the CSS file is stored in a symlink-ed directory, provide an array of link paths to target paths, where the link paths are within the document root. Because paths need to be normalized for this to work, use "//" to substitute the doc root in the link paths (the array keys). E.g.:
@example
<code>
array('//symlink' => '/real/target/path') // unix
array('//static' => 'D:\\staticStorage')  // Windows
</code>
@return		string
In CSS content rewrite file relative URIs as root relative