1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Ghostscript package |
4
|
|
|
* |
5
|
|
|
* @author Daniel Schröder <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Ghostscript\Device; |
9
|
|
|
|
10
|
|
|
use GravityMedia\Ghostscript\Process\Argument as ProcessArgument; |
11
|
|
|
use GravityMedia\Ghostscript\Process\Arguments as ProcessArguments; |
12
|
|
|
use Symfony\Component\Process\Process; |
13
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The abstract device class |
17
|
|
|
* |
18
|
|
|
* @package GravityMedia\Ghostscript\Devices |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractDevice |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The process builder object |
24
|
|
|
* |
25
|
|
|
* @var ProcessBuilder |
26
|
|
|
*/ |
27
|
|
|
private $builder; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The arguments object |
31
|
|
|
* |
32
|
|
|
* @var ProcessArguments |
33
|
|
|
*/ |
34
|
|
|
private $arguments; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create abstract device object |
38
|
|
|
* |
39
|
|
|
* @param ProcessBuilder $builder |
40
|
|
|
* @param ProcessArguments $arguments |
41
|
|
|
*/ |
42
|
15 |
|
public function __construct(ProcessBuilder $builder, ProcessArguments $arguments) |
43
|
|
|
{ |
44
|
15 |
|
$this->builder = $builder; |
45
|
15 |
|
$this->arguments = $arguments; |
46
|
15 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get Argument |
50
|
|
|
* |
51
|
|
|
* @param string $name |
52
|
|
|
* |
53
|
|
|
* @return null|ProcessArgument |
54
|
|
|
*/ |
55
|
6 |
|
protected function getArgument($name) |
56
|
|
|
{ |
57
|
6 |
|
return $this->arguments->getArgument($name); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get argument value |
62
|
|
|
* |
63
|
|
|
* @param string $name |
64
|
|
|
* |
65
|
|
|
* @return null|string |
66
|
|
|
*/ |
67
|
3 |
|
protected function getArgumentValue($name) |
68
|
|
|
{ |
69
|
3 |
|
$argument = $this->getArgument($name); |
70
|
3 |
|
if (null === $argument) { |
71
|
3 |
|
return null; |
72
|
|
|
} |
73
|
|
|
|
74
|
3 |
|
return $argument->getValue(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set argument |
79
|
|
|
* |
80
|
|
|
* @param string $argument |
81
|
|
|
* |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
3 |
|
protected function setArgument($argument) |
85
|
|
|
{ |
86
|
3 |
|
$this->arguments->setArgument($argument); |
87
|
|
|
|
88
|
3 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Create process object |
93
|
|
|
* |
94
|
|
|
* @param string $inputFile |
95
|
|
|
* |
96
|
|
|
* @throws \RuntimeException |
97
|
|
|
* |
98
|
|
|
* @return Process |
99
|
|
|
*/ |
100
|
6 |
|
public function createProcess($inputFile) |
101
|
|
|
{ |
102
|
6 |
|
if (!is_file($inputFile)) { |
103
|
3 |
|
throw new \RuntimeException('Input file does not exist'); |
104
|
|
|
} |
105
|
|
|
|
106
|
3 |
|
$arguments = array_values($this->arguments->toArray()); |
107
|
3 |
|
array_push($arguments, '-f', $inputFile); |
108
|
|
|
|
109
|
3 |
|
return $this->builder->setArguments($arguments)->getProcess(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|