lib/YUI/Compressor.php
public function compress($data)
	{
		// Construct the command
		$cmd = $this->_options['javaPath'].' -jar '.escapeshellarg($this->_jarPath);
		$cmd .= ' --charset '.$this->_options['charset'];
		$cmd .= ' --type '.$this->_options['type'];

		if ($this->_options['line-break'] !== false)
			$cmd .= ' --line-break '.(int) $this->_options['line-break'];

		if ($this->_options['verbose'])
			$cmd .= " -v";

		// Javascript-specific options
		if ($this->_options['type'] === self::TYPE_JS)
			foreach (self::$_javaScriptOptions as $option)
				if ($this->_options[$option])
					$cmd .= ' --'.$option;

		// Run the command
		$pipes = array();
		$descriptors = array(
			0=>array('pipe', 'r'),
			1=>array('pipe', 'w'),
			2=>array('pipe', 'w'),
		);

		$process = proc_open($cmd, $descriptors, $pipes);

		if (is_resource($process))
		{
			// Write the data we want to compress to STDIN
			fwrite($pipes[0], $data);
			fclose($pipes[0]);

			// Get the compressed data and eventual error from STDOUT and STDERR
			$compressedData = stream_get_contents($pipes[1]);
			$error = stream_get_contents($pipes[2]);
			fclose($pipes[1]);
			fclose($pipes[2]);

			$return = proc_close($process);

			// Throw an exception if compression fails
			if ($return === 0)
				return $compressedData;
			else
				throw new Exception('Failed to compress data: '.$error, $return);
		}

		throw new Exception('Failed to open a process');
	}
public function compress($data)
	{
		// Construct the command
		$cmd = $this->_options['javaPath'].' -jar '.escapeshellarg($this->_jarPath);
		$cmd .= ' --charset '.$this->_options['charset'];
		$cmd .= ' --type '.$this->_options['type'];

		if ($this->_options['line-break'] !== false)
			$cmd .= ' --line-break '.(int) $this->_options['line-break'];

		if ($this->_options['verbose'])
			$cmd .= " -v";

		// Javascript-specific options
		if ($this->_options['type'] === self::TYPE_JS)
			foreach (self::$_javaScriptOptions as $option)
				if ($this->_options[$option])
					$cmd .= ' --'.$option;

		// Run the command
		$pipes = array();
		$descriptors = array(
			0=>array('pipe', 'r'),
			1=>array('pipe', 'w'),
			2=>array('pipe', 'w'),
		);

		$process = proc_open($cmd, $descriptors, $pipes);

		if (is_resource($process))
		{
			// Write the data we want to compress to STDIN
			fwrite($pipes[0], $data);
			fclose($pipes[0]);

			// Get the compressed data and eventual error from STDOUT and STDERR
			$compressedData = stream_get_contents($pipes[1]);
			$error = stream_get_contents($pipes[2]);
			fclose($pipes[1]);
			fclose($pipes[2]);

			$return = proc_close($process);

			// Throw an exception if compression fails
			if ($return === 0)
				return $compressedData;
			else
				throw new Exception('Failed to compress data: '.$error, $return);
		}

		throw new Exception('Failed to open a process');
	}
public function compress ( $ data ) { // Construct the command $ cmd = $ this -> _options [ 'javaPath' ] . ' -jar ' . escapeshellarg ( $ this -> _jarPath ) ; $ cmd .= ' --charset ' . $ this -> _options [ 'charset' ] ; $ cmd .= ' --type ' . $ this -> _options [ 'type' ] ; if ( $ this -> _options [ 'line-break' ] !== false ) $ cmd .= ' --line-break ' . ( int ) $ this -> _options [ 'line-break' ] ; if ( $ this -> _options [ 'verbose' ] ) $ cmd .= " -v" ; // Javascript-specific options if ( $ this -> _options [ 'type' ] === self :: TYPE_JS ) foreach ( self :: $ _javaScriptOptions as $ option ) if ( $ this -> _options [ $ option ] ) $ cmd .= ' --' . $ option ; // Run the command $ pipes = array ( ) ; $ descriptors = array ( 0 => array ( 'pipe' , 'r' ) , 1 => array ( 'pipe' , 'w' ) , 2 => array ( 'pipe' , 'w' ) , ) ; $ process = proc_open ( $ cmd , $ descriptors , $ pipes ) ; if ( is_resource ( $ process ) ) { // Write the data we want to compress to STDIN fwrite ( $ pipes [ 0 ] , $ data ) ; fclose ( $ pipes [ 0 ] ) ; // Get the compressed data and eventual error from STDOUT and STDERR $ compressedData = stream_get_contents ( $ pipes [ 1 ] ) ; $ error = stream_get_contents ( $ pipes [ 2 ] ) ; fclose ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 2 ] ) ; $ return = proc_close ( $ process ) ; // Throw an exception if compression fails if ( $ return === 0 ) return $ compressedData ; else throw new Exception ( 'Failed to compress data: ' . $ error , $ return ) ; } throw new Exception ( 'Failed to open a process' ) ; }
Compresses the specified data and returns it
@param string $data the data
@return string the compressed data
@throws Exception if the compression fails
Compresses the specified data and returns it