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