You are here

private function Lessjs::proc_open in Less CSS Preprocessor 7.4

Same name and namespace in other branches
  1. 8 classes/class.lessjs.inc \Lessjs::proc_open()
  2. 7.3 class.lessjs.inc \Lessjs::proc_open()

Execute compilation command through proc_open().

Parameters

string[] $command_arguments:

Return value

null|string

Throws

Exception

See also

proc_open()

2 calls to Lessjs::proc_open()
Lessjs::compile in classes/class.lessjs.inc
Executes compilation of LESS input.
Lessjs::depends in classes/class.lessjs.inc
Returns list of files that input file depends on.

File

classes/class.lessjs.inc, line 245
Contains 'lessjs' class; an abstraction layer for command line less.js.

Class

Lessjs
'lessjs' class.

Code

private function proc_open(array $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;
}