@@ -60,34 +60,24 @@ class Api
6060 private $ name ;
6161
6262 /**
63- * @var EncodingList
64- */
65- private $ encodings ;
66-
67- /**
68- * @var DecodingList
69- */
70- private $ decodings ;
71-
72- /**
73- * @var bool
63+ * @var Url
7464 */
75- private $ useEloquent ;
65+ private $ url ;
7666
7767 /**
78- * @var Url
68+ * @var Config
7969 */
80- private $ url ;
70+ private $ config ;
8171
8272 /**
83- * @var Jobs
73+ * @var EncodingList|null
8474 */
85- private $ jobs ;
75+ private $ encodings ;
8676
8777 /**
88- * @var string |null
78+ * @var DecodingList |null
8979 */
90- private $ supportedExt ;
80+ private $ decodings ;
9181
9282 /**
9383 * @var ContainerInterface|null
@@ -104,71 +94,27 @@ class Api
10494 */
10595 private $ responses ;
10696
107- /**
108- * @var array
109- */
110- private $ providers ;
111-
112- /**
113- * @var string|null
114- */
115- private $ connection ;
116-
117- /**
118- * @var bool
119- */
120- private $ transactions ;
121-
122- /**
123- * @var string|null
124- */
125- private $ modelNamespace ;
126-
12797 /**
12898 * Api constructor.
12999 *
130100 * @param Factory $factory
131101 * @param AggregateResolver $resolver
132- * @param $apiName
133- * @param EncodingList $encodings
134- * @param DecodingList $decodings
102+ * @param string $name
135103 * @param Url $url
136- * @param Jobs $jobs
137- * @param bool $useEloquent
138- * @param string|null $supportedExt
139- * @param array $providers
140- * @param string|null $connection
141- * @param bool $transactions
142- * @param string|null $modelNamespace
104+ * @param Config $config
143105 */
144106 public function __construct (
145107 Factory $ factory ,
146108 AggregateResolver $ resolver ,
147- $ apiName ,
148- EncodingList $ encodings ,
149- DecodingList $ decodings ,
109+ string $ name ,
150110 Url $ url ,
151- Jobs $ jobs ,
152- $ useEloquent = true ,
153- $ supportedExt = null ,
154- array $ providers = [],
155- string $ connection = null ,
156- bool $ transactions = true ,
157- string $ modelNamespace = null
111+ Config $ config
158112 ) {
159113 $ this ->factory = $ factory ;
160114 $ this ->resolver = $ resolver ;
161- $ this ->name = $ apiName ;
162- $ this ->encodings = $ encodings ;
163- $ this ->decodings = $ decodings ;
115+ $ this ->name = $ name ;
164116 $ this ->url = $ url ;
165- $ this ->jobs = $ jobs ;
166- $ this ->useEloquent = $ useEloquent ;
167- $ this ->supportedExt = $ supportedExt ;
168- $ this ->providers = $ providers ;
169- $ this ->connection = $ connection ;
170- $ this ->transactions = $ transactions ;
171- $ this ->modelNamespace = $ modelNamespace ;
117+ $ this ->config = $ config ;
172118 }
173119
174120 /**
@@ -223,7 +169,7 @@ public function getName()
223169 */
224170 public function isEloquent ()
225171 {
226- return $ this ->useEloquent ;
172+ return $ this ->config -> useEloquent () ;
227173 }
228174
229175 /**
@@ -239,7 +185,7 @@ public function getUrl()
239185 */
240186 public function getJobs ()
241187 {
242- return $ this ->jobs ;
188+ return Jobs:: fromArray ( $ this ->config -> jobs ()) ;
243189 }
244190
245191 /**
@@ -271,27 +217,38 @@ public function getStore()
271217 */
272218 public function getSupportedExtensions ()
273219 {
274- if (! $ this ->supportedExt ) {
275- return null ;
220+ if ($ ext = $ this ->config -> supportedExt () ) {
221+ return $ this -> factory -> createSupportedExtensions ( $ ext ) ;
276222 }
277223
278- return $ this -> factory -> createSupportedExtensions ( $ this -> supportedExt ) ;
224+ return null ;
279225 }
280226
281227 /**
282228 * @return EncodingList
283229 */
284230 public function getEncodings (): EncodingList
285231 {
286- return $ this ->encodings ;
232+ if ($ this ->encodings ) {
233+ return $ this ->encodings ;
234+ }
235+
236+ return $ this ->encodings = EncodingList::fromArray (
237+ $ this ->config ->encoding (),
238+ $ this ->url ->toString ()
239+ );
287240 }
288241
289242 /**
290243 * @return DecodingList
291244 */
292245 public function getDecodings (): DecodingList
293246 {
294- return $ this ->decodings ;
247+ if ($ this ->decodings ) {
248+ return $ this ->decodings ;
249+ }
250+
251+ return $ this ->decodings = DecodingList::fromArray ($ this ->config ->decoding ());
295252 }
296253
297254 /**
@@ -303,8 +260,8 @@ public function getDefaultCodec(): Codec
303260 {
304261 return $ this ->factory ->createCodec (
305262 $ this ->getContainer (),
306- $ this ->encodings ->find (MediaTypeInterface::JSON_API_MEDIA_TYPE ) ?: Encoding::jsonApi (),
307- $ this ->decodings ->find (MediaTypeInterface::JSON_API_MEDIA_TYPE )
263+ $ this ->getEncodings () ->find (MediaTypeInterface::JSON_API_MEDIA_TYPE ) ?: Encoding::jsonApi (),
264+ $ this ->getDecodings () ->find (MediaTypeInterface::JSON_API_MEDIA_TYPE )
308265 );
309266 }
310267
@@ -329,7 +286,7 @@ public function getResponses()
329286 */
330287 public function getConnection (): ?string
331288 {
332- return $ this ->connection ;
289+ return $ this ->config -> dbConnection () ;
333290 }
334291
335292 /**
@@ -339,7 +296,7 @@ public function getConnection(): ?string
339296 */
340297 public function hasTransactions (): bool
341298 {
342- return $ this ->transactions ;
299+ return $ this ->config -> dbTransactions () ;
343300 }
344301
345302 /**
@@ -356,7 +313,7 @@ public function exceptions(): ExceptionParserInterface
356313 */
357314 public function getModelNamespace (): ?string
358315 {
359- return $ this ->modelNamespace ;
316+ return $ this ->config -> modelNamespace () ;
360317 }
361318
362319 /**
@@ -438,7 +395,7 @@ public function providers(): ResourceProviders
438395 {
439396 return new ResourceProviders (
440397 $ this ->factory ,
441- $ this ->providers
398+ $ this ->config -> providers ()
442399 );
443400 }
444401
0 commit comments