Assetic\Util\ProcessBuilder::getProcess PHP Method

getProcess() public method

public getProcess ( )
    public function getProcess()
    {
        if (!count($this->parts)) {
            throw new \LogicException('You must add() command parts before calling getProcess().');
        }

        $parts = $this->parts;
        $cmd = array_shift($parts);
        $script = escapeshellcmd($cmd).' '.implode(' ', array_map('escapeshellarg', $parts));

        $env = $this->inheritEnv ? ($this->env ?: array()) + $_ENV : $this->env;

        return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $this->options);
    }

Usage Example

 /**
  * Compresses a string.
  *
  * @param string $content The content to compress
  * @param string $type    The type of content, either "js" or "css"
  * @param array  $options An indexed array of additional options
  *
  * @return string The compressed content
  */
 protected function compress($content, $type, $options = array())
 {
     $pb = new ProcessBuilder();
     $pb->inheritEnvironmentVariables()->add($this->javaPath)->add('-jar')->add($this->jarPath);
     foreach ($options as $option) {
         $pb->add($option);
     }
     if (null !== $this->charset) {
         $pb->add('--charset')->add($this->charset);
     }
     if (null !== $this->lineBreak) {
         $pb->add('--line-break')->add($this->lineBreak);
     }
     // input and output files
     $tempDir = realpath(sys_get_temp_dir());
     $hash = substr(sha1(time() . rand(11111, 99999)), 0, 7);
     $input = $tempDir . DIRECTORY_SEPARATOR . $hash . '.' . $type;
     $output = $tempDir . DIRECTORY_SEPARATOR . $hash . '-min.' . $type;
     file_put_contents($input, $content);
     $pb->add('-o')->add($output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 < $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw new \RuntimeException($proc->getErrorOutput());
     } elseif (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $retval = file_get_contents($output);
     unlink($output);
     return $retval;
 }
All Usage Examples Of Assetic\Util\ProcessBuilder::getProcess