@@ -33,6 +33,15 @@ class Environment implements \ArrayAccess
3333 public $ postProcessors ;
3434 public $ bundleProcessors ;
3535
36+ public $ compressors = array (
37+ "uglify_js " => "\\Pipe \\Compressor \\UglifyJs " ,
38+ "yuglify_css " => "\\Pipe \\Compressor \\YuglifyCss " ,
39+ "yuglify_js " => "\\Pipe \\Compressor \\YuglifyJs " ,
40+ );
41+
42+ protected $ jsCompressor ;
43+ protected $ cssCompressor ;
44+
3645 function __construct ($ root = null )
3746 {
3847 $ this ->root = $ root ;
@@ -121,6 +130,43 @@ function find($logicalPath, $options = array())
121130 return $ asset ;
122131 }
123132
133+ function setJsCompressor ($ compressor )
134+ {
135+ if (!isset ($ this ->compressors [$ compressor ])) {
136+ throw new \InvalidArgumentException (sprintf ('Undefined compressor "%s" ' , $ compressor ));
137+ }
138+
139+ $ js = $ this ->contentType ('.js ' );
140+
141+ if ($ this ->jsCompressor !== null ) {
142+ $ this ->bundleProcessors ->unregister ($ js , $ this ->jsCompressor );
143+ }
144+
145+ $ this ->jsCompressor = $ compressor ;
146+ $ this ->bundleProcessors ->register ($ js , $ this ->compressors [$ compressor ]);
147+ }
148+
149+ function setCssCompressor ($ compressor )
150+ {
151+ if (!isset ($ this ->compressors [$ compressor ])) {
152+ throw new \InvalidArgumentException (sprintf ('Undefined compressor "%s" ' , $ compressor ));
153+ }
154+
155+ $ css = $ this ->contentType ('.css ' );
156+
157+ if ($ this ->cssCompressor !== null ) {
158+ $ this ->bundleProcessors ->unregister ($ css , $ this ->cssCompressor );
159+ }
160+
161+ $ this ->cssCompressor = $ compressor ;
162+ $ this ->bundleProcessors ->register ($ css , $ this ->compressors [$ compressor ]);
163+ }
164+
165+ function contentType ($ extension )
166+ {
167+ return @$ this ->contentTypes [Path::normalizeExtension ($ extension )];
168+ }
169+
124170 # Sugar for find().
125171 #
126172 # logicalPath - The path relative to the virtual file system.
0 commit comments