@@ -18,28 +18,28 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @param $entity |
|
23 | - * @param $args |
|
24 | - * @param $context |
|
25 | - * @param $info |
|
26 | - * @return AbstractConnectionResolver |
|
27 | - * @throws Exception |
|
28 | - */ |
|
29 | - abstract public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver; |
|
21 | + /** |
|
22 | + * @param $entity |
|
23 | + * @param $args |
|
24 | + * @param $context |
|
25 | + * @param $info |
|
26 | + * @return AbstractConnectionResolver |
|
27 | + * @throws Exception |
|
28 | + */ |
|
29 | + abstract public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver; |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param $entity |
|
34 | - * @param $args |
|
35 | - * @param $context |
|
36 | - * @param $info |
|
37 | - * @return array |
|
38 | - * @throws Exception |
|
39 | - */ |
|
40 | - public function resolveConnection($entity, $args, $context, $info): object |
|
41 | - { |
|
42 | - $resolver = $this->getConnectionResolver($entity, $args, $context, $info); |
|
43 | - return $resolver->get_connection(); |
|
44 | - } |
|
32 | + /** |
|
33 | + * @param $entity |
|
34 | + * @param $args |
|
35 | + * @param $context |
|
36 | + * @param $info |
|
37 | + * @return array |
|
38 | + * @throws Exception |
|
39 | + */ |
|
40 | + public function resolveConnection($entity, $args, $context, $info): object |
|
41 | + { |
|
42 | + $resolver = $this->getConnectionResolver($entity, $args, $context, $info); |
|
43 | + return $resolver->get_connection(); |
|
44 | + } |
|
45 | 45 | } |
@@ -19,223 +19,223 @@ |
||
19 | 19 | */ |
20 | 20 | class GQLRequests extends Route |
21 | 21 | { |
22 | - /** |
|
23 | - * @var AssetManifestFactory |
|
24 | - */ |
|
25 | - private $manifest_factory; |
|
22 | + /** |
|
23 | + * @var AssetManifestFactory |
|
24 | + */ |
|
25 | + private $manifest_factory; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * AssetRequests constructor. |
|
30 | - * |
|
31 | - * @param EE_Dependency_Map $dependency_map |
|
32 | - * @param LoaderInterface $loader |
|
33 | - * @param RequestInterface $request |
|
34 | - * @param AssetManifestFactory $manifest_factory |
|
35 | - */ |
|
36 | - public function __construct( |
|
37 | - EE_Dependency_Map $dependency_map, |
|
38 | - LoaderInterface $loader, |
|
39 | - RequestInterface $request, |
|
40 | - AssetManifestFactory $manifest_factory |
|
41 | - ) { |
|
42 | - $this->manifest_factory = $manifest_factory; |
|
43 | - parent::__construct($dependency_map, $loader, $request); |
|
44 | - } |
|
28 | + /** |
|
29 | + * AssetRequests constructor. |
|
30 | + * |
|
31 | + * @param EE_Dependency_Map $dependency_map |
|
32 | + * @param LoaderInterface $loader |
|
33 | + * @param RequestInterface $request |
|
34 | + * @param AssetManifestFactory $manifest_factory |
|
35 | + */ |
|
36 | + public function __construct( |
|
37 | + EE_Dependency_Map $dependency_map, |
|
38 | + LoaderInterface $loader, |
|
39 | + RequestInterface $request, |
|
40 | + AssetManifestFactory $manifest_factory |
|
41 | + ) { |
|
42 | + $this->manifest_factory = $manifest_factory; |
|
43 | + parent::__construct($dependency_map, $loader, $request); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * returns true if the current request matches this route |
|
49 | - * |
|
50 | - * @return bool |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function matchesCurrentRequest(): bool |
|
54 | - { |
|
55 | - global $pagenow; |
|
56 | - return ( |
|
57 | - $this->request->isGQL() |
|
58 | - || $this->request->isUnitTesting() |
|
59 | - || ( |
|
60 | - $this->request->isAdmin() |
|
61 | - && $this->request->getRequestParam('page') === 'espresso_events' |
|
62 | - && ( |
|
63 | - $this->request->getRequestParam('action') === 'create_new' |
|
64 | - || $this->request->getRequestParam('action') === 'edit' |
|
65 | - ) |
|
66 | - ) |
|
67 | - || ( |
|
68 | - $pagenow |
|
69 | - && ( |
|
70 | - $pagenow === 'post-new.php' |
|
71 | - || ( |
|
72 | - $pagenow === 'post.php' |
|
73 | - && $this->request->getRequestParam('action') === 'edit' |
|
74 | - ) |
|
75 | - ) |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
47 | + /** |
|
48 | + * returns true if the current request matches this route |
|
49 | + * |
|
50 | + * @return bool |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function matchesCurrentRequest(): bool |
|
54 | + { |
|
55 | + global $pagenow; |
|
56 | + return ( |
|
57 | + $this->request->isGQL() |
|
58 | + || $this->request->isUnitTesting() |
|
59 | + || ( |
|
60 | + $this->request->isAdmin() |
|
61 | + && $this->request->getRequestParam('page') === 'espresso_events' |
|
62 | + && ( |
|
63 | + $this->request->getRequestParam('action') === 'create_new' |
|
64 | + || $this->request->getRequestParam('action') === 'edit' |
|
65 | + ) |
|
66 | + ) |
|
67 | + || ( |
|
68 | + $pagenow |
|
69 | + && ( |
|
70 | + $pagenow === 'post-new.php' |
|
71 | + || ( |
|
72 | + $pagenow === 'post.php' |
|
73 | + && $this->request->getRequestParam('action') === 'edit' |
|
74 | + ) |
|
75 | + ) |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * @since $VID:$ |
|
83 | - */ |
|
84 | - protected function registerDependencies() |
|
85 | - { |
|
86 | - $this->dependency_map->registerDependencies( |
|
87 | - 'EventEspresso\core\services\graphql\GraphQLManager', |
|
88 | - [ |
|
89 | - 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
90 | - 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
91 | - 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
92 | - 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
93 | - 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
94 | - ] |
|
95 | - ); |
|
96 | - $this->dependency_map->registerDependencies( |
|
97 | - 'EventEspresso\core\services\graphql\TypesManager', |
|
98 | - [ |
|
99 | - 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->dependency_map->registerDependencies( |
|
103 | - 'EventEspresso\core\services\graphql\InputsManager', |
|
104 | - [ |
|
105 | - 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
106 | - ] |
|
107 | - ); |
|
108 | - $this->dependency_map->registerDependencies( |
|
109 | - 'EventEspresso\core\services\graphql\EnumsManager', |
|
110 | - [ |
|
111 | - 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
112 | - ] |
|
113 | - ); |
|
114 | - $this->dependency_map->registerDependencies( |
|
115 | - 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
116 | - [ |
|
117 | - 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
118 | - ] |
|
119 | - ); |
|
120 | - $this->dependency_map->registerDependencies( |
|
121 | - 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
122 | - [ |
|
123 | - 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
124 | - ] |
|
125 | - ); |
|
126 | - $this->dependency_map->registerDependencies( |
|
127 | - 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
128 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
129 | - ); |
|
130 | - $this->dependency_map->registerDependencies( |
|
131 | - 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
132 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
133 | - ); |
|
134 | - $this->dependency_map->registerDependencies( |
|
135 | - 'EventEspresso\core\domain\services\graphql\types\Event', |
|
136 | - ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
137 | - ); |
|
138 | - $this->dependency_map->registerDependencies( |
|
139 | - 'EventEspresso\core\domain\services\graphql\types\FormElement', |
|
140 | - ['EEM_Form_Input' => EE_Dependency_Map::load_from_cache] |
|
141 | - ); |
|
142 | - $this->dependency_map->registerDependencies( |
|
143 | - 'EventEspresso\core\domain\services\graphql\types\FormSection', |
|
144 | - ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
145 | - ); |
|
146 | - $this->dependency_map->registerDependencies( |
|
147 | - 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
148 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
149 | - ); |
|
150 | - $this->dependency_map->registerDependencies( |
|
151 | - 'EventEspresso\core\domain\services\graphql\types\Price', |
|
152 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
153 | - ); |
|
154 | - $this->dependency_map->registerDependencies( |
|
155 | - 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
156 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
157 | - ); |
|
158 | - $this->dependency_map->registerDependencies( |
|
159 | - 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
160 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
161 | - ); |
|
162 | - $this->dependency_map->registerDependencies( |
|
163 | - 'EventEspresso\core\domain\services\graphql\types\State', |
|
164 | - ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
165 | - ); |
|
166 | - $this->dependency_map->registerDependencies( |
|
167 | - 'EventEspresso\core\domain\services\graphql\types\Country', |
|
168 | - ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
169 | - ); |
|
170 | - $this->dependency_map->registerDependencies( |
|
171 | - 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
172 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
173 | - ); |
|
174 | - $this->dependency_map->registerDependencies( |
|
175 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
176 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
177 | - ); |
|
178 | - $this->dependency_map->registerDependencies( |
|
179 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
180 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
181 | - ); |
|
182 | - $this->dependency_map->registerDependencies( |
|
183 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormElementsConnection', |
|
184 | - ['EEM_Form_Input' => EE_Dependency_Map::load_from_cache] |
|
185 | - ); |
|
186 | - $this->dependency_map->registerDependencies( |
|
187 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormSectionsConnection', |
|
188 | - ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
189 | - ); |
|
190 | - $this->dependency_map->registerDependencies( |
|
191 | - 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
192 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
193 | - ); |
|
194 | - $this->dependency_map->registerDependencies( |
|
195 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
196 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
197 | - ); |
|
198 | - $this->dependency_map->registerDependencies( |
|
199 | - 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
200 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
201 | - ); |
|
202 | - $this->dependency_map->registerDependencies( |
|
203 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
204 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
205 | - ); |
|
206 | - $this->dependency_map->registerDependencies( |
|
207 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
208 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
209 | - ); |
|
210 | - $this->dependency_map->registerDependencies( |
|
211 | - 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
212 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
213 | - ); |
|
214 | - $this->dependency_map->registerDependencies( |
|
215 | - 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
216 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
217 | - ); |
|
218 | - } |
|
81 | + /** |
|
82 | + * @since $VID:$ |
|
83 | + */ |
|
84 | + protected function registerDependencies() |
|
85 | + { |
|
86 | + $this->dependency_map->registerDependencies( |
|
87 | + 'EventEspresso\core\services\graphql\GraphQLManager', |
|
88 | + [ |
|
89 | + 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
90 | + 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
91 | + 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
92 | + 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
93 | + 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
94 | + ] |
|
95 | + ); |
|
96 | + $this->dependency_map->registerDependencies( |
|
97 | + 'EventEspresso\core\services\graphql\TypesManager', |
|
98 | + [ |
|
99 | + 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->dependency_map->registerDependencies( |
|
103 | + 'EventEspresso\core\services\graphql\InputsManager', |
|
104 | + [ |
|
105 | + 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
106 | + ] |
|
107 | + ); |
|
108 | + $this->dependency_map->registerDependencies( |
|
109 | + 'EventEspresso\core\services\graphql\EnumsManager', |
|
110 | + [ |
|
111 | + 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
112 | + ] |
|
113 | + ); |
|
114 | + $this->dependency_map->registerDependencies( |
|
115 | + 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
116 | + [ |
|
117 | + 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
118 | + ] |
|
119 | + ); |
|
120 | + $this->dependency_map->registerDependencies( |
|
121 | + 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
122 | + [ |
|
123 | + 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
124 | + ] |
|
125 | + ); |
|
126 | + $this->dependency_map->registerDependencies( |
|
127 | + 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
128 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
129 | + ); |
|
130 | + $this->dependency_map->registerDependencies( |
|
131 | + 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
132 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
133 | + ); |
|
134 | + $this->dependency_map->registerDependencies( |
|
135 | + 'EventEspresso\core\domain\services\graphql\types\Event', |
|
136 | + ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
137 | + ); |
|
138 | + $this->dependency_map->registerDependencies( |
|
139 | + 'EventEspresso\core\domain\services\graphql\types\FormElement', |
|
140 | + ['EEM_Form_Input' => EE_Dependency_Map::load_from_cache] |
|
141 | + ); |
|
142 | + $this->dependency_map->registerDependencies( |
|
143 | + 'EventEspresso\core\domain\services\graphql\types\FormSection', |
|
144 | + ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
145 | + ); |
|
146 | + $this->dependency_map->registerDependencies( |
|
147 | + 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
148 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
149 | + ); |
|
150 | + $this->dependency_map->registerDependencies( |
|
151 | + 'EventEspresso\core\domain\services\graphql\types\Price', |
|
152 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
153 | + ); |
|
154 | + $this->dependency_map->registerDependencies( |
|
155 | + 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
156 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
157 | + ); |
|
158 | + $this->dependency_map->registerDependencies( |
|
159 | + 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
160 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
161 | + ); |
|
162 | + $this->dependency_map->registerDependencies( |
|
163 | + 'EventEspresso\core\domain\services\graphql\types\State', |
|
164 | + ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
165 | + ); |
|
166 | + $this->dependency_map->registerDependencies( |
|
167 | + 'EventEspresso\core\domain\services\graphql\types\Country', |
|
168 | + ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
169 | + ); |
|
170 | + $this->dependency_map->registerDependencies( |
|
171 | + 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
172 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
173 | + ); |
|
174 | + $this->dependency_map->registerDependencies( |
|
175 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
176 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
177 | + ); |
|
178 | + $this->dependency_map->registerDependencies( |
|
179 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
180 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
181 | + ); |
|
182 | + $this->dependency_map->registerDependencies( |
|
183 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormElementsConnection', |
|
184 | + ['EEM_Form_Input' => EE_Dependency_Map::load_from_cache] |
|
185 | + ); |
|
186 | + $this->dependency_map->registerDependencies( |
|
187 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryFormSectionsConnection', |
|
188 | + ['EEM_Form_Section' => EE_Dependency_Map::load_from_cache] |
|
189 | + ); |
|
190 | + $this->dependency_map->registerDependencies( |
|
191 | + 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
192 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
193 | + ); |
|
194 | + $this->dependency_map->registerDependencies( |
|
195 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
196 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
197 | + ); |
|
198 | + $this->dependency_map->registerDependencies( |
|
199 | + 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
200 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
201 | + ); |
|
202 | + $this->dependency_map->registerDependencies( |
|
203 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
204 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
205 | + ); |
|
206 | + $this->dependency_map->registerDependencies( |
|
207 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
208 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
209 | + ); |
|
210 | + $this->dependency_map->registerDependencies( |
|
211 | + 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
212 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
213 | + ); |
|
214 | + $this->dependency_map->registerDependencies( |
|
215 | + 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
216 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
217 | + ); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - /** |
|
222 | - * implements logic required to run during request |
|
223 | - * |
|
224 | - * @return bool |
|
225 | - * @since $VID:$ |
|
226 | - */ |
|
227 | - protected function requestHandler(): bool |
|
228 | - { |
|
229 | - if (! class_exists('WPGraphQL')) { |
|
230 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
231 | - } |
|
232 | - // load handler for EE GraphQL requests |
|
233 | - $graphQL_manager = $this->loader->getShared( |
|
234 | - 'EventEspresso\core\services\graphql\GraphQLManager' |
|
235 | - ); |
|
236 | - $graphQL_manager->init(); |
|
237 | - $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
238 | - $manifest->initialize(); |
|
239 | - return true; |
|
240 | - } |
|
221 | + /** |
|
222 | + * implements logic required to run during request |
|
223 | + * |
|
224 | + * @return bool |
|
225 | + * @since $VID:$ |
|
226 | + */ |
|
227 | + protected function requestHandler(): bool |
|
228 | + { |
|
229 | + if (! class_exists('WPGraphQL')) { |
|
230 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
231 | + } |
|
232 | + // load handler for EE GraphQL requests |
|
233 | + $graphQL_manager = $this->loader->getShared( |
|
234 | + 'EventEspresso\core\services\graphql\GraphQLManager' |
|
235 | + ); |
|
236 | + $graphQL_manager->init(); |
|
237 | + $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
238 | + $manifest->initialize(); |
|
239 | + return true; |
|
240 | + } |
|
241 | 241 | } |
@@ -13,91 +13,91 @@ |
||
13 | 13 | abstract class EnumBase implements EnumInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var string $namespace The graphql namespace/prefix. |
|
18 | - */ |
|
19 | - protected $namespace = 'Espresso'; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var string $name |
|
23 | - */ |
|
24 | - protected $name = ''; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string $description |
|
28 | - */ |
|
29 | - protected $description = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array $values |
|
33 | - */ |
|
34 | - protected $values = []; |
|
35 | - |
|
36 | - /** |
|
37 | - * EnumBase constructor. |
|
38 | - */ |
|
39 | - public function __construct() |
|
40 | - { |
|
41 | - $this->setValues($this->getValues()); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - abstract protected function getValues(): array; |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function name(): string |
|
55 | - { |
|
56 | - return $this->name; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string $name |
|
62 | - */ |
|
63 | - protected function setName(string $name) |
|
64 | - { |
|
65 | - $this->name = $name; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function description(): string |
|
73 | - { |
|
74 | - return $this->description; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $description |
|
80 | - */ |
|
81 | - protected function setDescription(string $description) |
|
82 | - { |
|
83 | - $this->description = $description; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public function values(): array |
|
91 | - { |
|
92 | - return $this->values; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param array $values |
|
98 | - */ |
|
99 | - protected function setValues(array $values) |
|
100 | - { |
|
101 | - $this->values = $values; |
|
102 | - } |
|
16 | + /** |
|
17 | + * @var string $namespace The graphql namespace/prefix. |
|
18 | + */ |
|
19 | + protected $namespace = 'Espresso'; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var string $name |
|
23 | + */ |
|
24 | + protected $name = ''; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string $description |
|
28 | + */ |
|
29 | + protected $description = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array $values |
|
33 | + */ |
|
34 | + protected $values = []; |
|
35 | + |
|
36 | + /** |
|
37 | + * EnumBase constructor. |
|
38 | + */ |
|
39 | + public function __construct() |
|
40 | + { |
|
41 | + $this->setValues($this->getValues()); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + abstract protected function getValues(): array; |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function name(): string |
|
55 | + { |
|
56 | + return $this->name; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string $name |
|
62 | + */ |
|
63 | + protected function setName(string $name) |
|
64 | + { |
|
65 | + $this->name = $name; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function description(): string |
|
73 | + { |
|
74 | + return $this->description; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $description |
|
80 | + */ |
|
81 | + protected function setDescription(string $description) |
|
82 | + { |
|
83 | + $this->description = $description; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function values(): array |
|
91 | + { |
|
92 | + return $this->values; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param array $values |
|
98 | + */ |
|
99 | + protected function setValues(array $values) |
|
100 | + { |
|
101 | + $this->values = $values; |
|
102 | + } |
|
103 | 103 | } |
@@ -15,22 +15,22 @@ |
||
15 | 15 | abstract class ConnectionBase implements ConnectionInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EEM_Base $model |
|
20 | - */ |
|
21 | - protected $model; |
|
18 | + /** |
|
19 | + * @var EEM_Base $model |
|
20 | + */ |
|
21 | + protected $model; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var string $namespace The graphql namespace/prefix. |
|
25 | - */ |
|
26 | - protected $namespace = 'Espresso'; |
|
23 | + /** |
|
24 | + * @var string $namespace The graphql namespace/prefix. |
|
25 | + */ |
|
26 | + protected $namespace = 'Espresso'; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @param EEM_Base $model |
|
31 | - */ |
|
32 | - public function __construct(EEM_Base $model) |
|
33 | - { |
|
34 | - $this->model = $model; |
|
35 | - } |
|
29 | + /** |
|
30 | + * @param EEM_Base $model |
|
31 | + */ |
|
32 | + public function __construct(EEM_Base $model) |
|
33 | + { |
|
34 | + $this->model = $model; |
|
35 | + } |
|
36 | 36 | } |
@@ -15,12 +15,12 @@ |
||
15 | 15 | interface GQLDataDomainInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param array $loaders The loaders accessible in the AppContext |
|
20 | - * @param AppContext $context The AppContext |
|
21 | - * @return array |
|
22 | - * @return array |
|
23 | - * @since $VID:$ |
|
24 | - */ |
|
25 | - public function registerLoaders(array $loaders, AppContext $context): array; |
|
18 | + /** |
|
19 | + * @param array $loaders The loaders accessible in the AppContext |
|
20 | + * @param AppContext $context The AppContext |
|
21 | + * @return array |
|
22 | + * @return array |
|
23 | + * @since $VID:$ |
|
24 | + */ |
|
25 | + public function registerLoaders(array $loaders, AppContext $context): array; |
|
26 | 26 | } |
@@ -24,79 +24,79 @@ |
||
24 | 24 | interface TypeInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function name(): string; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function description(): string; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @return GraphQLFieldInterface[] |
|
41 | - * @since $VID:$ |
|
42 | - */ |
|
43 | - public function fields(): array; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Creates a key map for internal resolver. |
|
48 | - * |
|
49 | - * @return array |
|
50 | - * @since $VID:$ |
|
51 | - */ |
|
52 | - public function getFieldsForResolver(): array; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function isCustomPostType(): bool; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @param int|float $value |
|
63 | - * @return int |
|
64 | - * @since $VID:$ |
|
65 | - */ |
|
66 | - public function parseInfiniteValue($value): int; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
71 | - * @param array $args The inputArgs on the field |
|
72 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
73 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
74 | - * @return mixed |
|
75 | - * @throws EE_Error |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - * @throws UnexpectedEntityException |
|
79 | - * @throws UserError |
|
80 | - * @throws InvalidArgumentException |
|
81 | - * @throws ReflectionException |
|
82 | - * @since $VID:$ |
|
83 | - */ |
|
84 | - public function resolveField($source, array $args, AppContext $context, ResolveInfo $info); |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param mixed $payload The payload returned after mutation |
|
89 | - * @param array $args The inputArgs on the field |
|
90 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
91 | - * @return string|null |
|
92 | - * @throws EE_Error |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws UnexpectedEntityException |
|
96 | - * @throws UserError |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws ReflectionException |
|
99 | - * @since $VID:$ |
|
100 | - */ |
|
101 | - public function resolveFromPayload($payload, array $args, AppContext $context); |
|
27 | + /** |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function name(): string; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function description(): string; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @return GraphQLFieldInterface[] |
|
41 | + * @since $VID:$ |
|
42 | + */ |
|
43 | + public function fields(): array; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Creates a key map for internal resolver. |
|
48 | + * |
|
49 | + * @return array |
|
50 | + * @since $VID:$ |
|
51 | + */ |
|
52 | + public function getFieldsForResolver(): array; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function isCustomPostType(): bool; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @param int|float $value |
|
63 | + * @return int |
|
64 | + * @since $VID:$ |
|
65 | + */ |
|
66 | + public function parseInfiniteValue($value): int; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
71 | + * @param array $args The inputArgs on the field |
|
72 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
73 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
74 | + * @return mixed |
|
75 | + * @throws EE_Error |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + * @throws UnexpectedEntityException |
|
79 | + * @throws UserError |
|
80 | + * @throws InvalidArgumentException |
|
81 | + * @throws ReflectionException |
|
82 | + * @since $VID:$ |
|
83 | + */ |
|
84 | + public function resolveField($source, array $args, AppContext $context, ResolveInfo $info); |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param mixed $payload The payload returned after mutation |
|
89 | + * @param array $args The inputArgs on the field |
|
90 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
91 | + * @return string|null |
|
92 | + * @throws EE_Error |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws UnexpectedEntityException |
|
96 | + * @throws UserError |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws ReflectionException |
|
99 | + * @since $VID:$ |
|
100 | + */ |
|
101 | + public function resolveFromPayload($payload, array $args, AppContext $context); |
|
102 | 102 | } |
@@ -5,61 +5,61 @@ |
||
5 | 5 | class Element |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * indicates that element is not archived or trashed |
|
10 | - */ |
|
11 | - public const STATUS_ACTIVE = 'active'; |
|
8 | + /** |
|
9 | + * indicates that element is not archived or trashed |
|
10 | + */ |
|
11 | + public const STATUS_ACTIVE = 'active'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * indicates that element is archived and should no longer be displayed on public forms |
|
15 | - * but may still be required due to existing answers when form was completed prior to input being archived |
|
16 | - */ |
|
17 | - public const STATUS_ARCHIVED = 'archived'; |
|
13 | + /** |
|
14 | + * indicates that element is archived and should no longer be displayed on public forms |
|
15 | + * but may still be required due to existing answers when form was completed prior to input being archived |
|
16 | + */ |
|
17 | + public const STATUS_ARCHIVED = 'archived'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * indicates that element should be automatically added to newly created forms |
|
21 | - */ |
|
22 | - public const STATUS_DEFAULT = 'default'; |
|
19 | + /** |
|
20 | + * indicates that element should be automatically added to newly created forms |
|
21 | + */ |
|
22 | + public const STATUS_DEFAULT = 'default'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * indicates that a copy of the form section will be saved for use in other events but not loaded by default |
|
26 | - */ |
|
27 | - public const STATUS_SHARED = 'shared'; |
|
24 | + /** |
|
25 | + * indicates that a copy of the form section will be saved for use in other events but not loaded by default |
|
26 | + */ |
|
27 | + public const STATUS_SHARED = 'shared'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * indicates that element is no longer needed, has no existing answers, and can be moved to the trash |
|
31 | - */ |
|
32 | - public const STATUS_TRASHED = 'trashed'; |
|
29 | + /** |
|
30 | + * indicates that element is no longer needed, has no existing answers, and can be moved to the trash |
|
31 | + */ |
|
32 | + public const STATUS_TRASHED = 'trashed'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - private $valid_status_options; |
|
34 | + /** |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + private $valid_status_options; |
|
38 | 38 | |
39 | 39 | |
40 | - public function __construct() |
|
41 | - { |
|
42 | - $this->valid_status_options = apply_filters( |
|
43 | - 'FHEE__EventEspresso_core_services_form_meta_Element__valid_status_options', |
|
44 | - [ |
|
45 | - Element::STATUS_ACTIVE => esc_html__('Active', 'event_espresso'), |
|
46 | - Element::STATUS_ARCHIVED => esc_html__('Archived', 'event_espresso'), |
|
47 | - Element::STATUS_DEFAULT => esc_html__('Default', 'event_espresso'), |
|
48 | - Element::STATUS_SHARED => esc_html__('Shared', 'event_espresso'), |
|
49 | - Element::STATUS_TRASHED => esc_html__('Trashed', 'event_espresso'), |
|
50 | - ] |
|
51 | - ); |
|
52 | - } |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | + $this->valid_status_options = apply_filters( |
|
43 | + 'FHEE__EventEspresso_core_services_form_meta_Element__valid_status_options', |
|
44 | + [ |
|
45 | + Element::STATUS_ACTIVE => esc_html__('Active', 'event_espresso'), |
|
46 | + Element::STATUS_ARCHIVED => esc_html__('Archived', 'event_espresso'), |
|
47 | + Element::STATUS_DEFAULT => esc_html__('Default', 'event_espresso'), |
|
48 | + Element::STATUS_SHARED => esc_html__('Shared', 'event_espresso'), |
|
49 | + Element::STATUS_TRASHED => esc_html__('Trashed', 'event_espresso'), |
|
50 | + ] |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @param bool $constants_only |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function validStatusOptions(bool $constants_only = false): array |
|
60 | - { |
|
61 | - return $constants_only |
|
62 | - ? array_keys($this->valid_status_options) |
|
63 | - : $this->valid_status_options; |
|
64 | - } |
|
55 | + /** |
|
56 | + * @param bool $constants_only |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function validStatusOptions(bool $constants_only = false): array |
|
60 | + { |
|
61 | + return $constants_only |
|
62 | + ? array_keys($this->valid_status_options) |
|
63 | + : $this->valid_status_options; |
|
64 | + } |
|
65 | 65 | } |
@@ -14,337 +14,337 @@ |
||
14 | 14 | */ |
15 | 15 | class JsonDataHandler |
16 | 16 | { |
17 | - const DATA_TYPE_ARRAY = 'array'; |
|
18 | - |
|
19 | - const DATA_TYPE_OBJECT = 'object'; |
|
20 | - |
|
21 | - const DATA_TYPE_USE_FLAGS = 'flags'; |
|
22 | - |
|
23 | - const NO_ERROR_MSG = 'No error'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - private $data_type; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array|stdClass |
|
32 | - */ |
|
33 | - private $decoded_data; |
|
34 | - |
|
35 | - /** |
|
36 | - * JSON_BIGINT_AS_STRING, |
|
37 | - * JSON_INVALID_UTF8_IGNORE, |
|
38 | - * JSON_INVALID_UTF8_SUBSTITUTE, |
|
39 | - * JSON_OBJECT_AS_ARRAY, |
|
40 | - * JSON_THROW_ON_ERROR |
|
41 | - * |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - private $decode_flags; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var int |
|
48 | - */ |
|
49 | - private $depth; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - private $encoded_data; |
|
55 | - |
|
56 | - /** |
|
57 | - * JSON_FORCE_OBJECT, |
|
58 | - * JSON_HEX_QUOT, |
|
59 | - * JSON_HEX_TAG, |
|
60 | - * JSON_HEX_AMP, |
|
61 | - * JSON_HEX_APOS, |
|
62 | - * JSON_INVALID_UTF8_IGNORE, |
|
63 | - * JSON_INVALID_UTF8_SUBSTITUTE, |
|
64 | - * JSON_NUMERIC_CHECK, |
|
65 | - * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
66 | - * JSON_PRESERVE_ZERO_FRACTION, |
|
67 | - * JSON_PRETTY_PRINT, |
|
68 | - * JSON_UNESCAPED_LINE_TERMINATORS, |
|
69 | - * JSON_UNESCAPED_SLASHES, |
|
70 | - * JSON_UNESCAPED_UNICODE, |
|
71 | - * JSON_THROW_ON_ERROR. |
|
72 | - * |
|
73 | - * @var int |
|
74 | - */ |
|
75 | - private $encode_flags; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var int |
|
79 | - */ |
|
80 | - private $last_error_code = JSON_ERROR_NONE; |
|
81 | - |
|
82 | - /** |
|
83 | - * @var string |
|
84 | - */ |
|
85 | - private $last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * JsonDataHandler constructor. |
|
90 | - */ |
|
91 | - public function __construct() |
|
92 | - { |
|
93 | - if (! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
94 | - define('JSON_INVALID_UTF8_IGNORE', 1048576); |
|
95 | - } |
|
96 | - if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
97 | - define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152); |
|
98 | - } |
|
99 | - if (! defined('JSON_THROW_ON_ERROR')) { |
|
100 | - define('JSON_THROW_ON_ERROR', 4194304); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * set $data_type, $decode_flags, $encode_flags, and depth all in one shot |
|
107 | - * |
|
108 | - * @param string $data_type |
|
109 | - * @param int $decode_flags |
|
110 | - * @param int $encode_flags |
|
111 | - * @param int $depth |
|
112 | - */ |
|
113 | - public function configure( |
|
114 | - string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS, |
|
115 | - int $decode_flags = 0, |
|
116 | - int $encode_flags = 0, |
|
117 | - int $depth = 512 |
|
118 | - ) { |
|
119 | - $this->setDataType($data_type); |
|
120 | - $this->setDecodeFlags($decode_flags); |
|
121 | - $this->setDepth($depth); |
|
122 | - $this->setEncodeFlags($encode_flags); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $data_type |
|
128 | - */ |
|
129 | - public function setDataType(string $data_type): void |
|
130 | - { |
|
131 | - $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY |
|
132 | - || $data_type === JsonDataHandler::DATA_TYPE_OBJECT |
|
133 | - || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS |
|
134 | - ? $data_type |
|
135 | - : JsonDataHandler::DATA_TYPE_USE_FLAGS; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * One or more Bitmask values: |
|
141 | - * JSON_BIGINT_AS_STRING, |
|
142 | - * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
143 | - * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
144 | - * JSON_OBJECT_AS_ARRAY, |
|
145 | - * JSON_THROW_ON_ERROR PHP >= 7.3 |
|
146 | - * |
|
147 | - * pass multiple values separated with | |
|
148 | - * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY |
|
149 | - * |
|
150 | - * @param int $decode_flags |
|
151 | - */ |
|
152 | - public function setDecodeFlags(int $decode_flags): void |
|
153 | - { |
|
154 | - $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING |
|
155 | - || $decode_flags === JSON_OBJECT_AS_ARRAY |
|
156 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
157 | - || $decode_flags === JSON_INVALID_UTF8_IGNORE |
|
158 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
159 | - || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
160 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
161 | - || $decode_flags === JSON_THROW_ON_ERROR |
|
162 | - ? $decode_flags |
|
163 | - : 0; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param int $depth |
|
169 | - */ |
|
170 | - public function setDepth(int $depth): void |
|
171 | - { |
|
172 | - $depth = absint($depth); |
|
173 | - $this->depth = $depth ?: 512; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * One or more Bitmask values: |
|
179 | - * JSON_FORCE_OBJECT, |
|
180 | - * JSON_HEX_QUOT, |
|
181 | - * JSON_HEX_TAG, |
|
182 | - * JSON_HEX_AMP, |
|
183 | - * JSON_HEX_APOS, |
|
184 | - * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
185 | - * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
186 | - * JSON_NUMERIC_CHECK, |
|
187 | - * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
188 | - * JSON_PRESERVE_ZERO_FRACTION, |
|
189 | - * JSON_PRETTY_PRINT, |
|
190 | - * JSON_UNESCAPED_LINE_TERMINATORS, |
|
191 | - * JSON_UNESCAPED_SLASHES, |
|
192 | - * JSON_UNESCAPED_UNICODE, |
|
193 | - * JSON_THROW_ON_ERROR. PHP >= 7.3 |
|
194 | - * |
|
195 | - * pass multiple values separated with | |
|
196 | - * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR |
|
197 | - * |
|
198 | - * @param int $encode_flags |
|
199 | - */ |
|
200 | - public function setEncodeFlags(int $encode_flags): void |
|
201 | - { |
|
202 | - $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT |
|
203 | - || $encode_flags === JSON_HEX_QUOT |
|
204 | - || $encode_flags === JSON_HEX_TAG |
|
205 | - || $encode_flags === JSON_HEX_AMP |
|
206 | - || $encode_flags === JSON_HEX_APOS |
|
207 | - || $encode_flags === JSON_NUMERIC_CHECK |
|
208 | - || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR |
|
209 | - || $encode_flags === JSON_PRESERVE_ZERO_FRACTION |
|
210 | - || $encode_flags === JSON_PRETTY_PRINT |
|
211 | - || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS |
|
212 | - || $encode_flags === JSON_UNESCAPED_SLASHES |
|
213 | - || $encode_flags === JSON_UNESCAPED_UNICODE |
|
214 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
215 | - || $encode_flags === JSON_INVALID_UTF8_IGNORE |
|
216 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
217 | - || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
218 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
219 | - || $encode_flags === JSON_THROW_ON_ERROR |
|
220 | - ? $encode_flags |
|
221 | - : 0; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return bool|null |
|
227 | - */ |
|
228 | - private function asAssociative(): ?bool |
|
229 | - { |
|
230 | - switch ($this->data_type) { |
|
231 | - case JsonDataHandler::DATA_TYPE_ARRAY: |
|
232 | - return true; |
|
233 | - case JsonDataHandler::DATA_TYPE_OBJECT: |
|
234 | - return false; |
|
235 | - case JsonDataHandler::DATA_TYPE_USE_FLAGS: |
|
236 | - return null; |
|
237 | - } |
|
238 | - return null; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param array|string $json |
|
244 | - * @return array|mixed|stdClass |
|
245 | - */ |
|
246 | - public function decodeJson($json) |
|
247 | - { |
|
248 | - $this->resetErrors(); |
|
249 | - if ($this->isJson($json)) { |
|
250 | - $this->decoded_data = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
251 | - $this->last_error_code = json_last_error(); |
|
252 | - $this->last_error_msg = json_last_error_msg(); |
|
253 | - } else { |
|
254 | - $this->decoded_data = $json; |
|
255 | - $this->last_error_code = JSON_ERROR_NONE; |
|
256 | - $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
257 | - } |
|
258 | - return $this->decoded_data; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param $data |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - public function encodeData($data): string |
|
267 | - { |
|
268 | - $this->resetErrors(); |
|
269 | - if ($this->isJson($data)) { |
|
270 | - $this->encoded_data = $data; |
|
271 | - $this->last_error_code = JSON_ERROR_NONE; |
|
272 | - $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
273 | - } else { |
|
274 | - $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth); |
|
275 | - $this->last_error_code = json_last_error(); |
|
276 | - $this->last_error_msg = json_last_error_msg(); |
|
277 | - } |
|
278 | - return $this->encoded_data ?: '{}'; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * @return array|stdClass |
|
284 | - */ |
|
285 | - public function getDecodedData() |
|
286 | - { |
|
287 | - return $this->decoded_data; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * @return string |
|
293 | - */ |
|
294 | - public function getEncodedData(): string |
|
295 | - { |
|
296 | - return $this->encoded_data; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * @param bool $reset |
|
302 | - * @return int |
|
303 | - */ |
|
304 | - public function getLastErrorCode(bool $reset = false): int |
|
305 | - { |
|
306 | - $last_error = $this->last_error_code; |
|
307 | - if ($reset) { |
|
308 | - $this->resetErrors(); |
|
309 | - } |
|
310 | - return $last_error; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param bool $reset |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public function getLastErrorMessage(bool $reset = false): string |
|
319 | - { |
|
320 | - $last_error = $this->last_error_msg; |
|
321 | - if ($reset) { |
|
322 | - $this->resetErrors(); |
|
323 | - } |
|
324 | - return $last_error; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param array|string $maybe_json |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function isJson($maybe_json): bool |
|
333 | - { |
|
334 | - if (! is_string($maybe_json)) { |
|
335 | - return false; |
|
336 | - } |
|
337 | - $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
338 | - return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json)); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @since $VID:$ |
|
344 | - */ |
|
345 | - public function resetErrors() |
|
346 | - { |
|
347 | - $this->last_error_code = JSON_ERROR_NONE; |
|
348 | - $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
349 | - } |
|
17 | + const DATA_TYPE_ARRAY = 'array'; |
|
18 | + |
|
19 | + const DATA_TYPE_OBJECT = 'object'; |
|
20 | + |
|
21 | + const DATA_TYPE_USE_FLAGS = 'flags'; |
|
22 | + |
|
23 | + const NO_ERROR_MSG = 'No error'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + private $data_type; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array|stdClass |
|
32 | + */ |
|
33 | + private $decoded_data; |
|
34 | + |
|
35 | + /** |
|
36 | + * JSON_BIGINT_AS_STRING, |
|
37 | + * JSON_INVALID_UTF8_IGNORE, |
|
38 | + * JSON_INVALID_UTF8_SUBSTITUTE, |
|
39 | + * JSON_OBJECT_AS_ARRAY, |
|
40 | + * JSON_THROW_ON_ERROR |
|
41 | + * |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + private $decode_flags; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var int |
|
48 | + */ |
|
49 | + private $depth; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + private $encoded_data; |
|
55 | + |
|
56 | + /** |
|
57 | + * JSON_FORCE_OBJECT, |
|
58 | + * JSON_HEX_QUOT, |
|
59 | + * JSON_HEX_TAG, |
|
60 | + * JSON_HEX_AMP, |
|
61 | + * JSON_HEX_APOS, |
|
62 | + * JSON_INVALID_UTF8_IGNORE, |
|
63 | + * JSON_INVALID_UTF8_SUBSTITUTE, |
|
64 | + * JSON_NUMERIC_CHECK, |
|
65 | + * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
66 | + * JSON_PRESERVE_ZERO_FRACTION, |
|
67 | + * JSON_PRETTY_PRINT, |
|
68 | + * JSON_UNESCAPED_LINE_TERMINATORS, |
|
69 | + * JSON_UNESCAPED_SLASHES, |
|
70 | + * JSON_UNESCAPED_UNICODE, |
|
71 | + * JSON_THROW_ON_ERROR. |
|
72 | + * |
|
73 | + * @var int |
|
74 | + */ |
|
75 | + private $encode_flags; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var int |
|
79 | + */ |
|
80 | + private $last_error_code = JSON_ERROR_NONE; |
|
81 | + |
|
82 | + /** |
|
83 | + * @var string |
|
84 | + */ |
|
85 | + private $last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * JsonDataHandler constructor. |
|
90 | + */ |
|
91 | + public function __construct() |
|
92 | + { |
|
93 | + if (! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
94 | + define('JSON_INVALID_UTF8_IGNORE', 1048576); |
|
95 | + } |
|
96 | + if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
97 | + define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152); |
|
98 | + } |
|
99 | + if (! defined('JSON_THROW_ON_ERROR')) { |
|
100 | + define('JSON_THROW_ON_ERROR', 4194304); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * set $data_type, $decode_flags, $encode_flags, and depth all in one shot |
|
107 | + * |
|
108 | + * @param string $data_type |
|
109 | + * @param int $decode_flags |
|
110 | + * @param int $encode_flags |
|
111 | + * @param int $depth |
|
112 | + */ |
|
113 | + public function configure( |
|
114 | + string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS, |
|
115 | + int $decode_flags = 0, |
|
116 | + int $encode_flags = 0, |
|
117 | + int $depth = 512 |
|
118 | + ) { |
|
119 | + $this->setDataType($data_type); |
|
120 | + $this->setDecodeFlags($decode_flags); |
|
121 | + $this->setDepth($depth); |
|
122 | + $this->setEncodeFlags($encode_flags); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $data_type |
|
128 | + */ |
|
129 | + public function setDataType(string $data_type): void |
|
130 | + { |
|
131 | + $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY |
|
132 | + || $data_type === JsonDataHandler::DATA_TYPE_OBJECT |
|
133 | + || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS |
|
134 | + ? $data_type |
|
135 | + : JsonDataHandler::DATA_TYPE_USE_FLAGS; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * One or more Bitmask values: |
|
141 | + * JSON_BIGINT_AS_STRING, |
|
142 | + * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
143 | + * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
144 | + * JSON_OBJECT_AS_ARRAY, |
|
145 | + * JSON_THROW_ON_ERROR PHP >= 7.3 |
|
146 | + * |
|
147 | + * pass multiple values separated with | |
|
148 | + * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY |
|
149 | + * |
|
150 | + * @param int $decode_flags |
|
151 | + */ |
|
152 | + public function setDecodeFlags(int $decode_flags): void |
|
153 | + { |
|
154 | + $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING |
|
155 | + || $decode_flags === JSON_OBJECT_AS_ARRAY |
|
156 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
157 | + || $decode_flags === JSON_INVALID_UTF8_IGNORE |
|
158 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
159 | + || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
160 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
161 | + || $decode_flags === JSON_THROW_ON_ERROR |
|
162 | + ? $decode_flags |
|
163 | + : 0; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param int $depth |
|
169 | + */ |
|
170 | + public function setDepth(int $depth): void |
|
171 | + { |
|
172 | + $depth = absint($depth); |
|
173 | + $this->depth = $depth ?: 512; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * One or more Bitmask values: |
|
179 | + * JSON_FORCE_OBJECT, |
|
180 | + * JSON_HEX_QUOT, |
|
181 | + * JSON_HEX_TAG, |
|
182 | + * JSON_HEX_AMP, |
|
183 | + * JSON_HEX_APOS, |
|
184 | + * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
185 | + * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
186 | + * JSON_NUMERIC_CHECK, |
|
187 | + * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
188 | + * JSON_PRESERVE_ZERO_FRACTION, |
|
189 | + * JSON_PRETTY_PRINT, |
|
190 | + * JSON_UNESCAPED_LINE_TERMINATORS, |
|
191 | + * JSON_UNESCAPED_SLASHES, |
|
192 | + * JSON_UNESCAPED_UNICODE, |
|
193 | + * JSON_THROW_ON_ERROR. PHP >= 7.3 |
|
194 | + * |
|
195 | + * pass multiple values separated with | |
|
196 | + * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR |
|
197 | + * |
|
198 | + * @param int $encode_flags |
|
199 | + */ |
|
200 | + public function setEncodeFlags(int $encode_flags): void |
|
201 | + { |
|
202 | + $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT |
|
203 | + || $encode_flags === JSON_HEX_QUOT |
|
204 | + || $encode_flags === JSON_HEX_TAG |
|
205 | + || $encode_flags === JSON_HEX_AMP |
|
206 | + || $encode_flags === JSON_HEX_APOS |
|
207 | + || $encode_flags === JSON_NUMERIC_CHECK |
|
208 | + || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR |
|
209 | + || $encode_flags === JSON_PRESERVE_ZERO_FRACTION |
|
210 | + || $encode_flags === JSON_PRETTY_PRINT |
|
211 | + || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS |
|
212 | + || $encode_flags === JSON_UNESCAPED_SLASHES |
|
213 | + || $encode_flags === JSON_UNESCAPED_UNICODE |
|
214 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
215 | + || $encode_flags === JSON_INVALID_UTF8_IGNORE |
|
216 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
217 | + || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
218 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
219 | + || $encode_flags === JSON_THROW_ON_ERROR |
|
220 | + ? $encode_flags |
|
221 | + : 0; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return bool|null |
|
227 | + */ |
|
228 | + private function asAssociative(): ?bool |
|
229 | + { |
|
230 | + switch ($this->data_type) { |
|
231 | + case JsonDataHandler::DATA_TYPE_ARRAY: |
|
232 | + return true; |
|
233 | + case JsonDataHandler::DATA_TYPE_OBJECT: |
|
234 | + return false; |
|
235 | + case JsonDataHandler::DATA_TYPE_USE_FLAGS: |
|
236 | + return null; |
|
237 | + } |
|
238 | + return null; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param array|string $json |
|
244 | + * @return array|mixed|stdClass |
|
245 | + */ |
|
246 | + public function decodeJson($json) |
|
247 | + { |
|
248 | + $this->resetErrors(); |
|
249 | + if ($this->isJson($json)) { |
|
250 | + $this->decoded_data = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
251 | + $this->last_error_code = json_last_error(); |
|
252 | + $this->last_error_msg = json_last_error_msg(); |
|
253 | + } else { |
|
254 | + $this->decoded_data = $json; |
|
255 | + $this->last_error_code = JSON_ERROR_NONE; |
|
256 | + $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
257 | + } |
|
258 | + return $this->decoded_data; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param $data |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + public function encodeData($data): string |
|
267 | + { |
|
268 | + $this->resetErrors(); |
|
269 | + if ($this->isJson($data)) { |
|
270 | + $this->encoded_data = $data; |
|
271 | + $this->last_error_code = JSON_ERROR_NONE; |
|
272 | + $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
273 | + } else { |
|
274 | + $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth); |
|
275 | + $this->last_error_code = json_last_error(); |
|
276 | + $this->last_error_msg = json_last_error_msg(); |
|
277 | + } |
|
278 | + return $this->encoded_data ?: '{}'; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * @return array|stdClass |
|
284 | + */ |
|
285 | + public function getDecodedData() |
|
286 | + { |
|
287 | + return $this->decoded_data; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * @return string |
|
293 | + */ |
|
294 | + public function getEncodedData(): string |
|
295 | + { |
|
296 | + return $this->encoded_data; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * @param bool $reset |
|
302 | + * @return int |
|
303 | + */ |
|
304 | + public function getLastErrorCode(bool $reset = false): int |
|
305 | + { |
|
306 | + $last_error = $this->last_error_code; |
|
307 | + if ($reset) { |
|
308 | + $this->resetErrors(); |
|
309 | + } |
|
310 | + return $last_error; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param bool $reset |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public function getLastErrorMessage(bool $reset = false): string |
|
319 | + { |
|
320 | + $last_error = $this->last_error_msg; |
|
321 | + if ($reset) { |
|
322 | + $this->resetErrors(); |
|
323 | + } |
|
324 | + return $last_error; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param array|string $maybe_json |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public function isJson($maybe_json): bool |
|
333 | + { |
|
334 | + if (! is_string($maybe_json)) { |
|
335 | + return false; |
|
336 | + } |
|
337 | + $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
338 | + return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json)); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @since $VID:$ |
|
344 | + */ |
|
345 | + public function resetErrors() |
|
346 | + { |
|
347 | + $this->last_error_code = JSON_ERROR_NONE; |
|
348 | + $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
349 | + } |
|
350 | 350 | } |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function __construct() |
92 | 92 | { |
93 | - if (! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
93 | + if ( ! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
94 | 94 | define('JSON_INVALID_UTF8_IGNORE', 1048576); |
95 | 95 | } |
96 | - if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
96 | + if ( ! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
97 | 97 | define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152); |
98 | 98 | } |
99 | - if (! defined('JSON_THROW_ON_ERROR')) { |
|
99 | + if ( ! defined('JSON_THROW_ON_ERROR')) { |
|
100 | 100 | define('JSON_THROW_ON_ERROR', 4194304); |
101 | 101 | } |
102 | 102 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function isJson($maybe_json): bool |
333 | 333 | { |
334 | - if (! is_string($maybe_json)) { |
|
334 | + if ( ! is_string($maybe_json)) { |
|
335 | 335 | return false; |
336 | 336 | } |
337 | 337 | $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags); |
@@ -27,510 +27,510 @@ |
||
27 | 27 | class EE_Form_Input extends EE_Base_Class |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @param array $props_n_values |
|
32 | - * @return EE_Form_Input |
|
33 | - * @throws EE_Error |
|
34 | - * @throws ReflectionException |
|
35 | - */ |
|
36 | - public static function new_instance(array $props_n_values = []): EE_Form_Input |
|
37 | - { |
|
38 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
39 | - return $has_object |
|
40 | - ?: new self($props_n_values); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param array $props_n_values |
|
46 | - * @return EE_Form_Input |
|
47 | - * @throws EE_Error |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Input |
|
51 | - { |
|
52 | - return new self($props_n_values); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Form Input UUID (universally unique identifier) |
|
58 | - * |
|
59 | - * @return string |
|
60 | - * @throws EE_Error |
|
61 | - * @throws ReflectionException |
|
62 | - */ |
|
63 | - public function UUID(): string |
|
64 | - { |
|
65 | - return $this->get('FIN_UUID'); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @param string $UUID |
|
71 | - * @throws EE_Error |
|
72 | - * @throws ReflectionException |
|
73 | - */ |
|
74 | - public function setUUID(string $UUID) |
|
75 | - { |
|
76 | - $this->set('FIN_UUID', $UUID); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Input label displayed in the admin to help differentiate input from others |
|
82 | - * |
|
83 | - * @return string |
|
84 | - * @throws EE_Error |
|
85 | - * @throws ReflectionException |
|
86 | - */ |
|
87 | - public function adminLabel():? string |
|
88 | - { |
|
89 | - return $this->get('FIN_adminLabel'); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $admin_label |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function setAdminLabel(string $admin_label) |
|
99 | - { |
|
100 | - $this->set('FIN_adminLabel', $admin_label); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
106 | - * |
|
107 | - * @return bool |
|
108 | - * @throws EE_Error |
|
109 | - * @throws ReflectionException |
|
110 | - */ |
|
111 | - public function adminOnly(): ?bool |
|
112 | - { |
|
113 | - return $this->get('FIN_adminOnly'); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param bool $admin_only |
|
119 | - * @throws EE_Error |
|
120 | - * @throws ReflectionException |
|
121 | - */ |
|
122 | - public function setAdminOnly(bool $admin_only) |
|
123 | - { |
|
124 | - $this->set('FIN_adminOnly', $admin_only); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * UUID of parent form section this form input belongs to. |
|
130 | - * |
|
131 | - * @return string |
|
132 | - * @throws EE_Error |
|
133 | - * @throws ReflectionException |
|
134 | - */ |
|
135 | - public function belongsTo(): string |
|
136 | - { |
|
137 | - return $this->get('FSC_UUID'); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $relation_UUID |
|
143 | - * @throws EE_Error |
|
144 | - * @throws ReflectionException |
|
145 | - */ |
|
146 | - public function setBelongsTo(string $relation_UUID) |
|
147 | - { |
|
148 | - $this->set('FSC_UUID', $relation_UUID); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Custom HTML classes to be applied to this form input's help text. |
|
154 | - * |
|
155 | - * @return string |
|
156 | - * @throws EE_Error |
|
157 | - * @throws ReflectionException |
|
158 | - */ |
|
159 | - public function helpClass():? string |
|
160 | - { |
|
161 | - return $this->get('FIN_helpClass'); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param string $help_class |
|
167 | - * @throws EE_Error |
|
168 | - * @throws ReflectionException |
|
169 | - */ |
|
170 | - public function setHelpClass(string $help_class) |
|
171 | - { |
|
172 | - $this->set('FIN_helpClass', $help_class); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Additional text displayed alongside a form input to assist users with completing the form. |
|
178 | - * |
|
179 | - * @return string |
|
180 | - * @throws EE_Error |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - public function helpText():? string |
|
184 | - { |
|
185 | - return $this->get('FIN_helpText'); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @param string $help_text |
|
191 | - * @throws EE_Error |
|
192 | - * @throws ReflectionException |
|
193 | - */ |
|
194 | - public function setHelpText(string $help_text) |
|
195 | - { |
|
196 | - $this->set('FIN_helpText', $help_text); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * HTML classes to be applied to this form input's container. |
|
202 | - * |
|
203 | - * @return string |
|
204 | - * @throws EE_Error |
|
205 | - * @throws ReflectionException |
|
206 | - */ |
|
207 | - public function htmlClass():? string |
|
208 | - { |
|
209 | - return $this->get('FIN_htmlClass'); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * HTML classes to be applied to this form input's container. |
|
215 | - * |
|
216 | - * @param string $html_class |
|
217 | - * @throws EE_Error |
|
218 | - * @throws ReflectionException |
|
219 | - */ |
|
220 | - public function setHtmlClass(string $html_class) |
|
221 | - { |
|
222 | - $this->set('FIN_htmlClass', $html_class); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Model and Fields name that this input maps to; ex: Attendee.email |
|
228 | - * |
|
229 | - * @return string |
|
230 | - * @throws EE_Error |
|
231 | - * @throws ReflectionException |
|
232 | - */ |
|
233 | - public function mapsTo():? string |
|
234 | - { |
|
235 | - return $this->get('FIN_mapsTo'); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * @param string $model ex: Attendee |
|
241 | - * @param string $field ex: email |
|
242 | - * @throws EE_Error |
|
243 | - * @throws ReflectionException |
|
244 | - */ |
|
245 | - public function setMapsTo(string $model, string $field) |
|
246 | - { |
|
247 | - $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Maximum numeric value or maximum characters allowed for form input answer. |
|
253 | - * |
|
254 | - * @return int|float |
|
255 | - * @throws EE_Error |
|
256 | - * @throws ReflectionException |
|
257 | - */ |
|
258 | - public function max() |
|
259 | - { |
|
260 | - $max = $this->get('FIN_max'); |
|
261 | - return $max > -1 ? $max : EE_INF; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @param int|float $max |
|
267 | - * @throws EE_Error |
|
268 | - * @throws ReflectionException |
|
269 | - */ |
|
270 | - public function setMax($max) |
|
271 | - { |
|
272 | - $this->set('FIN_max', $max); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Minimum numeric value or minimum characters allowed for form input answer. |
|
279 | - * |
|
280 | - * @return int|float |
|
281 | - * @throws EE_Error |
|
282 | - * @throws ReflectionException |
|
283 | - */ |
|
284 | - public function min() |
|
285 | - { |
|
286 | - return $this->get('FIN_min'); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @param int|float $min |
|
292 | - * @throws EE_Error |
|
293 | - * @throws ReflectionException |
|
294 | - */ |
|
295 | - public function setMin($min) |
|
296 | - { |
|
297 | - $this->set('FIN_min', $min); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
303 | - * |
|
304 | - * @return array |
|
305 | - * @throws EE_Error |
|
306 | - * @throws ReflectionException |
|
307 | - */ |
|
308 | - public function options(): ?array |
|
309 | - { |
|
310 | - return $this->get('FIN_options'); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param array $options |
|
316 | - * @throws EE_Error |
|
317 | - * @throws ReflectionException |
|
318 | - */ |
|
319 | - public function setOptions(array $options) |
|
320 | - { |
|
321 | - $this->set('FIN_options', $options); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Order in which form input appears in a form. |
|
328 | - * |
|
329 | - * @return int |
|
330 | - * @throws EE_Error |
|
331 | - * @throws ReflectionException |
|
332 | - */ |
|
333 | - public function order(): int |
|
334 | - { |
|
335 | - return $this->get('FIN_order'); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @param int $order |
|
341 | - * @throws EE_Error |
|
342 | - * @throws ReflectionException |
|
343 | - */ |
|
344 | - public function setOrder(int $order) |
|
345 | - { |
|
346 | - $this->set('FIN_order', $order); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * Example text displayed within an input to assist users with completing the form. |
|
352 | - * |
|
353 | - * @return string |
|
354 | - * @throws EE_Error |
|
355 | - * @throws ReflectionException |
|
356 | - */ |
|
357 | - public function placeholder():? string |
|
358 | - { |
|
359 | - return $this->get('FIN_placeholder'); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * @param string $placeholder |
|
365 | - * @throws EE_Error |
|
366 | - * @throws ReflectionException |
|
367 | - */ |
|
368 | - public function setPlaceholder(string $placeholder) |
|
369 | - { |
|
370 | - $this->set('FIN_placeholder', $placeholder); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Input label displayed on public forms, ie: the actual question text. |
|
376 | - * |
|
377 | - * @return string |
|
378 | - * @throws EE_Error |
|
379 | - * @throws ReflectionException |
|
380 | - */ |
|
381 | - public function publicLabel(): ?string |
|
382 | - { |
|
383 | - return $this->get('FIN_publicLabel'); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param string $publicLabel |
|
389 | - * @throws EE_Error |
|
390 | - * @throws ReflectionException |
|
391 | - */ |
|
392 | - public function setPublicLabel(string $publicLabel) |
|
393 | - { |
|
394 | - $this->set('FIN_publicLabel', $publicLabel); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * Whether or not the input must be supplied with a value in order to complete the form. |
|
400 | - * |
|
401 | - * @return bool |
|
402 | - * @throws EE_Error |
|
403 | - * @throws ReflectionException |
|
404 | - */ |
|
405 | - public function required(): ?bool |
|
406 | - { |
|
407 | - return $this->get('FIN_required'); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * @param bool $required |
|
413 | - * @throws EE_Error |
|
414 | - * @throws ReflectionException |
|
415 | - */ |
|
416 | - public function setRequired(bool $required) |
|
417 | - { |
|
418 | - $this->set('FIN_required', $required); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Custom validation text displayed alongside a required form input to assist users with completing the form. |
|
424 | - * |
|
425 | - * @return string |
|
426 | - * @throws EE_Error |
|
427 | - * @throws ReflectionException |
|
428 | - */ |
|
429 | - public function requiredText():? string |
|
430 | - { |
|
431 | - return $this->get('FIN_requiredText'); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $requiredText |
|
437 | - * @throws EE_Error |
|
438 | - * @throws ReflectionException |
|
439 | - */ |
|
440 | - public function setRequiredText(string $requiredText) |
|
441 | - { |
|
442 | - $this->set('FIN_requiredText', $requiredText); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * version of public label for use in identifiers |
|
448 | - * |
|
449 | - * @return string |
|
450 | - * @throws EE_Error |
|
451 | - * @throws ReflectionException |
|
452 | - */ |
|
453 | - public function slug(): ?string |
|
454 | - { |
|
455 | - return sanitize_title($this->publicLabel()); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
461 | - * Values correspond to the EEM_Form_Input::STATUS_* constants. |
|
462 | - * |
|
463 | - * @return string |
|
464 | - * @throws EE_Error |
|
465 | - * @throws ReflectionException |
|
466 | - */ |
|
467 | - public function status(): string |
|
468 | - { |
|
469 | - return $this->get('FIN_status'); |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
475 | - * Values correspond to the EEM_Form_Input::STATUS_* constants. |
|
476 | - * |
|
477 | - * @param string $status |
|
478 | - * @throws EE_Error |
|
479 | - * @throws ReflectionException |
|
480 | - */ |
|
481 | - public function setStatus(string $status) |
|
482 | - { |
|
483 | - $this->set('FIN_status', $status); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * Form input type. |
|
489 | - * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
490 | - * |
|
491 | - * @return string |
|
492 | - * @throws EE_Error |
|
493 | - * @throws ReflectionException |
|
494 | - */ |
|
495 | - public function type(): ?string |
|
496 | - { |
|
497 | - return $this->get('FIN_type'); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * @param string $type |
|
503 | - * @throws EE_Error |
|
504 | - * @throws ReflectionException |
|
505 | - */ |
|
506 | - public function setType(string $type) |
|
507 | - { |
|
508 | - $this->set('FIN_type', $type); |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * ID of the WP User that created this form input. |
|
514 | - * |
|
515 | - * @return int |
|
516 | - * @throws EE_Error |
|
517 | - * @throws ReflectionException |
|
518 | - */ |
|
519 | - public function wp_user(): int |
|
520 | - { |
|
521 | - return $this->get('FIN_wpUser'); |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * returns the id the wordpress user who created this question |
|
527 | - * |
|
528 | - * @param int $wp_user |
|
529 | - * @throws EE_Error |
|
530 | - * @throws ReflectionException |
|
531 | - */ |
|
532 | - public function setWpUser(int $wp_user) |
|
533 | - { |
|
534 | - $this->set('FIN_wpUser', $wp_user); |
|
535 | - } |
|
30 | + /** |
|
31 | + * @param array $props_n_values |
|
32 | + * @return EE_Form_Input |
|
33 | + * @throws EE_Error |
|
34 | + * @throws ReflectionException |
|
35 | + */ |
|
36 | + public static function new_instance(array $props_n_values = []): EE_Form_Input |
|
37 | + { |
|
38 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
39 | + return $has_object |
|
40 | + ?: new self($props_n_values); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param array $props_n_values |
|
46 | + * @return EE_Form_Input |
|
47 | + * @throws EE_Error |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Input |
|
51 | + { |
|
52 | + return new self($props_n_values); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Form Input UUID (universally unique identifier) |
|
58 | + * |
|
59 | + * @return string |
|
60 | + * @throws EE_Error |
|
61 | + * @throws ReflectionException |
|
62 | + */ |
|
63 | + public function UUID(): string |
|
64 | + { |
|
65 | + return $this->get('FIN_UUID'); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @param string $UUID |
|
71 | + * @throws EE_Error |
|
72 | + * @throws ReflectionException |
|
73 | + */ |
|
74 | + public function setUUID(string $UUID) |
|
75 | + { |
|
76 | + $this->set('FIN_UUID', $UUID); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Input label displayed in the admin to help differentiate input from others |
|
82 | + * |
|
83 | + * @return string |
|
84 | + * @throws EE_Error |
|
85 | + * @throws ReflectionException |
|
86 | + */ |
|
87 | + public function adminLabel():? string |
|
88 | + { |
|
89 | + return $this->get('FIN_adminLabel'); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $admin_label |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function setAdminLabel(string $admin_label) |
|
99 | + { |
|
100 | + $this->set('FIN_adminLabel', $admin_label); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
106 | + * |
|
107 | + * @return bool |
|
108 | + * @throws EE_Error |
|
109 | + * @throws ReflectionException |
|
110 | + */ |
|
111 | + public function adminOnly(): ?bool |
|
112 | + { |
|
113 | + return $this->get('FIN_adminOnly'); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param bool $admin_only |
|
119 | + * @throws EE_Error |
|
120 | + * @throws ReflectionException |
|
121 | + */ |
|
122 | + public function setAdminOnly(bool $admin_only) |
|
123 | + { |
|
124 | + $this->set('FIN_adminOnly', $admin_only); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * UUID of parent form section this form input belongs to. |
|
130 | + * |
|
131 | + * @return string |
|
132 | + * @throws EE_Error |
|
133 | + * @throws ReflectionException |
|
134 | + */ |
|
135 | + public function belongsTo(): string |
|
136 | + { |
|
137 | + return $this->get('FSC_UUID'); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $relation_UUID |
|
143 | + * @throws EE_Error |
|
144 | + * @throws ReflectionException |
|
145 | + */ |
|
146 | + public function setBelongsTo(string $relation_UUID) |
|
147 | + { |
|
148 | + $this->set('FSC_UUID', $relation_UUID); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Custom HTML classes to be applied to this form input's help text. |
|
154 | + * |
|
155 | + * @return string |
|
156 | + * @throws EE_Error |
|
157 | + * @throws ReflectionException |
|
158 | + */ |
|
159 | + public function helpClass():? string |
|
160 | + { |
|
161 | + return $this->get('FIN_helpClass'); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param string $help_class |
|
167 | + * @throws EE_Error |
|
168 | + * @throws ReflectionException |
|
169 | + */ |
|
170 | + public function setHelpClass(string $help_class) |
|
171 | + { |
|
172 | + $this->set('FIN_helpClass', $help_class); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Additional text displayed alongside a form input to assist users with completing the form. |
|
178 | + * |
|
179 | + * @return string |
|
180 | + * @throws EE_Error |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + public function helpText():? string |
|
184 | + { |
|
185 | + return $this->get('FIN_helpText'); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @param string $help_text |
|
191 | + * @throws EE_Error |
|
192 | + * @throws ReflectionException |
|
193 | + */ |
|
194 | + public function setHelpText(string $help_text) |
|
195 | + { |
|
196 | + $this->set('FIN_helpText', $help_text); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * HTML classes to be applied to this form input's container. |
|
202 | + * |
|
203 | + * @return string |
|
204 | + * @throws EE_Error |
|
205 | + * @throws ReflectionException |
|
206 | + */ |
|
207 | + public function htmlClass():? string |
|
208 | + { |
|
209 | + return $this->get('FIN_htmlClass'); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * HTML classes to be applied to this form input's container. |
|
215 | + * |
|
216 | + * @param string $html_class |
|
217 | + * @throws EE_Error |
|
218 | + * @throws ReflectionException |
|
219 | + */ |
|
220 | + public function setHtmlClass(string $html_class) |
|
221 | + { |
|
222 | + $this->set('FIN_htmlClass', $html_class); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Model and Fields name that this input maps to; ex: Attendee.email |
|
228 | + * |
|
229 | + * @return string |
|
230 | + * @throws EE_Error |
|
231 | + * @throws ReflectionException |
|
232 | + */ |
|
233 | + public function mapsTo():? string |
|
234 | + { |
|
235 | + return $this->get('FIN_mapsTo'); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * @param string $model ex: Attendee |
|
241 | + * @param string $field ex: email |
|
242 | + * @throws EE_Error |
|
243 | + * @throws ReflectionException |
|
244 | + */ |
|
245 | + public function setMapsTo(string $model, string $field) |
|
246 | + { |
|
247 | + $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Maximum numeric value or maximum characters allowed for form input answer. |
|
253 | + * |
|
254 | + * @return int|float |
|
255 | + * @throws EE_Error |
|
256 | + * @throws ReflectionException |
|
257 | + */ |
|
258 | + public function max() |
|
259 | + { |
|
260 | + $max = $this->get('FIN_max'); |
|
261 | + return $max > -1 ? $max : EE_INF; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @param int|float $max |
|
267 | + * @throws EE_Error |
|
268 | + * @throws ReflectionException |
|
269 | + */ |
|
270 | + public function setMax($max) |
|
271 | + { |
|
272 | + $this->set('FIN_max', $max); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Minimum numeric value or minimum characters allowed for form input answer. |
|
279 | + * |
|
280 | + * @return int|float |
|
281 | + * @throws EE_Error |
|
282 | + * @throws ReflectionException |
|
283 | + */ |
|
284 | + public function min() |
|
285 | + { |
|
286 | + return $this->get('FIN_min'); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @param int|float $min |
|
292 | + * @throws EE_Error |
|
293 | + * @throws ReflectionException |
|
294 | + */ |
|
295 | + public function setMin($min) |
|
296 | + { |
|
297 | + $this->set('FIN_min', $min); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
303 | + * |
|
304 | + * @return array |
|
305 | + * @throws EE_Error |
|
306 | + * @throws ReflectionException |
|
307 | + */ |
|
308 | + public function options(): ?array |
|
309 | + { |
|
310 | + return $this->get('FIN_options'); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param array $options |
|
316 | + * @throws EE_Error |
|
317 | + * @throws ReflectionException |
|
318 | + */ |
|
319 | + public function setOptions(array $options) |
|
320 | + { |
|
321 | + $this->set('FIN_options', $options); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Order in which form input appears in a form. |
|
328 | + * |
|
329 | + * @return int |
|
330 | + * @throws EE_Error |
|
331 | + * @throws ReflectionException |
|
332 | + */ |
|
333 | + public function order(): int |
|
334 | + { |
|
335 | + return $this->get('FIN_order'); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @param int $order |
|
341 | + * @throws EE_Error |
|
342 | + * @throws ReflectionException |
|
343 | + */ |
|
344 | + public function setOrder(int $order) |
|
345 | + { |
|
346 | + $this->set('FIN_order', $order); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * Example text displayed within an input to assist users with completing the form. |
|
352 | + * |
|
353 | + * @return string |
|
354 | + * @throws EE_Error |
|
355 | + * @throws ReflectionException |
|
356 | + */ |
|
357 | + public function placeholder():? string |
|
358 | + { |
|
359 | + return $this->get('FIN_placeholder'); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * @param string $placeholder |
|
365 | + * @throws EE_Error |
|
366 | + * @throws ReflectionException |
|
367 | + */ |
|
368 | + public function setPlaceholder(string $placeholder) |
|
369 | + { |
|
370 | + $this->set('FIN_placeholder', $placeholder); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Input label displayed on public forms, ie: the actual question text. |
|
376 | + * |
|
377 | + * @return string |
|
378 | + * @throws EE_Error |
|
379 | + * @throws ReflectionException |
|
380 | + */ |
|
381 | + public function publicLabel(): ?string |
|
382 | + { |
|
383 | + return $this->get('FIN_publicLabel'); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param string $publicLabel |
|
389 | + * @throws EE_Error |
|
390 | + * @throws ReflectionException |
|
391 | + */ |
|
392 | + public function setPublicLabel(string $publicLabel) |
|
393 | + { |
|
394 | + $this->set('FIN_publicLabel', $publicLabel); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * Whether or not the input must be supplied with a value in order to complete the form. |
|
400 | + * |
|
401 | + * @return bool |
|
402 | + * @throws EE_Error |
|
403 | + * @throws ReflectionException |
|
404 | + */ |
|
405 | + public function required(): ?bool |
|
406 | + { |
|
407 | + return $this->get('FIN_required'); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * @param bool $required |
|
413 | + * @throws EE_Error |
|
414 | + * @throws ReflectionException |
|
415 | + */ |
|
416 | + public function setRequired(bool $required) |
|
417 | + { |
|
418 | + $this->set('FIN_required', $required); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Custom validation text displayed alongside a required form input to assist users with completing the form. |
|
424 | + * |
|
425 | + * @return string |
|
426 | + * @throws EE_Error |
|
427 | + * @throws ReflectionException |
|
428 | + */ |
|
429 | + public function requiredText():? string |
|
430 | + { |
|
431 | + return $this->get('FIN_requiredText'); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $requiredText |
|
437 | + * @throws EE_Error |
|
438 | + * @throws ReflectionException |
|
439 | + */ |
|
440 | + public function setRequiredText(string $requiredText) |
|
441 | + { |
|
442 | + $this->set('FIN_requiredText', $requiredText); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * version of public label for use in identifiers |
|
448 | + * |
|
449 | + * @return string |
|
450 | + * @throws EE_Error |
|
451 | + * @throws ReflectionException |
|
452 | + */ |
|
453 | + public function slug(): ?string |
|
454 | + { |
|
455 | + return sanitize_title($this->publicLabel()); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
461 | + * Values correspond to the EEM_Form_Input::STATUS_* constants. |
|
462 | + * |
|
463 | + * @return string |
|
464 | + * @throws EE_Error |
|
465 | + * @throws ReflectionException |
|
466 | + */ |
|
467 | + public function status(): string |
|
468 | + { |
|
469 | + return $this->get('FIN_status'); |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
475 | + * Values correspond to the EEM_Form_Input::STATUS_* constants. |
|
476 | + * |
|
477 | + * @param string $status |
|
478 | + * @throws EE_Error |
|
479 | + * @throws ReflectionException |
|
480 | + */ |
|
481 | + public function setStatus(string $status) |
|
482 | + { |
|
483 | + $this->set('FIN_status', $status); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * Form input type. |
|
489 | + * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
490 | + * |
|
491 | + * @return string |
|
492 | + * @throws EE_Error |
|
493 | + * @throws ReflectionException |
|
494 | + */ |
|
495 | + public function type(): ?string |
|
496 | + { |
|
497 | + return $this->get('FIN_type'); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * @param string $type |
|
503 | + * @throws EE_Error |
|
504 | + * @throws ReflectionException |
|
505 | + */ |
|
506 | + public function setType(string $type) |
|
507 | + { |
|
508 | + $this->set('FIN_type', $type); |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * ID of the WP User that created this form input. |
|
514 | + * |
|
515 | + * @return int |
|
516 | + * @throws EE_Error |
|
517 | + * @throws ReflectionException |
|
518 | + */ |
|
519 | + public function wp_user(): int |
|
520 | + { |
|
521 | + return $this->get('FIN_wpUser'); |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * returns the id the wordpress user who created this question |
|
527 | + * |
|
528 | + * @param int $wp_user |
|
529 | + * @throws EE_Error |
|
530 | + * @throws ReflectionException |
|
531 | + */ |
|
532 | + public function setWpUser(int $wp_user) |
|
533 | + { |
|
534 | + $this->set('FIN_wpUser', $wp_user); |
|
535 | + } |
|
536 | 536 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @throws EE_Error |
85 | 85 | * @throws ReflectionException |
86 | 86 | */ |
87 | - public function adminLabel():? string |
|
87 | + public function adminLabel(): ? string |
|
88 | 88 | { |
89 | 89 | return $this->get('FIN_adminLabel'); |
90 | 90 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @throws EE_Error |
157 | 157 | * @throws ReflectionException |
158 | 158 | */ |
159 | - public function helpClass():? string |
|
159 | + public function helpClass(): ? string |
|
160 | 160 | { |
161 | 161 | return $this->get('FIN_helpClass'); |
162 | 162 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @throws EE_Error |
181 | 181 | * @throws ReflectionException |
182 | 182 | */ |
183 | - public function helpText():? string |
|
183 | + public function helpText(): ? string |
|
184 | 184 | { |
185 | 185 | return $this->get('FIN_helpText'); |
186 | 186 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @throws EE_Error |
205 | 205 | * @throws ReflectionException |
206 | 206 | */ |
207 | - public function htmlClass():? string |
|
207 | + public function htmlClass(): ? string |
|
208 | 208 | { |
209 | 209 | return $this->get('FIN_htmlClass'); |
210 | 210 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @throws EE_Error |
231 | 231 | * @throws ReflectionException |
232 | 232 | */ |
233 | - public function mapsTo():? string |
|
233 | + public function mapsTo(): ? string |
|
234 | 234 | { |
235 | 235 | return $this->get('FIN_mapsTo'); |
236 | 236 | } |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * @throws EE_Error |
355 | 355 | * @throws ReflectionException |
356 | 356 | */ |
357 | - public function placeholder():? string |
|
357 | + public function placeholder(): ? string |
|
358 | 358 | { |
359 | 359 | return $this->get('FIN_placeholder'); |
360 | 360 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @throws EE_Error |
427 | 427 | * @throws ReflectionException |
428 | 428 | */ |
429 | - public function requiredText():? string |
|
429 | + public function requiredText(): ? string |
|
430 | 430 | { |
431 | 431 | return $this->get('FIN_requiredText'); |
432 | 432 | } |