44
55namespace SimpleAsFuck \ApiToolkit \Service \Client ;
66
7- use Illuminate \Contracts \Config \Repository ;
8- use SimpleAsFuck \Validator \Factory \Validator ;
9- use SimpleAsFuck \Validator \Rule \General \Rules ;
7+ use SimpleAsFuck \ApiToolkit \Service \Config \LaravelAdapter ;
108
119final class LaravelConfig extends Config
1210{
1311 public function __construct (
14- private Repository $ repository
12+ private readonly LaravelAdapter $ laravelAdapter
1513 ) {
1614 }
1715
@@ -21,40 +19,45 @@ public function __construct(
2119 */
2220 public function getBaseUrl (string $ apiName ): string
2321 {
24- return $ this ->getValue ('services. ' .$ apiName .'.base_url ' )->string ()->notEmpty ()->notNull ();
22+ return $ this ->laravelAdapter -> get ('services. ' .$ apiName .'.base_url ' )->string ()->notEmpty ()->notNull ();
2523 }
2624
2725 /**
26+ * @deprecated in 0.6 will be removed use $this->getDefaultHeaders
2827 * @param non-empty-string $apiName
2928 * @return non-empty-string|null
3029 */
3130 public function getBearerToken (string $ apiName ): ?string
3231 {
33- return $ this ->getValue ('services. ' .$ apiName .'.token ' )->string ()->notEmpty ()->nullable ();
32+ return $ this ->laravelAdapter -> get ('services. ' .$ apiName .'.token ' )->string ()->notEmpty ()->nullable ();
3433 }
3534
3635 /**
3736 * @param non-empty-string $apiName
37+ * @return array<string>
3838 */
39- public function getVerifyCerts (string $ apiName ): bool
39+ public function getDefaultHeaders (string $ apiName ): array
4040 {
41- return $ this ->getValue ('services. ' .$ apiName .'.verify ' )->bool ()->nullable () ?? parent ::getVerifyCerts ($ apiName );
41+ return [
42+ ...parent ::getDefaultHeaders ($ apiName ),
43+ ...$ this ->laravelAdapter ->get ('services. ' .$ apiName .'.default_headers ' )->array ()->ofString ()->nullable () ?? [],
44+ ];
4245 }
4346
4447 /**
4548 * @param non-empty-string $apiName
46- * @return non-empty-string
4749 */
48- public function getDeprecatedHeader (string $ apiName ): string
50+ public function getVerifyCerts (string $ apiName ): bool
4951 {
50- return $ this ->getValue ('services. ' .$ apiName .'deprecated_header ' )->string ()->notEmpty ()-> nullable () ?? parent ::getDeprecatedHeader ($ apiName );
52+ return $ this ->laravelAdapter -> get ('services. ' .$ apiName .'.verify ' )->bool ()->nullable () ?? parent ::getVerifyCerts ($ apiName );
5153 }
5254
5355 /**
54- * @param non-empty-string $key
56+ * @param non-empty-string $apiName
57+ * @return non-empty-string
5558 */
56- private function getValue (string $ key ): Rules
59+ public function getDeprecatedHeader (string $ apiName ): string
5760 {
58- return Validator:: make ( $ this ->repository ->get ($ key ), ' Config key ' . $ key );
61+ return $ this ->laravelAdapter ->get (' services. ' . $ apiName . ' deprecated_header ' )-> string ()-> notEmpty ()-> nullable () ?? parent :: getDeprecatedHeader ( $ apiName );
5962 }
6063}
0 commit comments