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
* 'prependRelativePath': (default null) if given, this string will be
31
* prepended to all relative URIs in import/url declarations
33
* 'currentDir': (default null) if given, this is assumed to be the
34
* directory of the current CSS file. Using this, minify will rewrite
35
* all relative URIs in import/url declarations to correctly point to
36
* the desired files. For this to work, the files *must* exist and be
37
* visible by the PHP process.
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())
53
require_once 'Minify/CSS/Compressor.php';
54
if (isset($options['preserveComments'])
55
&& !$options['preserveComments']) {
56
$css = Minify_CSS_Compressor::process($css, $options);
58
require_once 'Minify/CommentPreserver.php';
59
$css = Minify_CommentPreserver::process(
61
,array('Minify_CSS_Compressor', 'process')
65
if (! isset($options['currentDir']) && ! isset($options['prependRelativePath'])) {
68
require_once 'Minify/CSS/UriRewriter.php';
69
if (isset($options['currentDir'])) {
70
return Minify_CSS_UriRewriter::rewrite(
72
,$options['currentDir']
73
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
74
,isset($options['symlinks']) ? $options['symlinks'] : array()
77
return Minify_CSS_UriRewriter::prepend(
79
,$options['prependRelativePath']
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(
59
'removeCharsets' => true,
60
'preserveComments' => true,
62
'docRoot' => $_SERVER['DOCUMENT_ROOT'],
63
'prependRelativePath' => null,
64
'symlinks' => array(),
67
if ($options['removeCharsets']) {
68
$css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
70
require_once 'Minify/CSS/Compressor.php';
71
if (! $options['preserveComments']) {
72
$css = Minify_CSS_Compressor::process($css, $options);
74
require_once 'Minify/CommentPreserver.php';
75
$css = Minify_CommentPreserver::process(
77
,array('Minify_CSS_Compressor', 'process')
81
if (! $options['currentDir'] && ! $options['prependRelativePath']) {
84
require_once 'Minify/CSS/UriRewriter.php';
85
if ($options['currentDir']) {
86
return Minify_CSS_UriRewriter::rewrite(
88
,$options['currentDir']
93
return Minify_CSS_UriRewriter::prepend(
95
,$options['prependRelativePath']