示例#1
0
 function render($context = null, $vars = array())
 {
     $options = $this->options;
     $compress = @$options["compress"] ?: false;
     $outputFile = tempnam(sys_get_temp_dir(), 'metatemplate_template_less_output');
     $finder = new ExecutableFinder();
     $bin = @$this->options["less_bin"] ?: self::DEFAULT_LESSC;
     $cmd = $finder->find($bin);
     if ($cmd === null) {
         throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
     }
     if ($compress) {
         $cmd .= ' -x';
     }
     if (array_key_exists('include_path', $this->options)) {
         $cmd .= sprintf('--include-path %s', escapeshellarg(join(PATH_SEPARATOR, (array) $this->options['include_path'])));
     }
     $cmd .= " --no-color - {$outputFile}";
     $process = new Process($cmd);
     $process->setStdin($this->getData());
     if ($this->isFile()) {
         $process->setWorkingDirectory(dirname($this->source));
     }
     $process->setEnv(array('PATH' => getenv("PATH")));
     $process->run();
     $content = @file_get_contents($outputFile);
     @unlink($outputFile);
     if (!$process->isSuccessful()) {
         throw new \RuntimeException("{$cmd} returned an error: " . $process->getErrorOutput());
     }
     return $content;
 }
 /**
  * {@inheritdoc)
  */
 public function transform(\Swift_Mime_Message $message)
 {
     $processor = new Process($this->getCommand());
     $processor->setStdin($message->getBody());
     $processor->run();
     if ($processor->isSuccessful()) {
         $message->addPart($processor->getOutput(), 'text/plain');
     }
 }
示例#3
0
 /**
  * tests results from sub processes
  *
  * @dataProvider pipesCodeProvider
  */
 public function testProcessPipes($expected, $code)
 {
     $p = new Process(sprintf('php -r \'%s\'', $code));
     $p->setStdin($expected);
     $p->run();
     $this->assertSame($expected, $p->getOutput());
     $this->assertSame($expected, $p->getErrorOutput());
     $this->assertSame(0, $p->getExitCode());
 }
示例#4
0
 /**
  * Executes external command
  */
 public function pipe($value, $command)
 {
     $process = new Process($command);
     $process->setStdin($value);
     $process->run();
     if (!$process->isSuccessful()) {
         return false;
     }
     return $process->getOutput();
 }
示例#5
0
文件: UglifyJs.php 项目: chh/pipe
 function render($context = null, $vars = array())
 {
     $cmd = "/usr/bin/env uglifyjs";
     $process = new Process($cmd);
     $process->setStdin($this->data);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception("uglifyjs exited with an error: {$process->getErrorOutput()}");
     }
     return $process->getOutput();
 }
示例#6
0
 /**
  * tests results from sub processes
  *
  * @dataProvider pipesCodeProvider
  */
 public function testProcessPipes($expected, $code)
 {
     if (strpos(PHP_OS, "WIN") === 0) {
         $this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 and https://bugs.php.net/bug.php?id=51800');
     }
     $p = new Process(sprintf('php -r %s', escapeshellarg($code)));
     $p->setStdin($expected);
     $p->run();
     $this->assertSame($expected, $p->getOutput());
     $this->assertSame($expected, $p->getErrorOutput());
     $this->assertSame(0, $p->getExitCode());
 }
示例#7
0
 /**
  * tests results from sub processes
  *
  * @dataProvider pipesCodeProvider
  */
 public function testProcessPipes($expected, $code)
 {
     if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
         $this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
     }
     $p = new Process(sprintf('php -r %s', escapeshellarg($code)));
     $p->setStdin($expected);
     $p->run();
     $this->assertSame($expected, $p->getOutput());
     $this->assertSame($expected, $p->getErrorOutput());
     $this->assertSame(0, $p->getExitCode());
 }
 function render($context = null, $vars = array())
 {
     $finder = new ExecutableFinder();
     $bin = @$this->options["coffee_bin"] ?: self::DEFAULT_COFFEE;
     $cmd = $finder->find($bin);
     if ($cmd === null) {
         throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
     }
     $cmd .= " -sc";
     $process = new Process($cmd);
     $process->setEnv(array('PATH' => @$_SERVER['PATH'] ?: join(PATH_SEPARATOR, array("/bin", "/sbin", "/usr/bin", "/usr/local/bin"))));
     $process->setStdin($this->data);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException("coffee({$this->source}) returned an error:\n {$process->getErrorOutput()}");
     }
     return $process->getOutput();
 }
示例#9
0
 public function executeCommand($command, $stdIn = null, $quiet = false)
 {
     $this->tty = $stdIn instanceof TTY;
     $command = $this->decorator->decorateCommand($command, $this);
     $this->process = $process = new Process($command, array_shift($this->workingDirectoriesStack));
     $process->setTimeout(null);
     if (null !== $stdIn) {
         if ($this->tty) {
             $process->setTty(true);
         } else {
             $process->setStdin($stdIn);
         }
     }
     $output = $this->getOutput();
     if ($output && $output->getVerbosity() >= $output::VERBOSITY_VERBOSE) {
         $output->writeln(sprintf('$ %s', $command));
         $start = true;
         $prefix = ' ---> ';
         $process->start(function ($type, $buffer) use($output, &$start, $prefix, $quiet) {
             if ($start) {
                 $buffer = $prefix . $buffer;
                 $start = false;
             }
             if ($buffer[strlen($buffer) - 1] == "\n") {
                 $start = true;
                 $buffer = strtr(substr($buffer, 0, -1), ["\n" => "\n" . $prefix]) . "\n";
             } else {
                 $buffer = strtr($buffer, ["\n" => "\n" . $prefix]);
             }
             $quiet || $output->write($buffer);
         });
         $process->wait();
     } else {
         $process->run();
     }
     if ($process->getExitCode() != 0) {
         throw new ProcessFailedException($process);
     }
     return $process->getOutput();
 }
示例#10
0
 public function setInput(Process $proc)
 {
     $proc->setStdin($this->resource);
 }