1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Helper; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* PhantomJS helper. |
16
|
|
|
* |
17
|
|
|
* @author webeweb <https://github.com/webeweb/> |
18
|
|
|
* @package WBW\Bundle\CoreBundle\Helper |
19
|
|
|
*/ |
20
|
|
|
class PhantomJSHelper { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Service name. |
24
|
|
|
* |
25
|
|
|
* @avr string |
26
|
|
|
*/ |
27
|
|
|
const SERVICE_NAME = "webeweb.core.helper.phantomjs"; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Binary path. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $binaryPath; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* OutputPath. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $outputPath; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* ScriptsPath. |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $scriptsPath; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Constructor. |
52
|
|
|
* |
53
|
|
|
* @param string $binaryPath The binary path. |
54
|
|
|
* @param string $scriptsPath The scripts path. |
55
|
|
|
* @param string $outputPath The output path. |
56
|
|
|
*/ |
57
|
|
|
public function __construct($binaryPath, $scriptsPath, $outputPath = null) { |
58
|
|
|
$this->setBinaryPath($binaryPath); |
59
|
|
|
$this->setScriptsPath($scriptsPath); |
60
|
|
|
$this->setOutputPath($outputPath); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the binary path. |
65
|
|
|
* |
66
|
|
|
* @return string Returns the binary path. |
67
|
|
|
*/ |
68
|
|
|
public function getBinaryPath() { |
69
|
|
|
return $this->binaryPath; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the command. |
74
|
|
|
* |
75
|
|
|
* @return string Returns the command. |
76
|
|
|
*/ |
77
|
|
|
public function getCommand() { |
78
|
|
|
|
79
|
|
|
// Initialize the command. |
80
|
|
|
$command = $this->getBinaryPath(); |
81
|
|
|
|
82
|
|
|
// Check the operating system. |
83
|
|
|
if (true === OSHelper::isWindows()) { |
84
|
|
|
$command .= ".exe"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// Return the command. |
88
|
|
|
return realpath($command); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the output path. |
93
|
|
|
* |
94
|
|
|
* @return string Returns the output path. |
95
|
|
|
*/ |
96
|
|
|
public function getOutputPath() { |
97
|
|
|
return $this->outputPath; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the scriptsPath. |
102
|
|
|
* |
103
|
|
|
* @return string Returns the scriptsPath. |
104
|
|
|
*/ |
105
|
|
|
public function getScriptsPath() { |
106
|
|
|
return $this->scriptsPath; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set the binary path. |
111
|
|
|
* |
112
|
|
|
* @param string $binaryPath The binary path. |
113
|
|
|
* @return PhantomJSHelper Returns this PhantomJS helper. |
114
|
|
|
*/ |
115
|
|
|
protected function setBinaryPath($binaryPath) { |
116
|
|
|
$this->binaryPath = $binaryPath; |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the output path. |
122
|
|
|
* |
123
|
|
|
* @param string $outputPath The output path. |
124
|
|
|
* @return PhantomJSHelper Returns this PhantomJS helper. |
125
|
|
|
*/ |
126
|
|
|
protected function setOutputPath($outputPath) { |
127
|
|
|
$this->outputPath = $outputPath; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Set the scripts path. |
133
|
|
|
* |
134
|
|
|
* @param string $scriptsPath The scripts path. |
135
|
|
|
* @return PhantomJSHelper Returns this PhantomJS helper. |
136
|
|
|
*/ |
137
|
|
|
protected function setScriptsPath($scriptsPath) { |
138
|
|
|
$this->scriptsPath = $scriptsPath; |
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|