From f53958b285205e5aa38eeda520a37fe21b5df210 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Date: Fri, 3 May 2019 14:24:22 -0300 Subject: [PATCH 1/3] Symfony process 4 compatibility --- composer.json | 2 +- src/Assetic/Filter/BaseProcessFilter.php | 12 ++--- .../GoogleClosure/CompilerJarFilter.php | 51 ++++++++++--------- tests/Assetic/Test/Filter/FilterTestCase.php | 8 +-- .../Test/Filter/UglifyJs2FilterTest.php | 12 +++-- .../Test/Filter/UglifyJsFilterTest.php | 11 ++-- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/composer.json b/composer.json index 80755d757..c5cde73d5 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "require": { "php": ">=5.3.1", - "symfony/process": "~2.1|~3.0" + "symfony/process": "~2.1|~3.0|~4.0" }, "conflict": { "twig/twig": "<1.27" diff --git a/src/Assetic/Filter/BaseProcessFilter.php b/src/Assetic/Filter/BaseProcessFilter.php index 642495ab4..95eeb508d 100644 --- a/src/Assetic/Filter/BaseProcessFilter.php +++ b/src/Assetic/Filter/BaseProcessFilter.php @@ -11,7 +11,7 @@ namespace Assetic\Filter; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * An external process based filter which provides a way to set a timeout on the process. @@ -35,11 +35,11 @@ public function setTimeout($timeout) * * @param array $arguments An optional array of arguments * - * @return ProcessBuilder A new process builder + * @return Process A new process builder */ protected function createProcessBuilder(array $arguments = array()) { - $pb = new ProcessBuilder($arguments); + $pb = new Process($arguments); if (null !== $this->timeout) { $pb->setTimeout($this->timeout); @@ -48,10 +48,8 @@ protected function createProcessBuilder(array $arguments = array()) return $pb; } - protected function mergeEnv(ProcessBuilder $pb) + protected function mergeEnv(Process $pb) { - foreach (array_filter($_SERVER, 'is_scalar') as $key => $value) { - $pb->setEnv($key, $value); - } + $pb->setEnv(array_filter($_SERVER, 'is_scalar')); } } diff --git a/src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php b/src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php index 7cd340efe..33d53d85f 100644 --- a/src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php +++ b/src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php @@ -14,7 +14,7 @@ use Assetic\Asset\AssetInterface; use Assetic\Exception\FilterException; use Assetic\Util\FilesystemUtils; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * Filter for the Google Closure Compiler JAR. @@ -44,69 +44,70 @@ public function filterDump(AssetInterface $asset) $is64bit = PHP_INT_SIZE === 8; $cleanup = array(); - $pb = new ProcessBuilder(array_merge( - array($this->javaPath), + $command = array_merge( + [$this->javaPath], $is64bit - ? array('-server', '-XX:+TieredCompilation') - : array('-client', '-d32'), - array('-jar', $this->jarPath) - )); - - if (null !== $this->timeout) { - $pb->setTimeout($this->timeout); - } + ? ['-server', '-XX:+TieredCompilation'] + : ['-client', '-d32'], + ['-jar', $this->jarPath] + ); if (null !== $this->compilationLevel) { - $pb->add('--compilation_level')->add($this->compilationLevel); + array_push($command, '--compilation_level', $this->compilationLevel); } if (null !== $this->jsExterns) { $cleanup[] = $externs = FilesystemUtils::createTemporaryFile('google_closure'); file_put_contents($externs, $this->jsExterns); - $pb->add('--externs')->add($externs); + array_push($command, '--externs', $externs); } if (null !== $this->externsUrl) { $cleanup[] = $externs = FilesystemUtils::createTemporaryFile('google_closure'); file_put_contents($externs, file_get_contents($this->externsUrl)); - $pb->add('--externs')->add($externs); + array_push($command, '--externs', $externs); } if (null !== $this->excludeDefaultExterns) { - $pb->add('--use_only_custom_externs'); + $command[] = '--use_only_custom_externs'; } if (null !== $this->formatting) { - $pb->add('--formatting')->add($this->formatting); + array_push($command, '--formatting', $this->formatting); } if (null !== $this->useClosureLibrary) { - $pb->add('--manage_closure_dependencies'); + $command[] = '--manage_closure_dependencies'; } if (null !== $this->warningLevel) { - $pb->add('--warning_level')->add($this->warningLevel); + array_push($command, '--warning_level', $this->warningLevel); } if (null !== $this->language) { - $pb->add('--language_in')->add($this->language); + array_push($command, '--language_in', $this->language); } if (null !== $this->flagFile) { - $pb->add('--flagfile')->add($this->flagFile); + array_push($command, '--flagfile', $this->flagFile); } - $pb->add('--js')->add($cleanup[] = $input = FilesystemUtils::createTemporaryFile('google_closure')); + array_push($command, '--js', $cleanup[] = $input = FilesystemUtils::createTemporaryFile('google_closure')); file_put_contents($input, $asset->getContent()); - $proc = $pb->getProcess(); - $code = $proc->run(); + $pb = new Process($command); + + if (null !== $this->timeout) { + $pb->setTimeout($this->timeout); + } + + $code = $pb->run(); array_map('unlink', $cleanup); if (0 !== $code) { - throw FilterException::fromProcess($proc)->setInput($asset->getContent()); + throw FilterException::fromProcess($pb)->setInput($asset->getContent()); } - $asset->setContent($proc->getOutput()); + $asset->setContent($pb->getOutput()); } } diff --git a/tests/Assetic/Test/Filter/FilterTestCase.php b/tests/Assetic/Test/Filter/FilterTestCase.php index 935b23133..184ca0d58 100644 --- a/tests/Assetic/Test/Filter/FilterTestCase.php +++ b/tests/Assetic/Test/Filter/FilterTestCase.php @@ -13,7 +13,7 @@ use Assetic\Test\TestCase; use Symfony\Component\Process\ExecutableFinder; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; abstract class FilterTestCase extends TestCase { @@ -49,13 +49,13 @@ protected function checkNodeModule($module, $bin = null) $this->markTestSkipped('Unable to find `node` executable.'); } - $pb = new ProcessBuilder(array($bin, '-e', 'require(\''.$module.'\')')); + $pb = new Process(array($bin, '-e', 'require(\''.$module.'\')')); if (isset($_SERVER['NODE_PATH'])) { - $pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']); + $pb->setEnv(['NODE_PATH' => $_SERVER['NODE_PATH']]); } - return 0 === $pb->getProcess()->run(); + return 0 === $pb->run(); } private function ensurePaths($current, array $paths) diff --git a/tests/Assetic/Test/Filter/UglifyJs2FilterTest.php b/tests/Assetic/Test/Filter/UglifyJs2FilterTest.php index 1d88844c8..48882fd71 100644 --- a/tests/Assetic/Test/Filter/UglifyJs2FilterTest.php +++ b/tests/Assetic/Test/Filter/UglifyJs2FilterTest.php @@ -13,7 +13,7 @@ use Assetic\Asset\FileAsset; use Assetic\Filter\UglifyJs2Filter; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * @group integration @@ -39,12 +39,14 @@ protected function setUp() } // verify uglifyjs version - $pb = new ProcessBuilder($nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin)); - $pb->add('--version'); + $command = $nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin); + $command[] = '--version'; + + $pb = new Process($command); if (isset($_SERVER['NODE_PATH'])) { - $pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']); + $pb->setEnv(['NODE_PATH' => $_SERVER['NODE_PATH']]); } - if (0 !== $pb->getProcess()->run()) { + if (0 !== $pb->run()) { $this->markTestSkipped('Incorrect version of UglifyJs'); } diff --git a/tests/Assetic/Test/Filter/UglifyJsFilterTest.php b/tests/Assetic/Test/Filter/UglifyJsFilterTest.php index 32de999b5..019789003 100644 --- a/tests/Assetic/Test/Filter/UglifyJsFilterTest.php +++ b/tests/Assetic/Test/Filter/UglifyJsFilterTest.php @@ -13,7 +13,7 @@ use Assetic\Asset\FileAsset; use Assetic\Filter\UglifyJsFilter; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * @group integration @@ -32,12 +32,13 @@ protected function setUp() } // verify uglifyjs version - $pb = new ProcessBuilder($nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin)); - $pb->add('--version'); + $command = $nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin); + $command[] = '--version'; + $pb = new Process($command); if (isset($_SERVER['NODE_PATH'])) { - $pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']); + $pb->setEnv(['NODE_PATH' => $_SERVER['NODE_PATH']]); } - if (0 === $pb->getProcess()->run()) { + if (0 === $pb->run()) { $this->markTestSkipped('Incorrect version of UglifyJs'); } From 7ca9b140beb8be988e7f8712c244cc7ce35c5d66 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Date: Wed, 7 Aug 2019 13:49:38 -0300 Subject: [PATCH 2/3] ProcessBuilder/Process fix --- src/Assetic/Filter/Yui/BaseCompressorFilter.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Assetic/Filter/Yui/BaseCompressorFilter.php b/src/Assetic/Filter/Yui/BaseCompressorFilter.php index b3ec26719..622680e6a 100644 --- a/src/Assetic/Filter/Yui/BaseCompressorFilter.php +++ b/src/Assetic/Filter/Yui/BaseCompressorFilter.php @@ -66,24 +66,24 @@ public function filterLoad(AssetInterface $asset) */ protected function compress($content, $type, $options = array()) { - $pb = $this->createProcessBuilder(array($this->javaPath)); + $arguments = [$this->javaPath]; if (null !== $this->stackSize) { - $pb->add('-Xss'.$this->stackSize); + $arguments[] = '-Xss'.$this->stackSize; } - $pb->add('-jar')->add($this->jarPath); + array_push($arguments, '-jar', $this->jarPath); foreach ($options as $option) { - $pb->add($option); + $arguments[] = $option; } if (null !== $this->charset) { - $pb->add('--charset')->add($this->charset); + array_push($arguments, '--charset', $this->charset); } if (null !== $this->lineBreak) { - $pb->add('--line-break')->add($this->lineBreak); + array_push($arguments, '--line-break', $this->lineBreak); } // input and output files @@ -91,9 +91,9 @@ protected function compress($content, $type, $options = array()) $input = tempnam($tempDir, 'assetic_yui_input'); $output = tempnam($tempDir, 'assetic_yui_output'); file_put_contents($input, $content); - $pb->add('-o')->add($output)->add('--type')->add($type)->add($input); + array_push($arguments, '-o', '--type', $type, $input); - $proc = $pb->getProcess(); + $proc = $this->createProcessBuilder($arguments); $code = $proc->run(); unlink($input); From e431ef2d5fde221dec121ebcaebc606315893695 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Date: Mon, 12 Aug 2019 16:52:22 -0300 Subject: [PATCH 3/3] missing output param correction --- src/Assetic/Filter/Yui/BaseCompressorFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Assetic/Filter/Yui/BaseCompressorFilter.php b/src/Assetic/Filter/Yui/BaseCompressorFilter.php index 622680e6a..9dcd0ba45 100644 --- a/src/Assetic/Filter/Yui/BaseCompressorFilter.php +++ b/src/Assetic/Filter/Yui/BaseCompressorFilter.php @@ -91,7 +91,7 @@ protected function compress($content, $type, $options = array()) $input = tempnam($tempDir, 'assetic_yui_input'); $output = tempnam($tempDir, 'assetic_yui_output'); file_put_contents($input, $content); - array_push($arguments, '-o', '--type', $type, $input); + array_push($arguments, '-o', $output, '--type', $type, $input); $proc = $this->createProcessBuilder($arguments); $code = $proc->run();