22
33namespace Expressionengine \Coilpack \Api \Graph \Support ;
44
5- use Expressionengine \Coilpack \Fieldtypes \Fieldtype ;
6- use Expressionengine \Coilpack \Models \Channel \ChannelField ;
7- use Expressionengine \Coilpack \FieldtypeManager ;
85use Expressionengine \Coilpack \Contracts \GeneratesGraphType ;
96use Expressionengine \Coilpack \Contracts \ListsGraphType ;
7+ use Expressionengine \Coilpack \FieldtypeManager ;
8+ use Expressionengine \Coilpack \Fieldtypes \Fieldtype ;
109use Expressionengine \Coilpack \Fieldtypes \Modifier ;
11- use Rebing \ GraphQL \ Support \ Facades \ GraphQL ;
10+ use Expressionengine \ Coilpack \ Models \ Channel \ ChannelField ;
1211use GraphQL \Type \Definition \Type ;
12+ use Rebing \GraphQL \Support \Facades \GraphQL ;
1313
14- class FieldtypeRegistrar {
15-
14+ class FieldtypeRegistrar
15+ {
1616 protected $ types = [];
17+
1718 protected $ inputs = [];
19+
1820 protected $ booted = false ;
1921
2022 public function __construct (FieldtypeManager $ manager )
@@ -24,7 +26,7 @@ public function __construct(FieldtypeManager $manager)
2426
2527 public function boot ()
2628 {
27- if ($ this ->booted ) {
29+ if ($ this ->booted ) {
2830 return ;
2931 }
3032
@@ -56,10 +58,10 @@ public function registerFieldtypes()
5658 {
5759 $ fieldtypes = $ this ->fieldtypeManager ->allFieldtypes ();
5860
59- foreach ($ fieldtypes as $ fieldtype ) {
61+ foreach ($ fieldtypes as $ fieldtype ) {
6062 $ fieldtype = app (FieldtypeManager::class)->make ($ fieldtype ->name );
6163 $ this ->registerFieldtype ($ fieldtype );
62- foreach ($ fieldtype ->modifiers () as $ modifier ) {
64+ foreach ($ fieldtype ->modifiers () as $ modifier ) {
6365 $ this ->registerModifier ($ modifier );
6466 }
6567 }
@@ -69,19 +71,19 @@ public function registerModifier(Modifier $modifier)
6971 {
7072 $ name = $ modifier ->getQualifiedName ();
7173
72- if (array_key_exists ($ name , $ this ->inputs )) {
74+ if (array_key_exists ($ name , $ this ->inputs )) {
7375 return GraphQL::type ($ name );
7476 }
7577
76- if (empty ($ modifier ->parameters )) {
78+ if (empty ($ modifier ->parameters )) {
7779 return null ;
7880 }
7981
8082 $ typeDefinition = new GeneratedInputType ([
8183 'name ' => $ name ,
8284 'fields ' => function () use ($ modifier ) {
8385 return $ modifier ->parameters ;
84- }
86+ },
8587 ]);
8688
8789 GraphQL::addType ($ typeDefinition , $ name );
@@ -98,21 +100,21 @@ public function registerField(ChannelField $field)
98100 {
99101 $ fieldtype = $ field ->getFieldType ();
100102
101- if ($ type = $ this ->registerFieldtype ($ fieldtype )) {
103+ if ($ type = $ this ->registerFieldtype ($ fieldtype )) {
102104 return $ type ;
103105 }
104106
105- if (array_key_exists ($ field ->field_name , $ this ->types )) {
107+ if (array_key_exists ($ field ->field_name , $ this ->types )) {
106108 return $ this ->types [$ field ->field_name ];
107109 }
108110
109111 $ name = "Field \\{$ field ->field_name }" ;
110112
111113 $ typeDefinition = new GeneratedType ([
112114 'name ' => $ name ,
113- 'fields ' => function () use ($ fieldtype , $ field ) {
115+ 'fields ' => function () use ($ fieldtype , $ field ) {
114116 return $ fieldtype ->generateGraphType ($ field );
115- }
117+ },
116118 ]);
117119
118120 GraphQL::addType ($ typeDefinition , $ name );
@@ -131,7 +133,7 @@ public function registerFieldtype(Fieldtype $fieldtype)
131133 return $ this ->types [$ fieldtype ->name ];
132134 }
133135
134- if (! $ fieldtype instanceof GeneratesGraphType) {
136+ if (! $ fieldtype instanceof GeneratesGraphType) {
135137 $ type = $ fieldtype ->graphType ();
136138 $ this ->types [$ fieldtype ->name ] = $ type ;
137139
@@ -143,7 +145,7 @@ public function getTypeForField($field)
143145 {
144146 $ type = $ this ->getType ($ field ->field_name );
145147 $ type = $ type ?: $ this ->getType ($ field ->field_type );
146- if ($ type === null ) {
148+ if ($ type === null ) {
147149 dd ($ field ->field_name , $ field ->field_type , $ field ->getFieldType (), $ this ->types );
148150 }
149151
@@ -158,6 +160,7 @@ public function getType($field)
158160
159161 if (array_key_exists ($ field , $ this ->types )) {
160162 $ type = $ this ->types [$ field ];
163+
161164 return (is_string ($ type )) ? GraphQL::type ($ type ) : $ this ->types [$ field ];
162165 }
163166
@@ -173,6 +176,4 @@ public function dd()
173176 {
174177 dd ($ this ->allTypes (), GraphQL::getTypes ());
175178 }
176-
177-
178- }
179+ }
0 commit comments