- //Use tool
- if (!empty($this->tool) && is_executable($this->tool)) {
- $descriptorSpec = array(
- 0 => array('pipe', 'r'),
- 1 => array('pipe', 'w'),
- 2 => array('pipe', 'w')
- );
- if (is_resource($proc = proc_open($this->tool, $descriptorSpec, $pipes))) {
- //Set stderr as non blocking
- stream_set_blocking($pipes[2], 0);
- //Send content to stdin
- fwrite($pipes[0], $content);
- //Close stdin
- fclose($pipes[0]);
- //Read content from stdout
- if ($stdout = stream_get_contents($pipes[1])) {
- $content = $stdout;
- }
- //Close stdout
- fclose($pipes[1]);
- //Read content from stderr
- if ($stderr = stream_get_contents($pipes[2])) {
- throw new \Twig_Error_Syntax(sprintf('Got unexpected strerr for %s: %s', $this->tool, $stderr), $token->getLine(), $stream->getFilename());
- }
- //Close stderr
- fclose($pipes[2]);
- //Close process
- if ($ret = proc_close($proc)) {
- throw new \Twig_Error_Syntax(sprintf('Got unexpected non zero return code %s: %d', $this->tool, $ret), $token->getLine(), $stream->getFilename());
- }
+ //Check filters
+ if (!empty($filters)) {
+ //Apply all filters
+ foreach($filters as $filter) {
+ //Prefix with filter
+ $filter = __NAMESPACE__.'\\Filter\\'.$filter;
+ //Init tool object
+ $tool = new $filter($this->containerInterface, $stream->getSourceContext(), $token->getLine());
+ //Process content
+ $content = $tool->process($content);
+ //Remove object
+ unset($tool);