@@ -24,63 +24,63 @@ |
||
24 | 24 | class EventFilterHeader extends AdminPageHeaderDecorator |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EEM_Event $event_model |
|
29 | - */ |
|
30 | - private $event_model; |
|
27 | + /** |
|
28 | + * @var EEM_Event $event_model |
|
29 | + */ |
|
30 | + private $event_model; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * EventFilterHeader constructor. |
|
35 | - * |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param EEM_Event $event_model |
|
38 | - */ |
|
39 | - public function __construct(RequestInterface $request, EEM_Event $event_model) |
|
40 | - { |
|
41 | - parent::__construct($request); |
|
42 | - $this->event_model = $event_model; |
|
43 | - } |
|
33 | + /** |
|
34 | + * EventFilterHeader constructor. |
|
35 | + * |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param EEM_Event $event_model |
|
38 | + */ |
|
39 | + public function __construct(RequestInterface $request, EEM_Event $event_model) |
|
40 | + { |
|
41 | + parent::__construct($request); |
|
42 | + $this->event_model = $event_model; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @param string $text |
|
48 | - * @return string |
|
49 | - * @throws EE_Error |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws ReflectionException |
|
54 | - * @since 4.10.2.p |
|
55 | - */ |
|
56 | - public function getHeaderText($text = '') |
|
57 | - { |
|
58 | - $EVT_ID = $this->request->getRequestParam('EVT_ID'); |
|
59 | - $EVT_ID = $this->request->getRequestParam('event_id', $EVT_ID); |
|
60 | - $EVT_ID = absint($EVT_ID); |
|
61 | - if ($EVT_ID) { |
|
62 | - $event = $this->event_model->get_one_by_ID($EVT_ID); |
|
63 | - if ($event instanceof EE_Event) { |
|
64 | - $text .= sprintf( |
|
65 | - /* translators: %s: <h3> %s: <a href>Event Name</a> %s: </h3> */ |
|
66 | - // phpcs:ignore WordPress.WP.I18n.UnorderedPlaceholdersText |
|
67 | - esc_html__('%s Viewing registrations for the event: %s%s', 'event_espresso'), |
|
68 | - '<h3 style="line-height:1.5em;">', |
|
69 | - ' <a href="' |
|
70 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
71 | - array( |
|
72 | - 'action' => 'edit', |
|
73 | - 'post' => $event->ID(), |
|
74 | - ), |
|
75 | - EVENTS_ADMIN_URL |
|
76 | - ) |
|
77 | - . '">' |
|
78 | - . $event->get('EVT_name') |
|
79 | - . '</a> ', |
|
80 | - '</h3>' |
|
81 | - ); |
|
82 | - } |
|
83 | - } |
|
84 | - return $text; |
|
85 | - } |
|
46 | + /** |
|
47 | + * @param string $text |
|
48 | + * @return string |
|
49 | + * @throws EE_Error |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws ReflectionException |
|
54 | + * @since 4.10.2.p |
|
55 | + */ |
|
56 | + public function getHeaderText($text = '') |
|
57 | + { |
|
58 | + $EVT_ID = $this->request->getRequestParam('EVT_ID'); |
|
59 | + $EVT_ID = $this->request->getRequestParam('event_id', $EVT_ID); |
|
60 | + $EVT_ID = absint($EVT_ID); |
|
61 | + if ($EVT_ID) { |
|
62 | + $event = $this->event_model->get_one_by_ID($EVT_ID); |
|
63 | + if ($event instanceof EE_Event) { |
|
64 | + $text .= sprintf( |
|
65 | + /* translators: %s: <h3> %s: <a href>Event Name</a> %s: </h3> */ |
|
66 | + // phpcs:ignore WordPress.WP.I18n.UnorderedPlaceholdersText |
|
67 | + esc_html__('%s Viewing registrations for the event: %s%s', 'event_espresso'), |
|
68 | + '<h3 style="line-height:1.5em;">', |
|
69 | + ' <a href="' |
|
70 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
71 | + array( |
|
72 | + 'action' => 'edit', |
|
73 | + 'post' => $event->ID(), |
|
74 | + ), |
|
75 | + EVENTS_ADMIN_URL |
|
76 | + ) |
|
77 | + . '">' |
|
78 | + . $event->get('EVT_name') |
|
79 | + . '</a> ', |
|
80 | + '</h3>' |
|
81 | + ); |
|
82 | + } |
|
83 | + } |
|
84 | + return $text; |
|
85 | + } |
|
86 | 86 | } |
@@ -49,137 +49,137 @@ |
||
49 | 49 | class RestApiSpoofer |
50 | 50 | { |
51 | 51 | |
52 | - /** |
|
53 | - * @var WP_REST_Server $wp_rest_server |
|
54 | - */ |
|
55 | - protected $wp_rest_server; |
|
52 | + /** |
|
53 | + * @var WP_REST_Server $wp_rest_server |
|
54 | + */ |
|
55 | + protected $wp_rest_server; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var Read |
|
59 | - */ |
|
60 | - protected $rest_controller; |
|
57 | + /** |
|
58 | + * @var Read |
|
59 | + */ |
|
60 | + protected $rest_controller; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var EED_Core_Rest_Api $rest_module |
|
64 | - */ |
|
65 | - protected $rest_module; |
|
62 | + /** |
|
63 | + * @var EED_Core_Rest_Api $rest_module |
|
64 | + */ |
|
65 | + protected $rest_module; |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * RestApiSpoofer constructor. |
|
70 | - * |
|
71 | - * @param WP_REST_Server $wp_rest_server |
|
72 | - * @param EED_Core_Rest_Api $rest_module |
|
73 | - * @param Read $rest_api |
|
74 | - * @param string $api_version |
|
75 | - */ |
|
76 | - public function __construct( |
|
77 | - WP_REST_Server $wp_rest_server, |
|
78 | - EED_Core_Rest_Api $rest_module, |
|
79 | - Read $rest_api, |
|
80 | - $api_version = '4.8.36' |
|
81 | - ) { |
|
82 | - $this->wp_rest_server = $wp_rest_server; |
|
83 | - $this->rest_module = $rest_module; |
|
84 | - $this->rest_controller = $rest_api; |
|
85 | - $this->rest_controller->setRequestedVersion($api_version); |
|
86 | - $this->setUpRestServer(); |
|
87 | - } |
|
68 | + /** |
|
69 | + * RestApiSpoofer constructor. |
|
70 | + * |
|
71 | + * @param WP_REST_Server $wp_rest_server |
|
72 | + * @param EED_Core_Rest_Api $rest_module |
|
73 | + * @param Read $rest_api |
|
74 | + * @param string $api_version |
|
75 | + */ |
|
76 | + public function __construct( |
|
77 | + WP_REST_Server $wp_rest_server, |
|
78 | + EED_Core_Rest_Api $rest_module, |
|
79 | + Read $rest_api, |
|
80 | + $api_version = '4.8.36' |
|
81 | + ) { |
|
82 | + $this->wp_rest_server = $wp_rest_server; |
|
83 | + $this->rest_module = $rest_module; |
|
84 | + $this->rest_controller = $rest_api; |
|
85 | + $this->rest_controller->setRequestedVersion($api_version); |
|
86 | + $this->setUpRestServer(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - private function setUpRestServer() |
|
91 | - { |
|
92 | - /* @var WP_REST_Server $wp_rest_server */ |
|
93 | - global $wp_rest_server; |
|
94 | - $wp_rest_server = $this->wp_rest_server; |
|
95 | - EED_Core_Rest_Api::set_hooks_both(); |
|
96 | - do_action('rest_api_init', $this->wp_rest_server); |
|
97 | - } |
|
90 | + private function setUpRestServer() |
|
91 | + { |
|
92 | + /* @var WP_REST_Server $wp_rest_server */ |
|
93 | + global $wp_rest_server; |
|
94 | + $wp_rest_server = $this->wp_rest_server; |
|
95 | + EED_Core_Rest_Api::set_hooks_both(); |
|
96 | + do_action('rest_api_init', $this->wp_rest_server); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param EEM_Base $model |
|
101 | - * @param array $query_params |
|
102 | - * @param string $include |
|
103 | - * @return array |
|
104 | - * @throws EE_Error |
|
105 | - * @throws InvalidArgumentException |
|
106 | - * @throws InvalidDataTypeException |
|
107 | - * @throws InvalidInterfaceException |
|
108 | - * @throws ModelConfigurationException |
|
109 | - * @throws ReflectionException |
|
110 | - * @throws RestException |
|
111 | - * @throws RestPasswordIncorrectException |
|
112 | - * @throws RestPasswordRequiredException |
|
113 | - * @throws UnexpectedEntityException |
|
114 | - * @throws DomainException |
|
115 | - * @since $VID:$ |
|
116 | - */ |
|
117 | - public function getOneApiResult(EEM_Base $model, array $query_params, $include = '') |
|
118 | - { |
|
119 | - if (! array_key_exists('limit', $query_params)) { |
|
120 | - $query_params['limit'] = 1; |
|
121 | - } |
|
122 | - $result = $this->getApiResults($model, $query_params, $include); |
|
123 | - return is_array($result) && isset($result[0]) ? $result[0] : []; |
|
124 | - } |
|
99 | + /** |
|
100 | + * @param EEM_Base $model |
|
101 | + * @param array $query_params |
|
102 | + * @param string $include |
|
103 | + * @return array |
|
104 | + * @throws EE_Error |
|
105 | + * @throws InvalidArgumentException |
|
106 | + * @throws InvalidDataTypeException |
|
107 | + * @throws InvalidInterfaceException |
|
108 | + * @throws ModelConfigurationException |
|
109 | + * @throws ReflectionException |
|
110 | + * @throws RestException |
|
111 | + * @throws RestPasswordIncorrectException |
|
112 | + * @throws RestPasswordRequiredException |
|
113 | + * @throws UnexpectedEntityException |
|
114 | + * @throws DomainException |
|
115 | + * @since $VID:$ |
|
116 | + */ |
|
117 | + public function getOneApiResult(EEM_Base $model, array $query_params, $include = '') |
|
118 | + { |
|
119 | + if (! array_key_exists('limit', $query_params)) { |
|
120 | + $query_params['limit'] = 1; |
|
121 | + } |
|
122 | + $result = $this->getApiResults($model, $query_params, $include); |
|
123 | + return is_array($result) && isset($result[0]) ? $result[0] : []; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param EEM_Base $model |
|
128 | - * @param array $query_params |
|
129 | - * @param string $include |
|
130 | - * @return array |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - * @throws ModelConfigurationException |
|
136 | - * @throws ReflectionException |
|
137 | - * @throws RestException |
|
138 | - * @throws RestPasswordIncorrectException |
|
139 | - * @throws RestPasswordRequiredException |
|
140 | - * @throws UnexpectedEntityException |
|
141 | - * @throws DomainException |
|
142 | - * @since $VID:$ |
|
143 | - */ |
|
144 | - public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
|
145 | - { |
|
146 | - if (! array_key_exists('caps', $query_params)) { |
|
147 | - $query_params['caps'] = EEM_Base::caps_read_admin; |
|
148 | - } |
|
149 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
150 | - $query_params['default_where_conditions'] = 'none'; |
|
151 | - } |
|
152 | - /** @type array $results */ |
|
153 | - $results = $model->get_all_wpdb_results($query_params); |
|
154 | - $rest_request = new WP_REST_Request(); |
|
155 | - $rest_request->set_param('include', $include); |
|
156 | - $rest_request->set_param('caps', 'edit'); |
|
157 | - $nice_results = array(); |
|
158 | - foreach ($results as $result) { |
|
159 | - $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
160 | - $model, |
|
161 | - $result, |
|
162 | - $rest_request |
|
163 | - ); |
|
164 | - } |
|
165 | - return $nice_results; |
|
166 | - } |
|
126 | + /** |
|
127 | + * @param EEM_Base $model |
|
128 | + * @param array $query_params |
|
129 | + * @param string $include |
|
130 | + * @return array |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + * @throws ModelConfigurationException |
|
136 | + * @throws ReflectionException |
|
137 | + * @throws RestException |
|
138 | + * @throws RestPasswordIncorrectException |
|
139 | + * @throws RestPasswordRequiredException |
|
140 | + * @throws UnexpectedEntityException |
|
141 | + * @throws DomainException |
|
142 | + * @since $VID:$ |
|
143 | + */ |
|
144 | + public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
|
145 | + { |
|
146 | + if (! array_key_exists('caps', $query_params)) { |
|
147 | + $query_params['caps'] = EEM_Base::caps_read_admin; |
|
148 | + } |
|
149 | + if (! array_key_exists('default_where_conditions', $query_params)) { |
|
150 | + $query_params['default_where_conditions'] = 'none'; |
|
151 | + } |
|
152 | + /** @type array $results */ |
|
153 | + $results = $model->get_all_wpdb_results($query_params); |
|
154 | + $rest_request = new WP_REST_Request(); |
|
155 | + $rest_request->set_param('include', $include); |
|
156 | + $rest_request->set_param('caps', 'edit'); |
|
157 | + $nice_results = array(); |
|
158 | + foreach ($results as $result) { |
|
159 | + $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
160 | + $model, |
|
161 | + $result, |
|
162 | + $rest_request |
|
163 | + ); |
|
164 | + } |
|
165 | + return $nice_results; |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * @param string $endpoint |
|
171 | - * @return array |
|
172 | - * @throws EE_Error |
|
173 | - * @since $VID:$ |
|
174 | - */ |
|
175 | - public function getModelSchema($endpoint) |
|
176 | - { |
|
177 | - $response = $this->wp_rest_server->dispatch( |
|
178 | - new WP_REST_Request( |
|
179 | - 'OPTIONS', |
|
180 | - "/ee/v4.8.36/{$endpoint}" |
|
181 | - ) |
|
182 | - ); |
|
183 | - return $response->get_data(); |
|
184 | - } |
|
169 | + /** |
|
170 | + * @param string $endpoint |
|
171 | + * @return array |
|
172 | + * @throws EE_Error |
|
173 | + * @since $VID:$ |
|
174 | + */ |
|
175 | + public function getModelSchema($endpoint) |
|
176 | + { |
|
177 | + $response = $this->wp_rest_server->dispatch( |
|
178 | + new WP_REST_Request( |
|
179 | + 'OPTIONS', |
|
180 | + "/ee/v4.8.36/{$endpoint}" |
|
181 | + ) |
|
182 | + ); |
|
183 | + return $response->get_data(); |
|
184 | + } |
|
185 | 185 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function getOneApiResult(EEM_Base $model, array $query_params, $include = '') |
118 | 118 | { |
119 | - if (! array_key_exists('limit', $query_params)) { |
|
119 | + if ( ! array_key_exists('limit', $query_params)) { |
|
120 | 120 | $query_params['limit'] = 1; |
121 | 121 | } |
122 | 122 | $result = $this->getApiResults($model, $query_params, $include); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function getApiResults(EEM_Base $model, array $query_params, $include = '') |
145 | 145 | { |
146 | - if (! array_key_exists('caps', $query_params)) { |
|
146 | + if ( ! array_key_exists('caps', $query_params)) { |
|
147 | 147 | $query_params['caps'] = EEM_Base::caps_read_admin; |
148 | 148 | } |
149 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
149 | + if ( ! array_key_exists('default_where_conditions', $query_params)) { |
|
150 | 150 | $query_params['default_where_conditions'] = 'none'; |
151 | 151 | } |
152 | 152 | /** @type array $results */ |
@@ -13,50 +13,50 @@ |
||
13 | 13 | interface ModelObjectToJsonConverterInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $entities |
|
18 | - * @return array |
|
19 | - * @since $VID:$ |
|
20 | - */ |
|
21 | - public function convertAndEncodeArrayOf(array $entities); |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param $entity |
|
26 | - * @return false|string |
|
27 | - * @since $VID:$ |
|
28 | - */ |
|
29 | - public function convertAndEncode($entity); |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param array $entities |
|
34 | - * @return array |
|
35 | - * @since $VID:$ |
|
36 | - */ |
|
37 | - public function convertArrayOf(array $entities); |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @param $entity |
|
42 | - * @return array |
|
43 | - * @since $VID:$ |
|
44 | - */ |
|
45 | - public function convert($entity); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param array $entities |
|
50 | - * @return array |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function encodeArrayOf(array $entities); |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param array $entity_array |
|
58 | - * @return false|string |
|
59 | - * @since $VID:$ |
|
60 | - */ |
|
61 | - public function encode(array $entity_array); |
|
16 | + /** |
|
17 | + * @param array $entities |
|
18 | + * @return array |
|
19 | + * @since $VID:$ |
|
20 | + */ |
|
21 | + public function convertAndEncodeArrayOf(array $entities); |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param $entity |
|
26 | + * @return false|string |
|
27 | + * @since $VID:$ |
|
28 | + */ |
|
29 | + public function convertAndEncode($entity); |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param array $entities |
|
34 | + * @return array |
|
35 | + * @since $VID:$ |
|
36 | + */ |
|
37 | + public function convertArrayOf(array $entities); |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @param $entity |
|
42 | + * @return array |
|
43 | + * @since $VID:$ |
|
44 | + */ |
|
45 | + public function convert($entity); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param array $entities |
|
50 | + * @return array |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function encodeArrayOf(array $entities); |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param array $entity_array |
|
58 | + * @return false|string |
|
59 | + * @since $VID:$ |
|
60 | + */ |
|
61 | + public function encode(array $entity_array); |
|
62 | 62 | } |
@@ -16,13 +16,13 @@ |
||
16 | 16 | interface ResolverInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param $source |
|
21 | - * @param array $args |
|
22 | - * @param AppContext $context |
|
23 | - * @param ResolveInfo $info |
|
24 | - * @return mixed |
|
25 | - * @since $VID:$ |
|
26 | - */ |
|
27 | - public function resolve($source, array $args, AppContext $context, ResolveInfo $info); |
|
19 | + /** |
|
20 | + * @param $source |
|
21 | + * @param array $args |
|
22 | + * @param AppContext $context |
|
23 | + * @param ResolveInfo $info |
|
24 | + * @return mixed |
|
25 | + * @since $VID:$ |
|
26 | + */ |
|
27 | + public function resolve($source, array $args, AppContext $context, ResolveInfo $info); |
|
28 | 28 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | $config = $field->toArray(); |
76 | 76 | if ($field->useForInput()) { |
77 | 77 | // Register input fields for existing mutations. |
78 | - register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
79 | - register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
78 | + register_graphql_field('Update'.$typeName.'Input', $fieldName, $config); |
|
79 | + register_graphql_field('Create'.$typeName.'Input', $fieldName, $config); |
|
80 | 80 | } |
81 | 81 | if ($field->useForOutput()) { |
82 | 82 | $config['resolve'] = [$type, 'resolveField']; |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | $fieldName = $field->name(); |
103 | 103 | $config = $field->toArray(); |
104 | 104 | if ($field->useForInput()) { |
105 | - $inputFields[ $fieldName ] = $config; |
|
105 | + $inputFields[$fieldName] = $config; |
|
106 | 106 | } |
107 | 107 | if ($field->useForOutput()) { |
108 | 108 | $config['resolve'] = [$type, 'resolveField']; |
109 | - $outputFields[ $fieldName ] = $config; |
|
109 | + $outputFields[$fieldName] = $config; |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | $typeName = $type->name(); |
113 | - if (! empty($outputFields)) { |
|
113 | + if ( ! empty($outputFields)) { |
|
114 | 114 | // Register the object type. |
115 | 115 | register_graphql_object_type( |
116 | 116 | $typeName, |
@@ -18,110 +18,110 @@ |
||
18 | 18 | class TypesManager implements GQLManagerInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var TypeCollection|TypeInterface[] $types |
|
23 | - */ |
|
24 | - private $types; |
|
21 | + /** |
|
22 | + * @var TypeCollection|TypeInterface[] $types |
|
23 | + */ |
|
24 | + private $types; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * TypesManager constructor. |
|
29 | - * |
|
30 | - * @param TypeCollection|TypeInterface[] $types |
|
31 | - */ |
|
32 | - public function __construct(TypeCollection $types) |
|
33 | - { |
|
34 | - $this->types = $types; |
|
35 | - } |
|
27 | + /** |
|
28 | + * TypesManager constructor. |
|
29 | + * |
|
30 | + * @param TypeCollection|TypeInterface[] $types |
|
31 | + */ |
|
32 | + public function __construct(TypeCollection $types) |
|
33 | + { |
|
34 | + $this->types = $types; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @throws CollectionDetailsException |
|
40 | - * @throws CollectionLoaderException |
|
41 | - * @since $VID:$ |
|
42 | - */ |
|
43 | - public function init() |
|
44 | - { |
|
45 | - $this->types->loadTypes(); |
|
46 | - add_action('graphql_register_types', [$this, 'configureTypes'], 10); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @throws CollectionDetailsException |
|
40 | + * @throws CollectionLoaderException |
|
41 | + * @since $VID:$ |
|
42 | + */ |
|
43 | + public function init() |
|
44 | + { |
|
45 | + $this->types->loadTypes(); |
|
46 | + add_action('graphql_register_types', [$this, 'configureTypes'], 10); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function configureTypes() |
|
54 | - { |
|
55 | - // loop through the collection of types and register their fields |
|
56 | - foreach ($this->types as $type) { |
|
57 | - if ($type->isCustomPostType()) { |
|
58 | - $this->extendCustomPostType($type); |
|
59 | - } else { |
|
60 | - $this->registerType($type); |
|
61 | - } |
|
62 | - } |
|
63 | - } |
|
50 | + /** |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function configureTypes() |
|
54 | + { |
|
55 | + // loop through the collection of types and register their fields |
|
56 | + foreach ($this->types as $type) { |
|
57 | + if ($type->isCustomPostType()) { |
|
58 | + $this->extendCustomPostType($type); |
|
59 | + } else { |
|
60 | + $this->registerType($type); |
|
61 | + } |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * @param TypeInterface $type |
|
68 | - * @since $VID:$ |
|
69 | - */ |
|
70 | - public function extendCustomPostType(TypeInterface $type) |
|
71 | - { |
|
72 | - $typeName = $type->name(); |
|
73 | - foreach ($type->fields() as $field) { |
|
74 | - $fieldName = $field->name(); |
|
75 | - $config = $field->toArray(); |
|
76 | - if ($field->useForInput()) { |
|
77 | - // Register input fields for existing mutations. |
|
78 | - register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
79 | - register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
80 | - } |
|
81 | - if ($field->useForOutput()) { |
|
82 | - $config['resolve'] = [$type, 'resolveField']; |
|
83 | - // Register fields for queries. |
|
84 | - register_graphql_field($typeName, $fieldName, $config); |
|
85 | - } |
|
86 | - } |
|
87 | - if (is_callable([$type, 'extendMutations'])) { |
|
88 | - $type->extendMutations(); |
|
89 | - } |
|
90 | - } |
|
66 | + /** |
|
67 | + * @param TypeInterface $type |
|
68 | + * @since $VID:$ |
|
69 | + */ |
|
70 | + public function extendCustomPostType(TypeInterface $type) |
|
71 | + { |
|
72 | + $typeName = $type->name(); |
|
73 | + foreach ($type->fields() as $field) { |
|
74 | + $fieldName = $field->name(); |
|
75 | + $config = $field->toArray(); |
|
76 | + if ($field->useForInput()) { |
|
77 | + // Register input fields for existing mutations. |
|
78 | + register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config); |
|
79 | + register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config); |
|
80 | + } |
|
81 | + if ($field->useForOutput()) { |
|
82 | + $config['resolve'] = [$type, 'resolveField']; |
|
83 | + // Register fields for queries. |
|
84 | + register_graphql_field($typeName, $fieldName, $config); |
|
85 | + } |
|
86 | + } |
|
87 | + if (is_callable([$type, 'extendMutations'])) { |
|
88 | + $type->extendMutations(); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @param TypeInterface $type |
|
95 | - * @since $VID:$ |
|
96 | - */ |
|
97 | - public function registerType(TypeInterface $type) |
|
98 | - { |
|
99 | - $outputFields = []; |
|
100 | - $inputFields = []; |
|
101 | - foreach ($type->fields() as $field) { |
|
102 | - $fieldName = $field->name(); |
|
103 | - $config = $field->toArray(); |
|
104 | - if ($field->useForInput()) { |
|
105 | - $inputFields[ $fieldName ] = $config; |
|
106 | - } |
|
107 | - if ($field->useForOutput()) { |
|
108 | - $config['resolve'] = [$type, 'resolveField']; |
|
109 | - $outputFields[ $fieldName ] = $config; |
|
110 | - } |
|
111 | - } |
|
112 | - $typeName = $type->name(); |
|
113 | - if (! empty($outputFields)) { |
|
114 | - // Register the object type. |
|
115 | - register_graphql_object_type( |
|
116 | - $typeName, |
|
117 | - [ |
|
118 | - 'description' => $type->description(), |
|
119 | - 'fields' => $outputFields, |
|
120 | - ] |
|
121 | - ); |
|
122 | - } |
|
123 | - if (is_callable([$type, 'registerMutations'])) { |
|
124 | - $type->registerMutations($inputFields); |
|
125 | - } |
|
126 | - } |
|
93 | + /** |
|
94 | + * @param TypeInterface $type |
|
95 | + * @since $VID:$ |
|
96 | + */ |
|
97 | + public function registerType(TypeInterface $type) |
|
98 | + { |
|
99 | + $outputFields = []; |
|
100 | + $inputFields = []; |
|
101 | + foreach ($type->fields() as $field) { |
|
102 | + $fieldName = $field->name(); |
|
103 | + $config = $field->toArray(); |
|
104 | + if ($field->useForInput()) { |
|
105 | + $inputFields[ $fieldName ] = $config; |
|
106 | + } |
|
107 | + if ($field->useForOutput()) { |
|
108 | + $config['resolve'] = [$type, 'resolveField']; |
|
109 | + $outputFields[ $fieldName ] = $config; |
|
110 | + } |
|
111 | + } |
|
112 | + $typeName = $type->name(); |
|
113 | + if (! empty($outputFields)) { |
|
114 | + // Register the object type. |
|
115 | + register_graphql_object_type( |
|
116 | + $typeName, |
|
117 | + [ |
|
118 | + 'description' => $type->description(), |
|
119 | + 'fields' => $outputFields, |
|
120 | + ] |
|
121 | + ); |
|
122 | + } |
|
123 | + if (is_callable([$type, 'registerMutations'])) { |
|
124 | + $type->registerMutations($inputFields); |
|
125 | + } |
|
126 | + } |
|
127 | 127 | } |
@@ -23,79 +23,79 @@ |
||
23 | 23 | interface TypeInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function name(); |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function description(); |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
40 | - * @since $VID:$ |
|
41 | - */ |
|
42 | - public function fields(); |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Creates a key map for internal resolver. |
|
47 | - * |
|
48 | - * @return array |
|
49 | - * @since $VID:$ |
|
50 | - */ |
|
51 | - public function getFieldsForResolver(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function isCustomPostType(); |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param int $value |
|
62 | - * @return int |
|
63 | - * @since $VID:$ |
|
64 | - */ |
|
65 | - public function parseInfiniteValue($value); |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
70 | - * @param array $args The inputArgs on the field |
|
71 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
72 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
73 | - * @return string |
|
74 | - * @throws EE_Error |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws UnexpectedEntityException |
|
78 | - * @throws UserError |
|
79 | - * @throws InvalidArgumentException |
|
80 | - * @throws ReflectionException |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolveField($source, $args, AppContext $context, ResolveInfo $info); |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param mixed $payload The payload returned after mutation |
|
88 | - * @param array $args The inputArgs on the field |
|
89 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
90 | - * @return string |
|
91 | - * @throws EE_Error |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidInterfaceException |
|
94 | - * @throws UnexpectedEntityException |
|
95 | - * @throws UserError |
|
96 | - * @throws InvalidArgumentException |
|
97 | - * @throws ReflectionException |
|
98 | - * @since $VID:$ |
|
99 | - */ |
|
100 | - public function resolveFromPayload($payload, $args, AppContext $context); |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function name(); |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function description(); |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @return \EventEspresso\core\services\graphql\fields\GraphQLFieldInterface[] |
|
40 | + * @since $VID:$ |
|
41 | + */ |
|
42 | + public function fields(); |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Creates a key map for internal resolver. |
|
47 | + * |
|
48 | + * @return array |
|
49 | + * @since $VID:$ |
|
50 | + */ |
|
51 | + public function getFieldsForResolver(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function isCustomPostType(); |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param int $value |
|
62 | + * @return int |
|
63 | + * @since $VID:$ |
|
64 | + */ |
|
65 | + public function parseInfiniteValue($value); |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
70 | + * @param array $args The inputArgs on the field |
|
71 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
72 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
73 | + * @return string |
|
74 | + * @throws EE_Error |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws UnexpectedEntityException |
|
78 | + * @throws UserError |
|
79 | + * @throws InvalidArgumentException |
|
80 | + * @throws ReflectionException |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolveField($source, $args, AppContext $context, ResolveInfo $info); |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param mixed $payload The payload returned after mutation |
|
88 | + * @param array $args The inputArgs on the field |
|
89 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
90 | + * @return string |
|
91 | + * @throws EE_Error |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidInterfaceException |
|
94 | + * @throws UnexpectedEntityException |
|
95 | + * @throws UserError |
|
96 | + * @throws InvalidArgumentException |
|
97 | + * @throws ReflectionException |
|
98 | + * @since $VID:$ |
|
99 | + */ |
|
100 | + public function resolveFromPayload($payload, $args, AppContext $context); |
|
101 | 101 | } |
@@ -155,7 +155,7 @@ |
||
155 | 155 | $fields = []; |
156 | 156 | foreach ($this->fields() as $field) { |
157 | 157 | if ($field->useForOutput()) { |
158 | - $fields[ $field->name() ] = $field; |
|
158 | + $fields[$field->name()] = $field; |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | return $fields; |
@@ -32,266 +32,266 @@ |
||
32 | 32 | abstract class TypeBase implements TypeInterface |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var string $namespace The graphql namespace/prefix. |
|
37 | - */ |
|
38 | - protected $namespace = 'Espresso'; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var EEM_Base $model |
|
42 | - */ |
|
43 | - protected $model; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string $name |
|
47 | - */ |
|
48 | - protected $name = ''; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string $description |
|
52 | - */ |
|
53 | - protected $description = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var GraphQLFieldInterface[] $fields |
|
57 | - */ |
|
58 | - protected $fields = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var array $graphql_to_model_map |
|
62 | - */ |
|
63 | - protected $graphql_to_model_map = []; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var FieldResolver $field_resolver |
|
67 | - */ |
|
68 | - protected $field_resolver; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var bool $is_custom_post_type |
|
72 | - */ |
|
73 | - protected $is_custom_post_type = false; |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * TypeBase constructor. |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->setFields($this->getFields()); |
|
82 | - $this->field_resolver = new FieldResolver( |
|
83 | - $this->model, |
|
84 | - $this->getFieldsForResolver() |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return GraphQLFieldInterface[] |
|
91 | - * @since $VID:$ |
|
92 | - */ |
|
93 | - abstract protected function getFields(); |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function name() |
|
100 | - { |
|
101 | - return $this->name; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $name |
|
107 | - */ |
|
108 | - protected function setName($name) |
|
109 | - { |
|
110 | - $this->name = $name; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function description() |
|
118 | - { |
|
119 | - return $this->description; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @param string $description |
|
125 | - */ |
|
126 | - protected function setDescription($description) |
|
127 | - { |
|
128 | - $this->description = $description; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return GraphQLFieldInterface[] |
|
134 | - * @since $VID:$ |
|
135 | - */ |
|
136 | - public function fields() |
|
137 | - { |
|
138 | - return (array) $this->fields; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param GraphQLFieldInterface[] $fields |
|
144 | - */ |
|
145 | - protected function setFields(array $fields) |
|
146 | - { |
|
147 | - foreach ($fields as $field) { |
|
148 | - if ($field instanceof GraphQLField) { |
|
149 | - $this->fields[] = $field; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Creates a key map for internal resolver. |
|
157 | - * |
|
158 | - * @return array |
|
159 | - * @since $VID:$ |
|
160 | - */ |
|
161 | - public function getFieldsForResolver() |
|
162 | - { |
|
163 | - $fields = []; |
|
164 | - foreach ($this->fields() as $field) { |
|
165 | - if ($field->useForOutput()) { |
|
166 | - $fields[ $field->name() ] = $field; |
|
167 | - } |
|
168 | - } |
|
169 | - return $fields; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public function isCustomPostType() |
|
177 | - { |
|
178 | - return $this->is_custom_post_type; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param bool $is_custom_post_type |
|
184 | - */ |
|
185 | - protected function setIsCustomPostType($is_custom_post_type) |
|
186 | - { |
|
187 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param int $value |
|
193 | - * @return int |
|
194 | - * @since $VID:$ |
|
195 | - */ |
|
196 | - public function parseInfiniteValue($value) |
|
197 | - { |
|
198 | - $value = trim($value); |
|
199 | - return $value === null |
|
200 | - || $value === '' |
|
201 | - || $value === '∞' |
|
202 | - || $value === 'INF' |
|
203 | - || $value === INF |
|
204 | - || $value === EE_INF |
|
205 | - || is_infinite((float) $value) |
|
206 | - ? -1 |
|
207 | - : $value; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param mixed $source |
|
213 | - * @return EE_Base_Class|null |
|
214 | - * @since $VID:$ |
|
215 | - */ |
|
216 | - private function getModel($source) |
|
217 | - { |
|
218 | - // If it comes from a custom connection |
|
219 | - // where the $source is already instantiated. |
|
220 | - if ($source instanceof EE_Base_Class) { |
|
221 | - return $source; |
|
222 | - } |
|
223 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
229 | - * @param array $args The inputArgs on the field |
|
230 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
231 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
232 | - * @return string |
|
233 | - * @throws EE_Error |
|
234 | - * @throws InvalidDataTypeException |
|
235 | - * @throws InvalidInterfaceException |
|
236 | - * @throws UnexpectedEntityException |
|
237 | - * @throws UserError |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @since $VID:$ |
|
241 | - */ |
|
242 | - public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
243 | - { |
|
244 | - $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
245 | - |
|
246 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param mixed $payload The payload returned after mutation |
|
252 | - * @param array $args The inputArgs on the field |
|
253 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
254 | - * @return string |
|
255 | - * @throws EE_Error |
|
256 | - * @throws InvalidDataTypeException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws UnexpectedEntityException |
|
259 | - * @throws UserError |
|
260 | - * @throws InvalidArgumentException |
|
261 | - * @throws ReflectionException |
|
262 | - * @since $VID:$ |
|
263 | - */ |
|
264 | - public function resolveFromPayload($payload, $args, AppContext $context) |
|
265 | - { |
|
266 | - if (empty($payload['id']) || ! absint($payload['id'])) { |
|
267 | - return null; |
|
268 | - } |
|
269 | - return $this->model->get_one_by_ID($payload['id']); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Prepares a datetime value in ISO8601/RFC3339 format. |
|
275 | - * It is assumed that the value of $datetime is in the format |
|
276 | - * returned by EE_Base_Class::get_format(). |
|
277 | - * |
|
278 | - * @param string $datetime The datetime value. |
|
279 | - * @param EE_Base_Class $source The source object. |
|
280 | - * @return string ISO8601/RFC3339 formatted datetime. |
|
281 | - * @throws InvalidDataTypeException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws InvalidArgumentException |
|
284 | - * @throws ReflectionException |
|
285 | - * @since $VID:$ |
|
286 | - */ |
|
287 | - public function formatDatetime($datetime, EE_Base_Class $source) |
|
288 | - { |
|
289 | - $format = $source->get_format(); |
|
290 | - // create date object based on local timezone |
|
291 | - $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
292 | - // change the timezone to UTC |
|
293 | - $datetime->setTimezone(new DateTimeZone('UTC')); |
|
294 | - |
|
295 | - return $datetime->format(DateTime::RFC3339); |
|
296 | - } |
|
35 | + /** |
|
36 | + * @var string $namespace The graphql namespace/prefix. |
|
37 | + */ |
|
38 | + protected $namespace = 'Espresso'; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var EEM_Base $model |
|
42 | + */ |
|
43 | + protected $model; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string $name |
|
47 | + */ |
|
48 | + protected $name = ''; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string $description |
|
52 | + */ |
|
53 | + protected $description = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var GraphQLFieldInterface[] $fields |
|
57 | + */ |
|
58 | + protected $fields = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var array $graphql_to_model_map |
|
62 | + */ |
|
63 | + protected $graphql_to_model_map = []; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var FieldResolver $field_resolver |
|
67 | + */ |
|
68 | + protected $field_resolver; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var bool $is_custom_post_type |
|
72 | + */ |
|
73 | + protected $is_custom_post_type = false; |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * TypeBase constructor. |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->setFields($this->getFields()); |
|
82 | + $this->field_resolver = new FieldResolver( |
|
83 | + $this->model, |
|
84 | + $this->getFieldsForResolver() |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return GraphQLFieldInterface[] |
|
91 | + * @since $VID:$ |
|
92 | + */ |
|
93 | + abstract protected function getFields(); |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function name() |
|
100 | + { |
|
101 | + return $this->name; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $name |
|
107 | + */ |
|
108 | + protected function setName($name) |
|
109 | + { |
|
110 | + $this->name = $name; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function description() |
|
118 | + { |
|
119 | + return $this->description; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @param string $description |
|
125 | + */ |
|
126 | + protected function setDescription($description) |
|
127 | + { |
|
128 | + $this->description = $description; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return GraphQLFieldInterface[] |
|
134 | + * @since $VID:$ |
|
135 | + */ |
|
136 | + public function fields() |
|
137 | + { |
|
138 | + return (array) $this->fields; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param GraphQLFieldInterface[] $fields |
|
144 | + */ |
|
145 | + protected function setFields(array $fields) |
|
146 | + { |
|
147 | + foreach ($fields as $field) { |
|
148 | + if ($field instanceof GraphQLField) { |
|
149 | + $this->fields[] = $field; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Creates a key map for internal resolver. |
|
157 | + * |
|
158 | + * @return array |
|
159 | + * @since $VID:$ |
|
160 | + */ |
|
161 | + public function getFieldsForResolver() |
|
162 | + { |
|
163 | + $fields = []; |
|
164 | + foreach ($this->fields() as $field) { |
|
165 | + if ($field->useForOutput()) { |
|
166 | + $fields[ $field->name() ] = $field; |
|
167 | + } |
|
168 | + } |
|
169 | + return $fields; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public function isCustomPostType() |
|
177 | + { |
|
178 | + return $this->is_custom_post_type; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param bool $is_custom_post_type |
|
184 | + */ |
|
185 | + protected function setIsCustomPostType($is_custom_post_type) |
|
186 | + { |
|
187 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param int $value |
|
193 | + * @return int |
|
194 | + * @since $VID:$ |
|
195 | + */ |
|
196 | + public function parseInfiniteValue($value) |
|
197 | + { |
|
198 | + $value = trim($value); |
|
199 | + return $value === null |
|
200 | + || $value === '' |
|
201 | + || $value === '∞' |
|
202 | + || $value === 'INF' |
|
203 | + || $value === INF |
|
204 | + || $value === EE_INF |
|
205 | + || is_infinite((float) $value) |
|
206 | + ? -1 |
|
207 | + : $value; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param mixed $source |
|
213 | + * @return EE_Base_Class|null |
|
214 | + * @since $VID:$ |
|
215 | + */ |
|
216 | + private function getModel($source) |
|
217 | + { |
|
218 | + // If it comes from a custom connection |
|
219 | + // where the $source is already instantiated. |
|
220 | + if ($source instanceof EE_Base_Class) { |
|
221 | + return $source; |
|
222 | + } |
|
223 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
229 | + * @param array $args The inputArgs on the field |
|
230 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
231 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
232 | + * @return string |
|
233 | + * @throws EE_Error |
|
234 | + * @throws InvalidDataTypeException |
|
235 | + * @throws InvalidInterfaceException |
|
236 | + * @throws UnexpectedEntityException |
|
237 | + * @throws UserError |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @since $VID:$ |
|
241 | + */ |
|
242 | + public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
243 | + { |
|
244 | + $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
245 | + |
|
246 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param mixed $payload The payload returned after mutation |
|
252 | + * @param array $args The inputArgs on the field |
|
253 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
254 | + * @return string |
|
255 | + * @throws EE_Error |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws UnexpectedEntityException |
|
259 | + * @throws UserError |
|
260 | + * @throws InvalidArgumentException |
|
261 | + * @throws ReflectionException |
|
262 | + * @since $VID:$ |
|
263 | + */ |
|
264 | + public function resolveFromPayload($payload, $args, AppContext $context) |
|
265 | + { |
|
266 | + if (empty($payload['id']) || ! absint($payload['id'])) { |
|
267 | + return null; |
|
268 | + } |
|
269 | + return $this->model->get_one_by_ID($payload['id']); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Prepares a datetime value in ISO8601/RFC3339 format. |
|
275 | + * It is assumed that the value of $datetime is in the format |
|
276 | + * returned by EE_Base_Class::get_format(). |
|
277 | + * |
|
278 | + * @param string $datetime The datetime value. |
|
279 | + * @param EE_Base_Class $source The source object. |
|
280 | + * @return string ISO8601/RFC3339 formatted datetime. |
|
281 | + * @throws InvalidDataTypeException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws InvalidArgumentException |
|
284 | + * @throws ReflectionException |
|
285 | + * @since $VID:$ |
|
286 | + */ |
|
287 | + public function formatDatetime($datetime, EE_Base_Class $source) |
|
288 | + { |
|
289 | + $format = $source->get_format(); |
|
290 | + // create date object based on local timezone |
|
291 | + $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
292 | + // change the timezone to UTC |
|
293 | + $datetime->setTimezone(new DateTimeZone('UTC')); |
|
294 | + |
|
295 | + return $datetime->format(DateTime::RFC3339); |
|
296 | + } |
|
297 | 297 | } |
@@ -11,30 +11,30 @@ |
||
11 | 11 | class GraphQLInputField extends GraphQLField |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param string $name |
|
16 | - * @param string|string[] $type |
|
17 | - * @param string|null $key |
|
18 | - * @param string $description |
|
19 | - * @param array $caps |
|
20 | - */ |
|
21 | - public function __construct( |
|
22 | - $name, |
|
23 | - $type, |
|
24 | - $key = null, |
|
25 | - $description = '', |
|
26 | - array $caps = [] |
|
27 | - ) { |
|
28 | - parent::__construct( |
|
29 | - $name, |
|
30 | - $type, |
|
31 | - $key, |
|
32 | - $description, |
|
33 | - null, |
|
34 | - null, |
|
35 | - $caps |
|
36 | - ); |
|
14 | + /** |
|
15 | + * @param string $name |
|
16 | + * @param string|string[] $type |
|
17 | + * @param string|null $key |
|
18 | + * @param string $description |
|
19 | + * @param array $caps |
|
20 | + */ |
|
21 | + public function __construct( |
|
22 | + $name, |
|
23 | + $type, |
|
24 | + $key = null, |
|
25 | + $description = '', |
|
26 | + array $caps = [] |
|
27 | + ) { |
|
28 | + parent::__construct( |
|
29 | + $name, |
|
30 | + $type, |
|
31 | + $key, |
|
32 | + $description, |
|
33 | + null, |
|
34 | + null, |
|
35 | + $caps |
|
36 | + ); |
|
37 | 37 | |
38 | - $this->setUseForOutput(false); |
|
39 | - } |
|
38 | + $this->setUseForOutput(false); |
|
39 | + } |
|
40 | 40 | } |
@@ -11,34 +11,34 @@ |
||
11 | 11 | class GraphQLOutputField extends GraphQLField |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param string $name |
|
16 | - * @param string|string[] $type |
|
17 | - * @param string|null $key |
|
18 | - * @param string $description |
|
19 | - * @param callable|null $formatter |
|
20 | - * @param callable|null $resolver |
|
21 | - * @param array $caps |
|
22 | - */ |
|
23 | - public function __construct( |
|
24 | - $name, |
|
25 | - $type, |
|
26 | - $key = null, |
|
27 | - $description = '', |
|
28 | - callable $formatter = null, |
|
29 | - callable $resolver = null, |
|
30 | - array $caps = [] |
|
31 | - ) { |
|
32 | - parent::__construct( |
|
33 | - $name, |
|
34 | - $type, |
|
35 | - $key, |
|
36 | - $description, |
|
37 | - $formatter, |
|
38 | - $resolver, |
|
39 | - $caps |
|
40 | - ); |
|
14 | + /** |
|
15 | + * @param string $name |
|
16 | + * @param string|string[] $type |
|
17 | + * @param string|null $key |
|
18 | + * @param string $description |
|
19 | + * @param callable|null $formatter |
|
20 | + * @param callable|null $resolver |
|
21 | + * @param array $caps |
|
22 | + */ |
|
23 | + public function __construct( |
|
24 | + $name, |
|
25 | + $type, |
|
26 | + $key = null, |
|
27 | + $description = '', |
|
28 | + callable $formatter = null, |
|
29 | + callable $resolver = null, |
|
30 | + array $caps = [] |
|
31 | + ) { |
|
32 | + parent::__construct( |
|
33 | + $name, |
|
34 | + $type, |
|
35 | + $key, |
|
36 | + $description, |
|
37 | + $formatter, |
|
38 | + $resolver, |
|
39 | + $caps |
|
40 | + ); |
|
41 | 41 | |
42 | - $this->setUseForInput(false); |
|
43 | - } |
|
42 | + $this->setUseForInput(false); |
|
43 | + } |
|
44 | 44 | } |