protected function compress($data, $config) { switch ($config['type']) { case 'jsmin': include_once Kohana::find_file('vendor', 'JSMin'); return JSMin::minify($data); case 'jsminplus': include_once Kohana::find_file('vendor', 'jsminplus'); return JSMinPlus::minify($data); case 'packer': include_once Kohana::find_file('vendor', 'JavaScriptPacker'); $packer = new JavaScriptPacker($data, empty($config['level']) ? 'Normal' : $config['level']); return $packer->pack(); case 'yuicompressor': $options = isset($config['options']) ? $config['options'] : ''; return yuicompressor::compress($data, 'js', $options); default: throw new Kohana_User_Exception('Unknown Javascript Compression Type', 'Unknown type: ' . $config['type']); } }
protected function compress($data, $config) { switch ($config['type']) { case 'strip': // Borrowed from the old Kohana media module: // http://code.google.com/p/kohanamodules/source/browse/tags/2.2/media/controllers/media.php // Remove comments $data = preg_replace('~/\\*[^*]*\\*+([^/][^*]*\\*+)*/~', '', $data); // Replace all whitespace by single spaces $data = preg_replace('~\\s+~', ' ', $data); // Remove needless whitespace $data = preg_replace('~ *+([{}+>:;,]) *~', '$1', trim($data)); // Remove ; that closes last property of each declaration $data = str_replace(';}', '}', $data); // Remove empty CSS declarations $data = preg_replace('~[^{}]++\\{\\}~', '', $data); return $data; case 'yuicompressor': $options = isset($config['options']) ? $config['options'] : ''; return yuicompressor::compress($data, 'css', $options); default: throw new Kohana_User_Exception('Unknown CSS Compression Type', 'Unknown type: ' . $config['type']); } }