34
34
* The default implementation of {@link ClientBuilderInterface}.
35
35
*
36
36
* @author Stefano Arlandini <[email protected] >
37
- *
38
- * @method int getSendAttempts()
39
- * @method setSendAttempts(int $attemptsCount)
40
- * @method string[] getPrefixes()
41
- * @method setPrefixes(array $prefixes)
42
- * @method float getSampleRate()
43
- * @method setSampleRate(float $sampleRate)
44
- * @method bool shouldAttachStacktrace()
45
- * @method setAttachStacktrace(bool $enable)
46
- * @method int getContextLines()
47
- * @method setContextLines(int $contextLines)
48
- * @method null|string getEnvironment()
49
- * @method setEnvironment(null|string $environment)
50
- * @method string[] getExcludedProjectPaths()
51
- * @method setExcludedProjectPaths(string[] $paths)
52
- * @method setExcludedLoggers(string[] $loggers)
53
- * @method string[] getExcludedExceptions()
54
- * @method string getProjectRoot()
55
- * @method setProjectRoot(string $path)
56
- * @method string getLogger()
57
- * @method setLogger(string $logger)
58
- * @method string getRelease()
59
- * @method setRelease(string $release)
60
- * @method string getDsn()
61
- * @method string getServerName()
62
- * @method setServerName(string $serverName)
63
- * @method string[] getTags()
64
- * @method setTags(string[] $tags)
65
- * @method bool shouldSendDefaultPii()
66
- * @method setSendDefaultPii(bool $enable)
67
- * @method bool hasDefaultIntegrations()
68
- * @method setDefaultIntegrations(bool $enable)
69
- * @method callable getBeforeSendCallback()
70
- * @method setBeforeSendCallback(callable $beforeSend)
71
37
*/
72
38
final class ClientBuilder implements ClientBuilderInterface
73
39
{
@@ -124,11 +90,11 @@ final class ClientBuilder implements ClientBuilderInterface
124
90
/**
125
91
* Class constructor.
126
92
*
127
- * @param array $options The client options
93
+ * @param Options|null $options The client options
128
94
*/
129
- public function __construct (array $ options = [] )
95
+ public function __construct (Options $ options = null )
130
96
{
131
- $ this ->options = new Options ($ options );
97
+ $ this ->options = $ options ?? new Options ();
132
98
133
99
if ($ this ->options ->hasDefaultIntegrations ()) {
134
100
$ this ->options ->setIntegrations (\array_merge ([
@@ -141,15 +107,23 @@ public function __construct(array $options = [])
141
107
/**
142
108
* {@inheritdoc}
143
109
*/
144
- public static function create (array $ options = []): self
110
+ public static function create (array $ options = []): ClientBuilderInterface
145
111
{
146
- return new static ($ options );
112
+ return new static (new Options ( $ options) );
147
113
}
148
114
149
115
/**
150
116
* {@inheritdoc}
151
117
*/
152
- public function setUriFactory (UriFactory $ uriFactory ): self
118
+ public function getOptions (): Options
119
+ {
120
+ return $ this ->options ;
121
+ }
122
+
123
+ /**
124
+ * {@inheritdoc}
125
+ */
126
+ public function setUriFactory (UriFactory $ uriFactory ): ClientBuilderInterface
153
127
{
154
128
$ this ->uriFactory = $ uriFactory ;
155
129
@@ -159,7 +133,7 @@ public function setUriFactory(UriFactory $uriFactory): self
159
133
/**
160
134
* {@inheritdoc}
161
135
*/
162
- public function setMessageFactory (MessageFactory $ messageFactory ): self
136
+ public function setMessageFactory (MessageFactory $ messageFactory ): ClientBuilderInterface
163
137
{
164
138
$ this ->messageFactory = $ messageFactory ;
165
139
@@ -169,7 +143,7 @@ public function setMessageFactory(MessageFactory $messageFactory): self
169
143
/**
170
144
* {@inheritdoc}
171
145
*/
172
- public function setTransport (TransportInterface $ transport ): self
146
+ public function setTransport (TransportInterface $ transport ): ClientBuilderInterface
173
147
{
174
148
$ this ->transport = $ transport ;
175
149
@@ -179,7 +153,7 @@ public function setTransport(TransportInterface $transport): self
179
153
/**
180
154
* {@inheritdoc}
181
155
*/
182
- public function setHttpClient (HttpAsyncClient $ httpClient ): self
156
+ public function setHttpClient (HttpAsyncClient $ httpClient ): ClientBuilderInterface
183
157
{
184
158
$ this ->httpClient = $ httpClient ;
185
159
@@ -189,7 +163,7 @@ public function setHttpClient(HttpAsyncClient $httpClient): self
189
163
/**
190
164
* {@inheritdoc}
191
165
*/
192
- public function addHttpClientPlugin (Plugin $ plugin ): self
166
+ public function addHttpClientPlugin (Plugin $ plugin ): ClientBuilderInterface
193
167
{
194
168
$ this ->httpClientPlugins [] = $ plugin ;
195
169
@@ -199,7 +173,7 @@ public function addHttpClientPlugin(Plugin $plugin): self
199
173
/**
200
174
* {@inheritdoc}
201
175
*/
202
- public function removeHttpClientPlugin (string $ className ): self
176
+ public function removeHttpClientPlugin (string $ className ): ClientBuilderInterface
203
177
{
204
178
foreach ($ this ->httpClientPlugins as $ index => $ httpClientPlugin ) {
205
179
if (!$ httpClientPlugin instanceof $ className ) {
@@ -215,7 +189,7 @@ public function removeHttpClientPlugin(string $className): self
215
189
/**
216
190
* {@inheritdoc}
217
191
*/
218
- public function setSerializer (SerializerInterface $ serializer ): self
192
+ public function setSerializer (SerializerInterface $ serializer ): ClientBuilderInterface
219
193
{
220
194
$ this ->serializer = $ serializer ;
221
195
@@ -225,7 +199,7 @@ public function setSerializer(SerializerInterface $serializer): self
225
199
/**
226
200
* {@inheritdoc}
227
201
*/
228
- public function setRepresentationSerializer (RepresentationSerializerInterface $ representationSerializer ): self
202
+ public function setRepresentationSerializer (RepresentationSerializerInterface $ representationSerializer ): ClientBuilderInterface
229
203
{
230
204
$ this ->representationSerializer = $ representationSerializer ;
231
205
@@ -235,7 +209,7 @@ public function setRepresentationSerializer(RepresentationSerializerInterface $r
235
209
/**
236
210
* {@inheritdoc}
237
211
*/
238
- public function setSdkIdentifier (string $ sdkIdentifier ): self
212
+ public function setSdkIdentifier (string $ sdkIdentifier ): ClientBuilderInterface
239
213
{
240
214
$ this ->sdkIdentifier = $ sdkIdentifier ;
241
215
@@ -259,7 +233,7 @@ private function getSdkVersion(): string
259
233
/**
260
234
* {@inheritdoc}
261
235
*/
262
- public function setSdkVersion (string $ sdkVersion ): self
236
+ public function setSdkVersion (string $ sdkVersion ): ClientBuilderInterface
263
237
{
264
238
$ this ->sdkVersion = $ sdkVersion ;
265
239
@@ -273,7 +247,7 @@ public function setSdkVersion(string $sdkVersion): self
273
247
*
274
248
* @return $this
275
249
*/
276
- public function setSdkVersionByPackageName (string $ packageName ): self
250
+ public function setSdkVersionByPackageName (string $ packageName ): ClientBuilderInterface
277
251
{
278
252
$ this ->sdkVersion = PrettyVersions::getVersion ($ packageName )->getPrettyVersion ();
279
253
@@ -293,25 +267,6 @@ public function getClient(): ClientInterface
293
267
return new Client ($ this ->options , $ this ->transport , $ this ->createEventFactory ());
294
268
}
295
269
296
- /**
297
- * This method forwards all methods calls to the options object.
298
- *
299
- * @param string $name The name of the method being called
300
- * @param array $arguments Parameters passed to the $name'ed method
301
- *
302
- * @return $this
303
- *
304
- * @throws \BadMethodCallException If the called method does not exists
305
- */
306
- public function __call ($ name , $ arguments )
307
- {
308
- if (!method_exists ($ this ->options , $ name )) {
309
- throw new \BadMethodCallException (sprintf ('The method named "%s" does not exists. ' , $ name ));
310
- }
311
-
312
- return $ this ->options ->$ name (...$ arguments );
313
- }
314
-
315
270
/**
316
271
* Creates a new instance of the HTTP client.
317
272
*
0 commit comments