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\Filter; 13 14use Symfony\Component\Process\ProcessBuilder; 15 16/** 17 * An external process based filter which provides a way to set a timeout on the process. 18 */ 19abstract class BaseProcessFilter implements FilterInterface 20{ 21 private $timeout; 22 23 /** 24 * Set the process timeout. 25 * 26 * @param int $timeout The timeout for the process 27 */ 28 public function setTimeout($timeout) 29 { 30 $this->timeout = $timeout; 31 } 32 33 /** 34 * Creates a new process builder. 35 * 36 * @param array $arguments An optional array of arguments 37 * 38 * @return ProcessBuilder A new process builder 39 */ 40 protected function createProcessBuilder(array $arguments = array()) 41 { 42 $pb = new ProcessBuilder($arguments); 43 44 if (null !== $this->timeout) { 45 $pb->setTimeout($this->timeout); 46 } 47 48 return $pb; 49 } 50 51 protected function mergeEnv(ProcessBuilder $pb) 52 { 53 foreach (array_filter($_SERVER, 'is_scalar') as $key => $value) { 54 $pb->setEnv($key, $value); 55 } 56 } 57} 58