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