1 | <?php |
||
36 | class RetrofitBuilder |
||
37 | { |
||
38 | /** |
||
39 | * Directory to store generated proxy clients |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $cacheDir; |
||
44 | |||
45 | /** |
||
46 | * A Retrofit http client used to make requests |
||
47 | * |
||
48 | * @var HttpClient |
||
49 | */ |
||
50 | private $httpClient; |
||
51 | |||
52 | /** |
||
53 | * The service's base url |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | private $baseUrl; |
||
58 | |||
59 | /** |
||
60 | * An array of factories used to create [@see CallAdapter]s |
||
61 | * |
||
62 | * @var CallAdapterFactory[] |
||
63 | */ |
||
64 | private $callAdapterFactories = []; |
||
65 | |||
66 | /** |
||
67 | * An array of factories used to convert types |
||
68 | * |
||
69 | * @var ConverterFactory[] |
||
70 | */ |
||
71 | private $converterFactories = []; |
||
72 | |||
73 | /** |
||
74 | * An array of factories used to create [@see Proxy] objects |
||
75 | * |
||
76 | * @var ProxyFactory[] |
||
77 | */ |
||
78 | private $proxyFactories = []; |
||
79 | |||
80 | /** |
||
81 | * An array of handlers used to modify the request based on an annotation |
||
82 | * |
||
83 | * @var AnnotationHandler[] |
||
84 | */ |
||
85 | private $annotationHandlers = []; |
||
86 | |||
87 | /** |
||
88 | * If we should cache the proxies |
||
89 | * |
||
90 | * @var bool |
||
91 | */ |
||
92 | private $shouldCache = false; |
||
93 | |||
94 | /** |
||
95 | * Set the cache directory |
||
96 | * |
||
97 | * @param string $cacheDir |
||
98 | * @return $this |
||
99 | */ |
||
100 | 1 | public function setCacheDir(string $cacheDir): RetrofitBuilder |
|
106 | |||
107 | /** |
||
108 | * Set the Retrofit http client |
||
109 | * |
||
110 | * @param HttpClient $client |
||
111 | * @return $this |
||
112 | */ |
||
113 | 18 | public function setHttpClient(HttpClient $client): RetrofitBuilder |
|
119 | |||
120 | /** |
||
121 | * Set the base url |
||
122 | * |
||
123 | * @param string $baseUrl |
||
124 | * @return RetrofitBuilder |
||
125 | */ |
||
126 | 18 | public function setBaseUrl(string $baseUrl): RetrofitBuilder |
|
132 | |||
133 | /** |
||
134 | * Add a [@see CallAdapterFactory] |
||
135 | * |
||
136 | * @param CallAdapterFactory $callAdapterFactory |
||
137 | * @return RetrofitBuilder |
||
138 | */ |
||
139 | 1 | public function addCallAdapterFactory(CallAdapterFactory $callAdapterFactory): RetrofitBuilder |
|
145 | |||
146 | /** |
||
147 | * Add a [@see ConverterFactory] |
||
148 | * |
||
149 | * @param ConverterFactory $converterFactory |
||
150 | * @return RetrofitBuilder |
||
151 | */ |
||
152 | 2 | public function addConverterFactory(ConverterFactory $converterFactory): RetrofitBuilder |
|
158 | |||
159 | /** |
||
160 | * Add a [@see ProxyFactory] |
||
161 | * |
||
162 | * @param ProxyFactory $proxyFactory |
||
163 | * @return RetrofitBuilder |
||
164 | */ |
||
165 | 1 | public function addProxyFactory(ProxyFactory $proxyFactory): RetrofitBuilder |
|
171 | |||
172 | /** |
||
173 | * Add an [@see AnnotationHandler] |
||
174 | * |
||
175 | * @param string $annotationName |
||
176 | * @param AnnotationHandler $annotationHandler |
||
177 | * @return RetrofitBuilder |
||
178 | */ |
||
179 | 1 | public function addAnnotationHandler(string $annotationName, AnnotationHandler $annotationHandler): RetrofitBuilder |
|
185 | |||
186 | /** |
||
187 | * Enable caching proxies |
||
188 | * |
||
189 | * @param bool $enable |
||
190 | * @return RetrofitBuilder |
||
191 | */ |
||
192 | 2 | public function enableCache(bool $enable = true): RetrofitBuilder |
|
198 | |||
199 | /** |
||
200 | * Build a retrofit instance |
||
201 | * |
||
202 | * @return Retrofit |
||
203 | * @throws \Doctrine\Common\Annotations\AnnotationException |
||
204 | * @throws \LogicException |
||
205 | */ |
||
206 | 17 | public function build(): Retrofit |
|
218 | |||
219 | /** |
||
220 | * Creates the default proxy factory and all necessary dependencies |
||
221 | * |
||
222 | * @return ProxyFactory |
||
223 | * @throws \Doctrine\Common\Annotations\AnnotationException |
||
224 | * @throws \LogicException |
||
225 | */ |
||
226 | 17 | private function createDefaultProxyFactory(): ProxyFactory |
|
295 | } |
||
296 |