1<?php 2 3/* 4 * This file is part of the Assetic package, an OpenSky project. 5 * 6 * (c) 2010-2014 OpenSky Project Inc 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Assetic\Exception; 13 14use Symfony\Component\Process\Process; 15 16/** 17 * Describes an exception that occurred within a filter. 18 * 19 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 20 */ 21class FilterException extends \RuntimeException implements Exception 22{ 23 private $originalMessage; 24 private $input; 25 26 public static function fromProcess(Process $proc) 27 { 28 $message = sprintf("An error occurred while running:\n%s", $proc->getCommandLine()); 29 30 $errorOutput = $proc->getErrorOutput(); 31 if (!empty($errorOutput)) { 32 $message .= "\n\nError Output:\n".str_replace("\r", '', $errorOutput); 33 } 34 35 $output = $proc->getOutput(); 36 if (!empty($output)) { 37 $message .= "\n\nOutput:\n".str_replace("\r", '', $output); 38 } 39 40 return new self($message); 41 } 42 43 public function __construct($message, $code = 0, \Exception $previous = null) 44 { 45 parent::__construct($message, $code, $previous); 46 47 $this->originalMessage = $message; 48 } 49 50 public function setInput($input) 51 { 52 $this->input = $input; 53 $this->updateMessage(); 54 55 return $this; 56 } 57 58 public function getInput() 59 { 60 return $this->input; 61 } 62 63 private function updateMessage() 64 { 65 $message = $this->originalMessage; 66 67 if (!empty($this->input)) { 68 $message .= "\n\nInput:\n".$this->input; 69 } 70 71 $this->message = $message; 72 } 73} 74