1 | <?php |
||
22 | abstract class AbstractApiClient implements ApiClientInterface |
||
23 | { |
||
24 | const MAX_RETRY_LIMIT = 3; |
||
25 | |||
26 | /** |
||
27 | * HTTP client. |
||
28 | * |
||
29 | * @var ClientInterface |
||
30 | */ |
||
31 | protected $client; |
||
32 | |||
33 | /** |
||
34 | * Authentication object. |
||
35 | * |
||
36 | * @var AuthenticationInterface |
||
37 | */ |
||
38 | protected $authenticator; |
||
39 | |||
40 | /** |
||
41 | * Retry attempt counter for authentication. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $authenticationRetryAttempt = 0; |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | public function __construct( |
||
51 | ClientInterface $client, |
||
52 | AuthenticationInterface $authenticator |
||
53 | ) { |
||
54 | $this->client = $client; |
||
55 | $this->authenticator = $authenticator; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Sets authentication retry limit to 0. |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | protected function resetAuthenticationRetryAttempt() |
||
64 | { |
||
65 | $this->authenticationRetryAttempt = 0; |
||
66 | |||
67 | return; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Increments the authentication retry attempt with 1. |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | protected function incrementAuthenticationRetryAttempt() |
||
76 | { |
||
77 | $this->authenticationRetryAttempt++; |
||
78 | |||
79 | return; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Returns authentication retry count. |
||
84 | * |
||
85 | * @return int |
||
86 | */ |
||
87 | public function getAuthenticationRetryAttempt() |
||
91 | |||
92 | /** |
||
93 | * Returns whether the authentication limit is reached. |
||
94 | * |
||
95 | * @return boolean |
||
96 | */ |
||
97 | protected function isAuthenticationRetryLimitReached() |
||
101 | } |
||
102 |