Skip to content

Commit 7c405cf

Browse files
committed
add deprecated warnings in old client
1 parent c5f19cd commit 7c405cf

File tree

2 files changed

+74
-18
lines changed

2 files changed

+74
-18
lines changed

docs/migrate-to-nativecurlclient.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ This example shows how you can parse the response body of a DELETE request.
107107

108108
```diff
109109
-$dataAsString = $this->client->delete($path);
110-
+$this->client->requestDelte($path);
110+
+$this->client->requestDelete($path);
111111
+$dataAsString = $this->client->getLastResponseBody();
112112
```
113113

@@ -237,7 +237,7 @@ test your code without errors and now simply switch the client.
237237
```diff
238238
// Instantiate with ApiKey
239239
-$client = new \Redmine\Client(
240-
+$client = new \Redmine\Client\Prs18Client(
240+
+$client = new \Redmine\Client\NativeCurlClient(
241241
'https://redmine.example.com',
242242
'1234567890abcdfgh'
243243
);

src/Redmine/Client.php

+72-16
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __construct($url, $apikeyOrUsername, $pass = null)
9999
/**
100100
* PHP getter magic method.
101101
*
102-
* @deprecated
102+
* @deprecated use getApi() instead
103103
*
104104
* @param string $name
105105
*
@@ -109,20 +109,24 @@ public function __construct($url, $apikeyOrUsername, $pass = null)
109109
*/
110110
public function __get($name)
111111
{
112-
return $this->api($name);
112+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use getApi() instead.', E_USER_DEPRECATED);
113+
114+
return $this->getApi(strval($name));
113115
}
114116

115117
/**
116118
* @param string $name
117119
*
118-
* @deprecated
120+
* @deprecated use getApi() instead
119121
*
120122
* @throws \InvalidArgumentException
121123
*
122124
* @return Api\AbstractApi
123125
*/
124126
public function api($name)
125127
{
128+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use getApi() instead.', E_USER_DEPRECATED);
129+
126130
return $this->getApi(strval($name));
127131
}
128132

@@ -135,6 +139,8 @@ public function api($name)
135139
*/
136140
public function getUrl()
137141
{
142+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
143+
138144
return $this->url;
139145
}
140146

@@ -205,7 +211,7 @@ public function getLastResponseBody(): string
205211
/**
206212
* HTTP GETs a json $path and tries to decode it.
207213
*
208-
* @deprecated
214+
* @deprecated use requestGet() instead
209215
*
210216
* @param string $path
211217
* @param bool $decode
@@ -214,6 +220,8 @@ public function getLastResponseBody(): string
214220
*/
215221
public function get($path, $decode = true)
216222
{
223+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use requestGet() instead.', E_USER_DEPRECATED);
224+
217225
if (false === $json = $this->runRequest($path, 'GET')) {
218226
return false;
219227
}
@@ -239,6 +247,8 @@ public function get($path, $decode = true)
239247
*/
240248
public function decode($json)
241249
{
250+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
251+
242252
if (empty($json)) {
243253
return '';
244254
}
@@ -256,7 +266,7 @@ public function decode($json)
256266
/**
257267
* HTTP POSTs $params to $path.
258268
*
259-
* @deprecated
269+
* @deprecated use requestPost() instead
260270
*
261271
* @param string $path
262272
* @param string $data
@@ -265,13 +275,15 @@ public function decode($json)
265275
*/
266276
public function post($path, $data)
267277
{
278+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use requestPost() instead.', E_USER_DEPRECATED);
279+
268280
return $this->runRequest($path, 'POST', $data);
269281
}
270282

271283
/**
272284
* HTTP PUTs $params to $path.
273285
*
274-
* @deprecated
286+
* @deprecated use requestPut() instead
275287
*
276288
* @param string $path
277289
* @param string $data
@@ -280,34 +292,40 @@ public function post($path, $data)
280292
*/
281293
public function put($path, $data)
282294
{
295+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use requestPut() instead.', E_USER_DEPRECATED);
296+
283297
return $this->runRequest($path, 'PUT', $data);
284298
}
285299

286300
/**
287301
* HTTP PUTs $params to $path.
288302
*
289-
* @deprecated
303+
* @deprecated use requestDelete() instead
290304
*
291305
* @param string $path
292306
*
293307
* @return false|\SimpleXMLElement|string
294308
*/
295309
public function delete($path)
296310
{
311+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use requestDelete() instead.', E_USER_DEPRECATED);
312+
297313
return $this->runRequest($path, 'DELETE');
298314
}
299315

300316
/**
301317
* Turns on/off ssl certificate check.
302318
*
303-
* @deprecated
319+
* @deprecated use setCurlOption() instead
304320
*
305321
* @param bool $check
306322
*
307323
* @return Client
308324
*/
309325
public function setCheckSslCertificate($check = false)
310326
{
327+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use setCurlOption() instead.', E_USER_DEPRECATED);
328+
311329
$this->checkSslCertificate = $check;
312330

313331
return $this;
@@ -322,20 +340,24 @@ public function setCheckSslCertificate($check = false)
322340
*/
323341
public function getCheckSslCertificate()
324342
{
343+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
344+
325345
return $this->checkSslCertificate;
326346
}
327347

328348
/**
329349
* Turns on/off ssl host certificate check.
330350
*
331-
* @deprecated
351+
* @deprecated use setCurlOption() instead
332352
*
333353
* @param bool $check
334354
*
335355
* @return Client
336356
*/
337357
public function setCheckSslHost($check = false)
338358
{
359+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use setCurlOption() instead.', E_USER_DEPRECATED);
360+
339361
$this->checkSslHost = (bool) $check;
340362

341363
return $this;
@@ -350,13 +372,15 @@ public function setCheckSslHost($check = false)
350372
*/
351373
public function getCheckSslHost()
352374
{
375+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
376+
353377
return $this->checkSslHost;
354378
}
355379

356380
/**
357381
* Forces the SSL/TLS version to use.
358382
*
359-
* @deprecated
383+
* @deprecated use setCurlOption() instead
360384
* @see http://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html
361385
*
362386
* @param int $sslVersion
@@ -365,6 +389,8 @@ public function getCheckSslHost()
365389
*/
366390
public function setSslVersion($sslVersion = 0)
367391
{
392+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use setCurlOption() instead.', E_USER_DEPRECATED);
393+
368394
$this->sslVersion = $sslVersion;
369395

370396
return $this;
@@ -379,20 +405,24 @@ public function setSslVersion($sslVersion = 0)
379405
*/
380406
public function getSslVersion()
381407
{
408+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
409+
382410
return $this->sslVersion;
383411
}
384412

385413
/**
386414
* Turns on/off http auth.
387415
*
388-
* @deprecated
416+
* @deprecated use setCurlOption() instead
389417
*
390418
* @param bool $use
391419
*
392420
* @return Client
393421
*/
394422
public function setUseHttpAuth($use = true)
395423
{
424+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use setCurlOption() instead.', E_USER_DEPRECATED);
425+
396426
$this->useHttpAuth = $use;
397427

398428
return $this;
@@ -407,20 +437,24 @@ public function setUseHttpAuth($use = true)
407437
*/
408438
public function getUseHttpAuth()
409439
{
440+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
441+
410442
return $this->useHttpAuth;
411443
}
412444

413445
/**
414446
* Set the port of the connection.
415447
*
416-
* @deprecated
448+
* @deprecated use setCurlOption() instead
417449
*
418450
* @param int $port
419451
*
420452
* @return Client
421453
*/
422454
public function setPort($port = null)
423455
{
456+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use setCurlOption() instead.', E_USER_DEPRECATED);
457+
424458
if (null !== $port) {
425459
$this->port = (int) $port;
426460
}
@@ -431,13 +465,15 @@ public function setPort($port = null)
431465
/**
432466
* Returns Redmine response code.
433467
*
434-
* @deprecated
468+
* @deprecated use getLastResponseStatusCode() instead
435469
*
436470
* @return int
437471
*/
438472
public function getResponseCode()
439473
{
440-
return (int) $this->responseCode;
474+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use getLastResponseStatusCode() instead.', E_USER_DEPRECATED);
475+
476+
return (int) $this->getLastResponseStatusCode();
441477
}
442478

443479
/**
@@ -451,11 +487,13 @@ public function getResponseCode()
451487
*/
452488
public function getPort()
453489
{
490+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
491+
454492
if (null !== $this->port) {
455493
return $this->port;
456494
}
457495

458-
$tmp = parse_url($this->getUrl());
496+
$tmp = parse_url($this->url);
459497
if (isset($tmp['port'])) {
460498
$this->setPort($tmp['port']);
461499
} elseif (isset($tmp['scheme'])) {
@@ -486,7 +524,7 @@ public function stopImpersonateUser(): void
486524
* Sets to an existing username so api calls can be
487525
* impersonated to this user.
488526
*
489-
* @deprecated
527+
* @deprecated use startImpersonateUser() and stopImpersonateUser() instead
490528
*
491529
* @param string|null $username
492530
*
@@ -495,8 +533,12 @@ public function stopImpersonateUser(): void
495533
public function setImpersonateUser($username = null)
496534
{
497535
if (null === $username) {
536+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use stopImpersonateUser() instead.', E_USER_DEPRECATED);
537+
498538
$this->stopImpersonateUser();
499539
} else {
540+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use startImpersonateUser() instead.', E_USER_DEPRECATED);
541+
500542
$this->startImpersonateUser($username);
501543
}
502544

@@ -512,6 +554,8 @@ public function setImpersonateUser($username = null)
512554
*/
513555
public function getImpersonateUser()
514556
{
557+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
558+
515559
return $this->impersonateUser;
516560
}
517561

@@ -524,6 +568,8 @@ public function getImpersonateUser()
524568
*/
525569
public function setCustomHost($customHost = null)
526570
{
571+
@trigger_error('The ' . __METHOD__ . ' method is deprecated, use setCurlOption() instead.', E_USER_DEPRECATED);
572+
527573
$this->customHost = $customHost;
528574

529575
return $this;
@@ -536,6 +582,8 @@ public function setCustomHost($customHost = null)
536582
*/
537583
public function getCustomHost()
538584
{
585+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
586+
539587
return $this->customHost;
540588
}
541589

@@ -577,6 +625,8 @@ public function unsetCurlOption($option)
577625
*/
578626
public function getCurlOptions()
579627
{
628+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
629+
580630
return $this->curlOptions;
581631
}
582632

@@ -593,6 +643,8 @@ public function getCurlOptions()
593643
*/
594644
public function prepareRequest($path, $method = 'GET', $data = '')
595645
{
646+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
647+
596648
$this->responseCode = 0;
597649
$this->responseContentType = '';
598650
$this->responseBody = '';
@@ -724,6 +776,8 @@ private function setHttpHeader($path)
724776
*/
725777
public function processCurlResponse($response, $contentType)
726778
{
779+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
780+
727781
if ($response) {
728782
// if response is XML, return an SimpleXMLElement object
729783
if (0 === strpos($contentType, 'application/xml')) {
@@ -751,6 +805,8 @@ public function processCurlResponse($response, $contentType)
751805
*/
752806
protected function runRequest($path, $method = 'GET', $data = '')
753807
{
808+
@trigger_error('The ' . __METHOD__ . ' method is deprecated. You should stop using it, as it will be removed in the future.', E_USER_DEPRECATED);
809+
754810
$curl = $this->prepareRequest($path, $method, $data);
755811

756812
// use HTTP 1.1

0 commit comments

Comments
 (0)