You are here

protected function LessAutoprefixer::proc_open in Less CSS Preprocessor 7.4

Same name and namespace in other branches
  1. 8 classes/class.lessautoprefixer.inc \LessAutoprefixer::proc_open()
1 call to LessAutoprefixer::proc_open()
LessAutoprefixer::compile in classes/class.lessautoprefixer.inc
Executes auto-prefixing of LESS output file.

File

classes/class.lessautoprefixer.inc, line 111
Contains 'LessAutoprefixer' class; an abstraction layer for command line Autoprefixer.

Class

LessAutoprefixer
'Autoprefixer' class.

Code

protected function proc_open($command_arguments = array()) {
  $output_data = NULL;
  $command = implode(' ', array_merge(array(
    self::BASE_COMMAND,
  ), $command_arguments));

  // Handles for data exchange.
  $pipes = array(
    0 => NULL,
    // STDIN
    1 => NULL,
    // STDOUT
    2 => NULL,
  );

  // Sets permissions on $pipes.
  $descriptors = array(
    0 => array(
      'pipe',
      'r',
    ),
    // STDIN
    1 => array(
      'pipe',
      'w',
    ),
    // STDOUT
    2 => array(
      'pipe',
      'w',
    ),
  );
  try {
    $process = proc_open($command, $descriptors, $pipes);
    if (is_resource($process)) {
      fclose($pipes[0]);

      // fclose() on STDIN executes $command, if program is expecting input from STDIN.
      $output_data = stream_get_contents($pipes[1]);
      fclose($pipes[1]);
      $error = stream_get_contents($pipes[2]);
      fclose($pipes[2]);
      if (!empty($error)) {
        throw new Exception($error);
      }
      proc_close($process);
    }
  } catch (Exception $e) {
    throw $e;
  }
  return $output_data;
}