Skip to content

Commit 4adc34b

Browse files
ricohummePadam87
authored andcommitted
Updates regarding SF 3.4 + due to deprecations (#14)
* Service made public, added environment Due to deprecation of access to services through the container. Process class requires environment in SF 4.0 * Added environment Due to deprecation since SF 3.3, start method requires an array of environments * Replaced ProcessBuilder with Process As of SF 3.4, the ProcessBuilder is deprecated * Removed import ProcessBuilder * Updated UnitTest for Rasterizer
1 parent 91364c8 commit 4adc34b

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

ConfigHelper.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Symfony\Component\Process\InputStream;
66
use Symfony\Component\Process\Process;
7-
use Symfony\Component\Process\ProcessBuilder;
87

98
class ConfigHelper
109
{
@@ -29,20 +28,17 @@ public function __construct(array $config)
2928
*/
3029
public function buildProcess($input, $arguments = array())
3130
{
32-
$builder = new ProcessBuilder();
33-
$builder
34-
->setPrefix($this->config['phantomjs']['callable'])
35-
->setArguments(
36-
array_merge(
37-
$this->processPhantomjsOptions(),
38-
[$this->config['script']],
39-
array_values(array_merge($this->config['arguments'], $arguments))
40-
)
41-
)
42-
->setInput($input)
43-
;
31+
$process = new Process(
32+
array_merge(
33+
[$this->config['phantomjs']['callable']],
34+
$this->processPhantomjsOptions(),
35+
[ $this->config['script'] ],
36+
array_values(array_merge($this->config['arguments'], $arguments))
37+
),
38+
null, [], $input
39+
);
4440

45-
return $builder->getProcess();
41+
return $process;
4642
}
4743

4844
/**

Rasterizer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ class Rasterizer
1717
*/
1818
protected $stopwatch;
1919

20+
/**
21+
* @var array
22+
*/
23+
protected $environment;
24+
2025
/**
2126
* @param ConfigHelper $configHelper
2227
* @param Stopwatch $stopwatch
28+
* @param string $environment
2329
*/
24-
public function __construct(ConfigHelper $configHelper, Stopwatch $stopwatch = null)
30+
public function __construct(ConfigHelper $configHelper, Stopwatch $stopwatch = null, $environment)
2531
{
2632
$this->configHelper = $configHelper;
2733
$this->stopwatch = $stopwatch;
34+
$this->environment = [ $environment ];
2835
}
2936

3037
/**
@@ -42,7 +49,7 @@ public function rasterize($html, $arguments = array())
4249
$input = new InputStream();
4350

4451
$process = $this->configHelper->buildProcess($input, $arguments);
45-
$process->start();
52+
$process->start(null, $this->environment);
4653

4754
$input->write($html);
4855
$input->close();

Resources/config/services.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
<service id="padam87_rasterize.config_helper" class="%padam87_rasterize.config_helper.class%">
1515
<argument>%padam87_rasterize.config%</argument>
1616
</service>
17-
<service id="padam87_rasterize.rasterizer" class="%padam87_rasterize.rasterizer.class%">
17+
<service id="padam87_rasterize.rasterizer" class="%padam87_rasterize.rasterizer.class%" public="true">
1818
<argument type="service" id="padam87_rasterize.config_helper" />
1919
<argument type="service" id="debug.stopwatch" on-invalid="null" />
20+
<argument>%kernel.environment%</argument>
2021
</service>
2122
</services>
2223
</container>

Tests/RasterizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testRasterize()
5252
$this->process->expects($this->once())->method('wait');
5353
$this->process->expects($this->once())->method('getOutput')->willReturn('pdfcontent');
5454

55-
$rasterizer = new Rasterizer($this->configHelper, $this->stopwatch);
55+
$rasterizer = new Rasterizer($this->configHelper, $this->stopwatch, 'test');
5656

5757
$this->assertSame('pdfcontent', $rasterizer->rasterize('<html></html>'));
5858
}

0 commit comments

Comments
 (0)