<?php

class js_css_compressor_compressor
{
	protected $_js_compressor;
	protected $_css_compressor;

	public function __construct()
	{
		$js_compressors=array(
			'jshrink'=>'minifier.php',
			'jsminplus'=>'jsminplus.php',
			'googleclousurecompiler'=>'googleclousurecompiler.php',
			'parsemaster'=>'javascriptpacker.php'
		);
		$css_compressors=array(
			'cancssmini'=>'cancssmini.php',
			'compressionautomate'=>'compressionautomate.php',
			'crunch_css'=>'crunch_css.php',
			'cssmin'=>'cssmin.php',
			'cssmin_yui'=>'cssmin_yui.php',
			'cssminregex'=>'cssminregex.php'
		);

		config::set('js_compressor', 'parsemaster');

		$js_compressor=(array_key_exists(config::get('js_compressor'), $js_compressors))
			?config::get('js_compressor'):'jshrink';
		$css_compressor=(array_key_exists(config::get('css_compressor'), $css_compressors))
			?config::get('css_compressor'):'cancssmini';

		Factory::set('js_compressor', $js_compressor.'_wrapper', dirname(__FILE__).'/compressors/'.$js_compressor.'.php');
		Factory::set('css_compressor', $css_compressor.'_wrapper', dirname(__FILE__).'/compressors/'.$css_compressor.'.php');
	}

	public function getJs($data)
	{
		return $this->_getJsCompressor()->getCompressed($data);
	}

	public function getCss($data)
	{
		return $this->_getCssCompressor()->getCompressed($data);
	}

	protected function _getJsCompressor()
	{
		if (!is_object($this->_js_compressor)) {
			$this->_js_compressor=Factory::create('js_compressor');
		}
		return $this->_js_compressor;
	}

	protected function _getCssCompressor()
	{
		if (!is_object($this->_css_compressor)) {
			$this->_css_compressor=Factory::create('css_compressor');
		}
		return $this->_css_compressor;
	}

}