From 469e59f888aea0ef9aa9e1062562c507332f1004 Mon Sep 17 00:00:00 2001 From: cyrusboadway Date: Thu, 29 Jan 2015 19:46:24 -0500 Subject: [PATCH] Exception on Missing Node Env If node isn't accessible, throw an exception. --- lib/Autoprefixer.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/Autoprefixer.php b/lib/Autoprefixer.php index 5272c07..238e537 100644 --- a/lib/Autoprefixer.php +++ b/lib/Autoprefixer.php @@ -38,7 +38,8 @@ public function setBrowsers($browsers) /** * @param mixed $css * @param mixed $browsers - * @throw AutoprefixerException + * @throws RuntimeException If node runtime unavailable + * @throws AutoprefixerException * @return array */ public function compile($css, $browsers = null) @@ -51,19 +52,20 @@ public function compile($css, $browsers = null) array(array('pipe', 'r'), array('pipe', 'w')), $pipes ); - - if ($nodejs) { - $this->fwrite_stream($pipes[0], - json_encode(array( - 'css' => $css, - 'browsers' => !is_null($browsers) ? $browsers : $this->browsers) - )); - fclose($pipes[0]); - - $output = stream_get_contents($pipes[1]); - $output = json_decode($output, true); - fclose($pipes[1]); + if ($nodejs === false) { + throw new RuntimeException('Could not reach node runtime'); } + + $this->fwrite_stream($pipes[0], + json_encode(array( + 'css' => $css, + 'browsers' => !is_null($browsers) ? $browsers : $this->browsers) + )); + fclose($pipes[0]); + + $output = stream_get_contents($pipes[1]); + $output = json_decode($output, true); + fclose($pipes[1]); proc_close($nodejs);