Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony process 4 compatibility #891

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 5 additions & 7 deletions src/Assetic/Filter/BaseProcessFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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'));
}
}
51 changes: 26 additions & 25 deletions src/Assetic/Filter/GoogleClosure/CompilerJarFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
}
16 changes: 8 additions & 8 deletions src/Assetic/Filter/Yui/BaseCompressorFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ 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
$tempDir = FilesystemUtils::getTemporaryDirectory();
$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', $output, '--type', $type, $input);

$proc = $pb->getProcess();
$proc = $this->createProcessBuilder($arguments);
$code = $proc->run();
unlink($input);

Expand Down
8 changes: 4 additions & 4 deletions tests/Assetic/Test/Filter/FilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions tests/Assetic/Test/Filter/UglifyJs2FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Assetic\Asset\FileAsset;
use Assetic\Filter\UglifyJs2Filter;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Process;

/**
* @group integration
Expand All @@ -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');
}

Expand Down
11 changes: 6 additions & 5 deletions tests/Assetic/Test/Filter/UglifyJsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Assetic\Asset\FileAsset;
use Assetic\Filter\UglifyJsFilter;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Process;

/**
* @group integration
Expand All @@ -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');
}

Expand Down