10 * This class uses Minify_CSS_Compressor and Minify_CSS_UriRewriter to
\r
11 * minify CSS and rewrite relative URIs.
\r
14 * @author Stephen Clay <steve@mrclay.org>
\r
15 * @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
\r
20 * Minify a CSS string
\r
22 * @param string $css
\r
24 * @param array $options available options:
\r
26 * 'preserveComments': (default true) multi-line comments that begin
\r
27 * with "/*!" will be preserved with newlines before and after to
\r
28 * enhance readability.
\r
30 * 'prependRelativePath': (default null) if given, this string will be
\r
31 * prepended to all relative URIs in import/url declarations
\r
33 * 'currentDir': (default null) if given, this is assumed to be the
\r
34 * directory of the current CSS file. Using this, minify will rewrite
\r
35 * all relative URIs in import/url declarations to correctly point to
\r
36 * the desired files. For this to work, the files *must* exist and be
\r
37 * visible by the PHP process.
\r
39 * 'symlinks': (default = array()) If the CSS file is stored in
40 * a symlink-ed directory, provide an array of link paths to
41 * target paths, where the link paths are within the document root. Because
42 * paths need to be normalized for this to work, use "//" to substitute
43 * the doc root in the link paths (the array keys). E.g.:
45 * array('//symlink' => '/real/target/path') // unix
46 * array('//static' => 'D:\\staticStorage') // Windows
51 public static function minify($css, $options = array())
\r
53 require_once 'Minify/CSS/Compressor.php';
\r
54 if (isset($options['preserveComments'])
\r
55 && !$options['preserveComments']) {
\r
56 $css = Minify_CSS_Compressor::process($css, $options);
\r
58 require_once 'Minify/CommentPreserver.php';
\r
59 $css = Minify_CommentPreserver::process(
\r
61 ,array('Minify_CSS_Compressor', 'process')
\r
65 if (! isset($options['currentDir']) && ! isset($options['prependRelativePath'])) {
\r
68 require_once 'Minify/CSS/UriRewriter.php';
\r
69 if (isset($options['currentDir'])) {
\r
70 return Minify_CSS_UriRewriter::rewrite(
\r
72 ,$options['currentDir']
\r
73 ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
\r
74 ,isset($options['symlinks']) ? $options['symlinks'] : array()
\r
77 return Minify_CSS_UriRewriter::prepend(
\r
79 ,$options['prependRelativePath']
\r