10 * This class uses Minify_CSS_Compressor and Minify_CSS_UriRewriter to
11 * minify CSS and rewrite relative URIs.
14 * @author Stephen Clay <steve@mrclay.org>
15 * @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
24 * @param array $options available options:
26 * 'preserveComments': (default true) multi-line comments that begin
27 * with "/*!" will be preserved with newlines before and after to
28 * enhance readability.
30 * 'removeCharsets': (default true) remove all @charset at-rules
32 * 'prependRelativePath': (default null) if given, this string will be
33 * prepended to all relative URIs in import/url declarations
35 * 'currentDir': (default null) if given, this is assumed to be the
36 * directory of the current CSS file. Using this, minify will rewrite
37 * all relative URIs in import/url declarations to correctly point to
38 * the desired files. For this to work, the files *must* exist and be
39 * visible by the PHP process.
41 * 'symlinks': (default = array()) If the CSS file is stored in
42 * a symlink-ed directory, provide an array of link paths to
43 * target paths, where the link paths are within the document root. Because
44 * paths need to be normalized for this to work, use "//" to substitute
45 * the doc root in the link paths (the array keys). E.g.:
47 * array('//symlink' => '/real/target/path') // unix
48 * array('//static' => 'D:\\staticStorage') // Windows
51 * 'docRoot': (default = $_SERVER['DOCUMENT_ROOT'])
52 * see Minify_CSS_UriRewriter::rewrite
56 public static function minify($css, $options = array())
58 $options = array_merge(array(
60 'removeCharsets' => true,
61 'preserveComments' => true,
63 'docRoot' => $_SERVER['DOCUMENT_ROOT'],
64 'prependRelativePath' => null,
65 'symlinks' => array(),
68 if ($options['removeCharsets']) {
69 $css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
71 if ($options['compress']) {
72 if (! $options['preserveComments']) {
73 $css = Minify_CSS_Compressor::process($css, $options);
75 $css = Minify_CommentPreserver::process(
77 ,array('Minify_CSS_Compressor', 'process')
82 if (! $options['currentDir'] && ! $options['prependRelativePath']) {
85 if ($options['currentDir']) {
86 return Minify_CSS_UriRewriter::rewrite(
88 ,$options['currentDir']
93 return Minify_CSS_UriRewriter::prepend(
95 ,$options['prependRelativePath']