1 | <?php |
||
35 | class RetrofitBuilder |
||
36 | { |
||
37 | /** |
||
38 | * A cache interface to be used in place of defaults |
||
39 | * |
||
40 | * If this is set, [@see RetrofitBuilder::$shouldCache] will be ignored for internal |
||
41 | * caches, however, [@see RetrofitBuilder::$shouldCache] and |
||
42 | * [@see RetrofitBuilder::$cacheDir] will still be used to cache proxy clients. |
||
43 | * |
||
44 | * @var CacheInterface |
||
45 | */ |
||
46 | private $cache; |
||
47 | |||
48 | /** |
||
49 | * Directory to store generated proxy clients |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $cacheDir; |
||
54 | |||
55 | /** |
||
56 | * A Retrofit http client used to make requests |
||
57 | * |
||
58 | * @var HttpClient |
||
59 | */ |
||
60 | private $httpClient; |
||
61 | |||
62 | /** |
||
63 | * The service's base url |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | private $baseUrl; |
||
68 | |||
69 | /** |
||
70 | * An array of factories used to create [@see CallAdapter]s |
||
71 | * |
||
72 | * @var CallAdapterFactory[] |
||
73 | */ |
||
74 | private $callAdapterFactories = []; |
||
75 | |||
76 | /** |
||
77 | * An array of factories used to convert types |
||
78 | * |
||
79 | * @var ConverterFactory[] |
||
80 | */ |
||
81 | private $converterFactories = []; |
||
82 | |||
83 | /** |
||
84 | * An array of factories used to create [@see Proxy] objects |
||
85 | * |
||
86 | * @var ProxyFactory[] |
||
87 | */ |
||
88 | private $proxyFactories = []; |
||
89 | |||
90 | /** |
||
91 | * An array of handlers used to modify the request based on an annotation |
||
92 | * |
||
93 | * @var AnnotationHandler[] |
||
94 | */ |
||
95 | private $annotationHandlers = []; |
||
96 | |||
97 | /** |
||
98 | * If we should cache the proxies |
||
99 | * |
||
100 | * @var bool |
||
101 | */ |
||
102 | private $shouldCache = false; |
||
103 | |||
104 | /** |
||
105 | * Override default cache adapters |
||
106 | * |
||
107 | * @param CacheInterface $cache |
||
108 | * @return RetrofitBuilder |
||
109 | */ |
||
110 | 1 | public function setCache(CacheInterface $cache): RetrofitBuilder |
|
116 | |||
117 | /** |
||
118 | * Set the cache directory |
||
119 | * |
||
120 | * @param string $cacheDir |
||
121 | * @return RetrofitBuilder |
||
122 | */ |
||
123 | 1 | public function setCacheDir(string $cacheDir): RetrofitBuilder |
|
129 | |||
130 | /** |
||
131 | * Set the Retrofit http client |
||
132 | * |
||
133 | * @param HttpClient $client |
||
134 | * @return RetrofitBuilder |
||
135 | */ |
||
136 | 22 | public function setHttpClient(HttpClient $client): RetrofitBuilder |
|
142 | |||
143 | /** |
||
144 | * Set the base url |
||
145 | * |
||
146 | * @param string $baseUrl |
||
147 | * @return RetrofitBuilder |
||
148 | */ |
||
149 | 22 | public function setBaseUrl(string $baseUrl): RetrofitBuilder |
|
155 | |||
156 | /** |
||
157 | * Add a [@see CallAdapterFactory] |
||
158 | * |
||
159 | * @param CallAdapterFactory $callAdapterFactory |
||
160 | * @return RetrofitBuilder |
||
161 | */ |
||
162 | 1 | public function addCallAdapterFactory(CallAdapterFactory $callAdapterFactory): RetrofitBuilder |
|
168 | |||
169 | /** |
||
170 | * Add a [@see ConverterFactory] |
||
171 | * |
||
172 | * @param ConverterFactory $converterFactory |
||
173 | * @return RetrofitBuilder |
||
174 | */ |
||
175 | 2 | public function addConverterFactory(ConverterFactory $converterFactory): RetrofitBuilder |
|
181 | |||
182 | /** |
||
183 | * Add a [@see ProxyFactory] |
||
184 | * |
||
185 | * @param ProxyFactory $proxyFactory |
||
186 | * @return RetrofitBuilder |
||
187 | */ |
||
188 | 1 | public function addProxyFactory(ProxyFactory $proxyFactory): RetrofitBuilder |
|
194 | |||
195 | /** |
||
196 | * Add an [@see AnnotationHandler] |
||
197 | * |
||
198 | * @param string $annotationName |
||
199 | * @param AnnotationHandler $annotationHandler |
||
200 | * @return RetrofitBuilder |
||
201 | */ |
||
202 | 1 | public function addAnnotationHandler(string $annotationName, AnnotationHandler $annotationHandler): RetrofitBuilder |
|
208 | |||
209 | /** |
||
210 | * Enable caching proxies |
||
211 | * |
||
212 | * @param bool $enable |
||
213 | * @return RetrofitBuilder |
||
214 | */ |
||
215 | 2 | public function enableCache(bool $enable = true): RetrofitBuilder |
|
221 | |||
222 | /** |
||
223 | * Build a retrofit instance |
||
224 | * |
||
225 | * @return Retrofit |
||
226 | * @throws \LogicException |
||
227 | */ |
||
228 | 21 | public function build(): Retrofit |
|
240 | |||
241 | /** |
||
242 | * Creates the default proxy factory and all necessary dependencies |
||
243 | * |
||
244 | * @return ProxyFactory |
||
245 | * @throws \LogicException |
||
246 | */ |
||
247 | 21 | private function createDefaultProxyFactory(): ProxyFactory |
|
320 | } |
||
321 |