1 | <?php |
||
23 | final class SyliusClient |
||
24 | { |
||
25 | /** |
||
26 | * @var HttpClient |
||
27 | */ |
||
28 | private $httpClient; |
||
29 | |||
30 | /** |
||
31 | * @var Hydrator |
||
32 | */ |
||
33 | private $hydrator; |
||
34 | |||
35 | /** |
||
36 | * @var RequestBuilder |
||
37 | */ |
||
38 | private $requestBuilder; |
||
39 | |||
40 | /** |
||
41 | * @var ClientConfigurator |
||
42 | */ |
||
43 | private $clientConfigurator; |
||
44 | |||
45 | /** |
||
46 | * @var string|null |
||
47 | */ |
||
48 | private $clientId; |
||
49 | |||
50 | /** |
||
51 | * @var string|null |
||
52 | */ |
||
53 | private $clientSecret; |
||
54 | |||
55 | /** |
||
56 | * @var Authenticator |
||
57 | */ |
||
58 | private $authenticator; |
||
59 | |||
60 | /** |
||
61 | * The constructor accepts already configured HTTP clients. |
||
62 | * Use the configure method to pass a configuration to the Client and create an HTTP Client. |
||
63 | */ |
||
64 | public function __construct( |
||
76 | |||
77 | public static function create(string $endpoint, string $clientId, string $clientSecret): self |
||
84 | |||
85 | /** |
||
86 | * Autnenticate a user with the API. This will return an access token. |
||
87 | * Warning, this will remove the current access token. |
||
88 | */ |
||
89 | public function createNewAccessToken(string $username, string $password): string |
||
95 | |||
96 | /** |
||
97 | * Autenticate the client with an access token. This should be the full access token object with |
||
98 | * refresh token and expirery timestamps. |
||
99 | * |
||
100 | * ```php |
||
101 | * $accessToken = $client->createNewAccessToken('foo', 'bar'); |
||
102 | * $client->authenticate($accessToken); |
||
103 | *``` |
||
104 | */ |
||
105 | public function authenticate(string $accessToken): void |
||
110 | |||
111 | /** |
||
112 | * The access token may have been refreshed during the requests. Use this function to |
||
113 | * get back the (possibly) refreshed access token. |
||
114 | */ |
||
115 | public function getAccessToken(): string |
||
119 | |||
120 | |||
121 | public function customer(): Api\Customer |
||
122 | { |
||
123 | return new Api\Customer($this->getHttpClient(), $this->hydrator, $this->requestBuilder); |
||
124 | } |
||
125 | |||
126 | public function cart(): Api\Cart |
||
127 | { |
||
128 | return new Api\Cart($this->getHttpClient(), $this->hydrator, $this->requestBuilder); |
||
129 | } |
||
130 | |||
131 | public function product(): Api\Product |
||
132 | { |
||
133 | return new Api\Product($this->getHttpClient(), $this->hydrator, $this->requestBuilder); |
||
134 | } |
||
135 | |||
136 | public function checkout(): Api\Checkout |
||
137 | { |
||
138 | return new Api\Checkout($this->getHttpClient(), $this->hydrator, $this->requestBuilder); |
||
139 | } |
||
140 | |||
141 | private function getHttpClient(): HttpClient |
||
145 | } |
||
146 |