|
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
|
|
|
* Base. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $base; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Path. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $path; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $path The path. |
|
47
|
|
|
* @param string $base The base. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct($path, $base) { |
|
50
|
|
|
$this->setBase($base); |
|
51
|
|
|
$this->setPath($path); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get the base. |
|
56
|
|
|
* |
|
57
|
|
|
* @return string Returns the base. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getBase() { |
|
60
|
|
|
return $this->base; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the command. |
|
65
|
|
|
* |
|
66
|
|
|
* @return string Returns the command. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getCommand() { |
|
69
|
|
|
|
|
70
|
|
|
// Initialize the command. |
|
71
|
|
|
$command = [ |
|
72
|
|
|
$this->getPath(), |
|
73
|
|
|
$this->getBase(), |
|
74
|
|
|
]; |
|
75
|
|
|
|
|
76
|
|
|
// Check the operating system. |
|
77
|
|
|
if (true === OSHelper::isWindows()) { |
|
78
|
|
|
$command[] = array_pop($command) . ".exe"; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// Return the command. |
|
82
|
|
|
return realpath(implode("/", $command)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get the path. |
|
87
|
|
|
* |
|
88
|
|
|
* @return string Returns the path. |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getPath() { |
|
91
|
|
|
return $this->path; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Set the base. |
|
96
|
|
|
* |
|
97
|
|
|
* @param string $base The base. |
|
98
|
|
|
* @return PhantomJSHelper Returns this phantomJS helper. |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function setBase($base) { |
|
101
|
|
|
$this->base = $base; |
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Set the path. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $path The path. |
|
109
|
|
|
* @return PhantomJSHelper Returns this phantomJS helper. |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function setPath($path) { |
|
112
|
|
|
$this->path = $path; |
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|