|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Vinelab\UrlShortener\Base; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class PackageManager is the heart of the package, |
|
7
|
|
|
* It' main job is to initialize the config file. |
|
8
|
|
|
* |
|
9
|
|
|
* @category Manager |
|
10
|
|
|
* |
|
11
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class PackageManager |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* default driver name. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $driverName; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* configurations of the default driver. |
|
24
|
|
|
* |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $driverParameters; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Http client. |
|
31
|
|
|
* |
|
32
|
|
|
* @var object |
|
33
|
|
|
*/ |
|
34
|
|
|
private $httpClient; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param \Vinelab\UrlShortener\Base\ConfigManager $config |
|
38
|
|
|
* @param null $httpClient The http Client 'will be injected here (mocked) for testing' |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(ConfigManager $config, $httpClient = null) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->setDriverName($config->driverName()); |
|
43
|
|
|
$this->setDriverParameters($config->driverParameters($this->getDriverName())); |
|
44
|
|
|
$this->setHttpClient($httpClient); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getDriverName() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->driverName; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getDriverParameters() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->driverParameters; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return object |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getHttpClient() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->httpClient; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $driverName |
|
73
|
|
|
*/ |
|
74
|
|
|
private function setDriverName($driverName) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->driverName = $driverName; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param array $driverParameters |
|
81
|
|
|
*/ |
|
82
|
|
|
private function setDriverParameters($driverParameters) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->driverParameters = $driverParameters; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param object $httpClient |
|
89
|
|
|
*/ |
|
90
|
|
|
private function setHttpClient($httpClient) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->httpClient = $httpClient; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: