1 | <?php |
||
30 | class Builder |
||
31 | { |
||
32 | /** |
||
33 | * @var HttpAsyncClient |
||
34 | */ |
||
35 | private $httpClient; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $parameters; |
||
41 | |||
42 | /** |
||
43 | * @var MessageFactory |
||
44 | */ |
||
45 | private $requestFactory; |
||
46 | |||
47 | /** |
||
48 | * A HTTP client with all our plugins. |
||
49 | * |
||
50 | * @var PluginClient |
||
51 | */ |
||
52 | private $pluginClient; |
||
53 | |||
54 | /** |
||
55 | * True if we should create a new Plugin client at next request. |
||
56 | * |
||
57 | * @var bool |
||
58 | */ |
||
59 | private $httpClientModified = true; |
||
60 | |||
61 | /** |
||
62 | * @var Plugin[] |
||
63 | */ |
||
64 | private $plugins = array(); |
||
65 | |||
66 | /** |
||
67 | * @param array $parameters |
||
68 | * @param HttpAsyncClient|null $httpAsyncClient |
||
69 | * @param RequestFactory|null $requestFactory |
||
70 | */ |
||
71 | 4 | public function __construct( |
|
79 | |||
80 | /** |
||
81 | * @param HttpAsyncClient $httpAsyncClient |
||
82 | */ |
||
83 | public function setHttpClient(HttpAsyncClient $httpAsyncClient) |
||
87 | |||
88 | /** |
||
89 | * @param MessageFactory $requestFactory |
||
90 | */ |
||
91 | public function setRequestFactory($requestFactory) |
||
95 | |||
96 | /** |
||
97 | * @param array $parameters |
||
98 | */ |
||
99 | 2 | public function setParameters(array $parameters) |
|
103 | |||
104 | public function resolveParameters() |
||
112 | |||
113 | /** |
||
114 | * @return PluginClient |
||
115 | */ |
||
116 | 3 | public function getHttpClient() |
|
117 | { |
||
118 | 3 | if ($this->httpClientModified) { |
|
119 | 3 | $this->addPlugin(new Plugin\AuthenticationPlugin(new Wsse( |
|
120 | 3 | $this->parameters['username'], |
|
121 | 3 | $this->parameters['secret']) |
|
122 | 3 | )); |
|
123 | |||
124 | 3 | $this->addPlugin(new Plugin\BaseUriPlugin( |
|
125 | 3 | UriFactoryDiscovery::find()->createUri('https://api.emarsys.net/api/v2')) |
|
126 | 3 | ); |
|
127 | |||
128 | 3 | $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( |
|
129 | 3 | 'User-Agent' => 'emarsys-php-client (https://github.com/ck-developer/emarsys-php-client)', |
|
130 | 3 | ))); |
|
131 | |||
132 | 3 | $this->httpClientModified = false; |
|
133 | 3 | $this->pluginClient = new PluginClient($this->httpClient, $this->plugins); |
|
134 | 3 | } |
|
135 | |||
136 | 3 | return $this->pluginClient; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * @return MessageFactory |
||
141 | */ |
||
142 | 2 | public function getRequestFactory() |
|
146 | |||
147 | /** |
||
148 | * Add a new plugin to the end of the plugin chain. |
||
149 | * |
||
150 | * @param Plugin $plugin |
||
151 | */ |
||
152 | 3 | public function addPlugin(Plugin $plugin) |
|
157 | |||
158 | /** |
||
159 | * Remove a plugin by its fully qualified class name. |
||
160 | * |
||
161 | * @param string $class |
||
162 | */ |
||
163 | public function removePlugin($class) |
||
169 | } |
||
170 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.