|
1
|
|
|
<?php |
|
2
|
|
|
namespace Peridot\WebDriverManager\Binary; |
|
3
|
|
|
|
|
4
|
|
|
use Peridot\WebDriverManager\Binary\Decompression\BinaryDecompressorInterface; |
|
5
|
|
|
use Peridot\WebDriverManager\Binary\Decompression\ZipDecompressor; |
|
6
|
|
|
use Peridot\WebDriverManager\Binary\Request\BinaryRequestInterface; |
|
7
|
|
|
use Peridot\WebDriverManager\Binary\Request\StandardBinaryRequest; |
|
8
|
|
|
use Peridot\WebDriverManager\Event\EventEmitterTrait; |
|
9
|
|
|
use Peridot\WebDriverManager\OS\System; |
|
10
|
|
|
use Peridot\WebDriverManager\OS\SystemInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* BinaryResolver is responsible for all steps of resoling a binary - that is fetching, decompressing, and |
|
14
|
|
|
* determining OS requirements. |
|
15
|
|
|
* |
|
16
|
|
|
* @package Peridot\WebDriverManager\Binary |
|
17
|
|
|
*/ |
|
18
|
|
|
class BinaryResolver implements |
|
19
|
|
|
BinaryRequestInterface, |
|
20
|
|
|
BinaryDecompressorInterface, |
|
21
|
|
|
BinaryResolverInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use EventEmitterTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var BinaryRequestInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $request; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var BinaryDecompressorInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $decompressor; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var SystemInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $system; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param BinaryRequestInterface $request |
|
42
|
|
|
* @param BinaryDecompressorInterface $decompressor |
|
43
|
|
|
* @param SystemInterface $system |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
BinaryRequestInterface $request = null, |
|
47
|
|
|
BinaryDecompressorInterface $decompressor = null, |
|
48
|
|
|
SystemInterface $system = null |
|
49
|
|
|
) { |
|
50
|
|
|
$this->request = $request; |
|
51
|
|
|
$this->decompressor = $decompressor; |
|
52
|
|
|
$this->system = $system; |
|
53
|
|
|
|
|
54
|
|
|
$this->inherit(['progress', 'request.start', 'complete'], $this->getBinaryRequest()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
* |
|
60
|
|
|
* @return BinaryRequestInterface|StandardBinaryRequest |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getBinaryRequest() |
|
63
|
|
|
{ |
|
64
|
|
|
if ($this->request === null) { |
|
65
|
|
|
$this->request = new StandardBinaryRequest(); |
|
66
|
|
|
} |
|
67
|
|
|
return $this->request; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
* |
|
73
|
|
|
* @return BinaryDecompressorInterface|ZipDecompressor |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getBinaryDecompressor() |
|
76
|
|
|
{ |
|
77
|
|
|
if ($this->decompressor === null) { |
|
78
|
|
|
$this->decompressor = new ZipDecompressor(); |
|
79
|
|
|
} |
|
80
|
|
|
return $this->decompressor; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
* |
|
86
|
|
|
* @return System|SystemInterface |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getSystem() |
|
89
|
|
|
{ |
|
90
|
|
|
if ($this->system === null) { |
|
91
|
|
|
$this->system = new System(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $this->system; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $compressedFilePath |
|
101
|
|
|
* @param string $directory |
|
102
|
|
|
* @return bool |
|
103
|
|
|
*/ |
|
104
|
|
|
public function extract($compressedFilePath, $directory) |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->getBinaryDecompressor()->extract($compressedFilePath, $directory); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* {@inheritdoc} |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $url |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
public function request($url) |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->getBinaryRequest()->request($url); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|