]> Raphaël G. Git Repositories - packbundle/blobdiff - Filter/JPackFilter.php
Add config and ctx member variables
[packbundle] / Filter / JPackFilter.php
index ca4555d71affc37e70dc88acfdf5a87135fcad57..9d758e4ff9f0c960af8c4631f6e6c3ef6e022873 100644 (file)
@@ -1,48 +1,42 @@
-<?php
+<?php declare(strict_types=1);
 
 
-namespace Rapsys\PackBundle\Twig\Filter;
+/*
+ * This file is part of the Rapsys PackBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * 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\Error\Error;
+use Twig\Source;
 
 
+/**
+ * {@inheritdoc}
+ */
 class JPackFilter implements FilterInterface {
 class JPackFilter 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: can be clean, shrink, obfuscate or best
-       public function __construct($fileName, $line, $bin = 'jpack', $compress = 'best') {
-               //Set fileName
-               $this->fileName = $fileName;
-
-               //Set line
-               $this->line = $line;
-
-               //Set bin
-               $this->bin = $bin;
-
-               //Set compress
-               $this->compress = $compress;
-
+       /**
+        * Setup jpack filter
+        *
+        * @xxx compress can be clean, shrink, obfuscate or best
+        */
+       public function __construct(protected Source $fileName, protected int $line, protected string $bin = 'jpack', protected string $compress = 'best') {
                //Deal with compress
                if (!empty($this->compress)) {
                        //Append clean parameter
                        if ($this->compress == 'clean') {
                //Deal with compress
                if (!empty($this->compress)) {
                        //Append clean parameter
                        if ($this->compress == 'clean') {
+                               //TODO: protect binary call by converting bin to array ?
                                $this->bin .= ' --clean';
                        //Append shrink parameter
                        } elseif ($this->compress == 'shrink') {
                                $this->bin .= ' --clean';
                        //Append shrink parameter
                        } elseif ($this->compress == 'shrink') {
+                               //TODO: protect binary call by converting bin to array ?
                                $this->bin .= ' --shrink';
                        //Append obfuscate parameter
                        } elseif ($this->compress == 'obfuscate') {
                                $this->bin .= ' --shrink';
                        //Append obfuscate parameter
                        } elseif ($this->compress == 'obfuscate') {
+                               //TODO: protect binary call by converting bin to array ?
                                $this->bin .= ' --obfuscate';
                        //Unknown compress type
                        //XXX: default compression is best
                                $this->bin .= ' --obfuscate';
                        //Unknown compress type
                        //XXX: default compression is best
@@ -53,7 +47,10 @@ class JPackFilter implements FilterInterface {
                }
        }
 
                }
        }
 
-       public function process($content) {
+       /**
+        * {@inheritdoc}
+        */
+       public function process(string $content): string {
                //Create descriptors
                $descriptorSpec = array(
                        0 => array('pipe', 'r'),
                //Create descriptors
                $descriptorSpec = array(
                        0 => array('pipe', 'r'),
@@ -64,7 +61,7 @@ class JPackFilter implements FilterInterface {
                //Open process
                if (is_resource($proc = proc_open($this->bin, $descriptorSpec, $pipes))) {
                        //Set stderr as non blocking
                //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);
 
                        //Send content to stdin
                        fwrite($pipes[0], $content);