X-Git-Url: https://git.rapsys.eu/packbundle/blobdiff_plain/6bc3a323095049fba5ac8bb2b1a2cef1e82b8df5..96fd400cf3fce1bdca1a9df772d6e07096af545a:/Filter/CPackFilter.php?ds=sidebyside diff --git a/Filter/CPackFilter.php b/Filter/CPackFilter.php index ca38c3b..f56bb95 100644 --- a/Filter/CPackFilter.php +++ b/Filter/CPackFilter.php @@ -1,42 +1,34 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\PackBundle\Filter; -use Rapsys\PackBundle\Twig\Filter\FilterInterface; use Twig\Error\Error; +use Twig\Source; +/** + * {@inheritdoc} + */ class CPackFilter implements FilterInterface { - //Default bin - private $bin; - - //Default compress type - private $compress; - - //Twig template filename - private $fileName; - - //Twig template line - private $line; - - //Configure the object - //XXX: compress can be minify or pretty - public function __construct($fileName, $line, $bin = 'cpack', $compress = 'minify') { - //Set fileName - $this->fileName = $fileName; - - //Set line - $this->line = $line; - - //Set bin - $this->bin = $bin; - - //Set compress - $this->compress = $compress; - + /** + * Setup cpack filter + * + * @xxx compress can be minify or pretty + */ + public function __construct(protected Source $fileName, protected int $line, protected string $bin = 'cpack', protected string $compress = 'minify') { //Deal with compress if (!empty($this->compress)) { //Append minify parameter if ($this->compress == 'minify') { + //TODO: protect binary call by converting bin to array ? $this->bin .= ' --minify'; //Unknown compress type //XXX: default compression is pretty @@ -47,7 +39,10 @@ class CPackFilter implements FilterInterface { } } - public function process($content) { + /** + * {@inheritdoc} + */ + public function process(string $content): string { //Create descriptors $descriptorSpec = array( 0 => array('pipe', 'r'), @@ -58,7 +53,7 @@ class CPackFilter implements FilterInterface { //Open process if (is_resource($proc = proc_open($this->bin, $descriptorSpec, $pipes))) { //Set stderr as non blocking - stream_set_blocking($pipes[2], 0); + stream_set_blocking($pipes[2], false); //Send content to stdin fwrite($pipes[0], $content);