1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace JonnyW\PhantomJs; |
11
|
|
|
|
12
|
|
|
use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface; |
13
|
|
|
use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface; |
14
|
|
|
use JonnyW\PhantomJs\IO\InputInterface; |
15
|
|
|
use JonnyW\PhantomJs\IO\OutputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* PHP PhantomJs. |
19
|
|
|
* |
20
|
|
|
* @author Jon Wenmoth <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Client implements ClientInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Client. |
26
|
|
|
* |
27
|
|
|
* @var \JonnyW\PhantomJs\Client\ClientInterface |
28
|
|
|
*/ |
29
|
|
|
protected static $instance; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* PhantomJs engine. |
33
|
|
|
* |
34
|
|
|
* @var \JonnyW\PhantomJs\Engine |
35
|
|
|
*/ |
36
|
|
|
protected $engine; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Procedure loader. |
40
|
|
|
* |
41
|
|
|
* @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface |
42
|
|
|
*/ |
43
|
|
|
protected $procedureLoader; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Procedure validator. |
47
|
|
|
* |
48
|
|
|
* @var \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface |
49
|
|
|
*/ |
50
|
|
|
protected $procedureCompiler; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Procedure template. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $procedure; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Internal constructor. |
61
|
|
|
* |
62
|
|
|
* @param \JonnyW\PhantomJs\Engine $engine |
63
|
|
|
* @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader |
64
|
|
|
* @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler |
65
|
|
|
*/ |
66
|
|
|
public function __construct(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler) |
67
|
|
|
{ |
68
|
|
|
$this->engine = $engine; |
69
|
|
|
$this->procedureLoader = $procedureLoader; |
70
|
|
|
$this->procedureCompiler = $procedureCompiler; |
71
|
|
|
$this->procedure = 'default'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get singleton instance. |
76
|
|
|
* |
77
|
|
|
* @return \JonnyW\PhantomJs\Client\ClientInterface |
78
|
|
|
*/ |
79
|
|
|
public static function getInstance() |
80
|
|
|
{ |
81
|
|
|
if (!self::$instance instanceof ClientInterface) { |
82
|
|
|
$serviceContainer = ServiceContainer::getInstance(); |
83
|
|
|
|
84
|
|
|
self::$instance = new static( |
|
|
|
|
85
|
|
|
$serviceContainer->get('engine'), |
86
|
|
|
$serviceContainer->get('procedure_loader'), |
87
|
|
|
$serviceContainer->get('procedure_compiler') |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return self::$instance; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Run client. |
96
|
|
|
* |
97
|
|
|
* @param \JonnyW\PhantomJs\IO\InputInterface $input |
98
|
|
|
* @param \JonnyW\PhantomJs\IO\OutputInterface $output |
99
|
|
|
* |
100
|
|
|
* @return \JonnyW\PhantomJs\IO\OutputInterface |
101
|
|
|
*/ |
102
|
|
|
public function run(InputInterface $input, OutputInterface $output) |
103
|
|
|
{ |
104
|
|
|
$procedure = $this->procedureLoader->load($this->procedure); |
105
|
|
|
|
106
|
|
|
$this->procedureCompiler->compile($procedure, $input); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$procedure->run($input, $output); |
|
|
|
|
109
|
|
|
|
110
|
|
|
return $output; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get PhantomJs engine. |
115
|
|
|
* |
116
|
|
|
* @return \JonnyW\PhantomJs\Engine |
117
|
|
|
*/ |
118
|
|
|
public function getEngine() |
119
|
|
|
{ |
120
|
|
|
return $this->engine; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get procedure loader instance. |
125
|
|
|
* |
126
|
|
|
* @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface |
127
|
|
|
*/ |
128
|
|
|
public function getProcedureLoader() |
129
|
|
|
{ |
130
|
|
|
return $this->procedureLoader; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get procedure compiler. |
135
|
|
|
* |
136
|
|
|
* @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface |
137
|
|
|
*/ |
138
|
|
|
public function getProcedureCompiler() |
139
|
|
|
{ |
140
|
|
|
return $this->procedureCompiler; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set procedure template. |
145
|
|
|
* |
146
|
|
|
* @param string $procedure |
147
|
|
|
*/ |
148
|
|
|
public function setProcedure($procedure) |
149
|
|
|
{ |
150
|
|
|
$this->procedure = $procedure; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get procedure template. |
155
|
|
|
* |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
public function getProcedure() |
159
|
|
|
{ |
160
|
|
|
return $this->procedure; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Get log. |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getLog() |
169
|
|
|
{ |
170
|
|
|
return $this->getEngine()->getLog(); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..