1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Waredesk; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\HandlerStack; |
6
|
|
|
|
7
|
|
|
class Waredesk |
8
|
|
|
{ |
9
|
|
|
const PRODUCTION_API_URL = 'https://api.waredesk.com'; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var Codes |
13
|
|
|
*/ |
14
|
|
|
public $codes; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Products |
18
|
|
|
*/ |
19
|
|
|
public $products; |
20
|
|
|
|
21
|
|
|
private $apiUrl; |
22
|
|
|
private $requestHandler; |
23
|
|
|
|
24
|
15 |
|
public function __construct(string $clientId, string $clientSecret, string $accessToken = null) |
25
|
|
|
{ |
26
|
15 |
|
$this->apiUrl = self::PRODUCTION_API_URL; |
27
|
15 |
|
$this->requestHandler = new RequestHandler($clientId, $clientSecret, $accessToken, $this->apiUrl); |
28
|
15 |
|
$this->products = new Products($this->requestHandler); |
29
|
15 |
|
$this->codes = new Codes($this->requestHandler); |
30
|
15 |
|
$this->categories = new Categories($this->requestHandler); |
|
|
|
|
31
|
15 |
|
} |
32
|
|
|
|
33
|
|
|
public function getApiUrl() |
34
|
|
|
{ |
35
|
|
|
return $this->apiUrl; |
36
|
|
|
} |
37
|
|
|
|
38
|
15 |
|
public function setApiUrl($apiUrl) |
39
|
|
|
{ |
40
|
15 |
|
$this->apiUrl = rtrim($apiUrl, '/'); |
41
|
15 |
|
$this->requestHandler->setApiUrl($this->apiUrl); |
42
|
15 |
|
} |
43
|
|
|
|
44
|
|
|
public function getClientId(): string |
45
|
|
|
{ |
46
|
|
|
return $this->requestHandler->getClientId(); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
public function setClientId(string $clientId = null) |
50
|
|
|
{ |
51
|
1 |
|
$this->requestHandler->setClientId($clientId); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
public function getClientSecret(): string |
55
|
|
|
{ |
56
|
|
|
return $this->requestHandler->getClientSecret(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setClientSecret(string $clientSecret = null) |
60
|
|
|
{ |
61
|
|
|
$this->requestHandler->setClientSecret($clientSecret); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
public function getAccessToken(): string |
65
|
|
|
{ |
66
|
2 |
|
return $this->requestHandler->getAccessToken(); |
67
|
|
|
} |
68
|
|
|
|
69
|
15 |
|
public function setAccessToken(string $accessToken = null) |
70
|
|
|
{ |
71
|
15 |
|
$this->requestHandler->setAccessToken($accessToken); |
72
|
15 |
|
} |
73
|
|
|
|
74
|
15 |
|
public function setMockHandler(HandlerStack $mockHandler = null) |
75
|
|
|
{ |
76
|
15 |
|
$this->requestHandler->setMockHandler($mockHandler); |
77
|
15 |
|
} |
78
|
|
|
} |
79
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: