@@ -16,130 +16,130 @@ |
||
16 | 16 | */ |
17 | 17 | class VenueConnectionResolver extends AbstractConnectionResolver |
18 | 18 | { |
19 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
20 | - public function get_loader_name(): string |
|
21 | - { |
|
22 | - return 'espresso_venue'; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return EEM_Venue |
|
27 | - * @throws EE_Error |
|
28 | - * @throws InvalidArgumentException |
|
29 | - * @throws InvalidDataTypeException |
|
30 | - * @throws InvalidInterfaceException |
|
31 | - * @throws ReflectionException |
|
32 | - */ |
|
33 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
34 | - public function get_query(): EEM_Venue |
|
35 | - { |
|
36 | - return EEM_Venue::instance(); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Return an array of item IDs from the query |
|
42 | - * |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | - public function get_ids(): array |
|
47 | - { |
|
48 | - $results = $this->query->get_col($this->query_args); |
|
49 | - |
|
50 | - return ! empty($results) ? $results : []; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
56 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
57 | - * handle batch resolution of the posts. |
|
58 | - * |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
62 | - public function get_query_args(): array |
|
63 | - { |
|
64 | - $where_params = []; |
|
65 | - $query_args = []; |
|
66 | - |
|
67 | - $query_args['limit'] = $this->getLimit(); |
|
68 | - |
|
69 | - // Avoid multiple entries by join. |
|
70 | - $query_args['group_by'] = 'VNU_ID'; |
|
71 | - |
|
72 | - $query_args['default_where_conditions'] = 'minimum'; |
|
73 | - |
|
74 | - /** |
|
75 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
76 | - */ |
|
77 | - $input_fields = []; |
|
78 | - if (! empty($this->args['where'])) { |
|
79 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
84 | - * For example, if we're querying for datetime as a field of event query, this will automatically |
|
85 | - * set the query to pull datetimes that belong to that event. |
|
86 | - * We can set more cases for other source types. |
|
87 | - */ |
|
88 | - if (is_object($this->source)) { |
|
89 | - switch (true) { |
|
90 | - // Assumed to be an event |
|
91 | - case $this->source instanceof Post: |
|
92 | - $where_params['Event.EVT_ID'] = $this->source->ID; |
|
93 | - break; |
|
94 | - case $this->source instanceof EE_Event: |
|
95 | - $where_params['Event.EVT_ID'] = $this->source->ID(); |
|
96 | - break; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Merge the input_fields with the default query_args |
|
102 | - */ |
|
103 | - if (! empty($input_fields)) { |
|
104 | - $where_params = array_merge($where_params, $input_fields); |
|
105 | - } |
|
106 | - |
|
107 | - [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'VNU_ID'); |
|
108 | - |
|
109 | - $where_params = apply_filters( |
|
110 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__venue_where_params', |
|
111 | - $where_params, |
|
112 | - $this->source, |
|
113 | - $this->args |
|
114 | - ); |
|
115 | - |
|
116 | - $query_args[] = $where_params; |
|
117 | - |
|
118 | - /** |
|
119 | - * Return the $query_args |
|
120 | - */ |
|
121 | - return apply_filters( |
|
122 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__venue_query_args', |
|
123 | - $query_args, |
|
124 | - $this->source, |
|
125 | - $this->args |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
132 | - * friendly keys. |
|
133 | - * |
|
134 | - * @param array $where_args |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function sanitizeInputFields(array $where_args): array |
|
138 | - { |
|
139 | - return $this->sanitizeWhereArgsForInputFields( |
|
140 | - $where_args, |
|
141 | - [], |
|
142 | - [] |
|
143 | - ); |
|
144 | - } |
|
19 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
20 | + public function get_loader_name(): string |
|
21 | + { |
|
22 | + return 'espresso_venue'; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return EEM_Venue |
|
27 | + * @throws EE_Error |
|
28 | + * @throws InvalidArgumentException |
|
29 | + * @throws InvalidDataTypeException |
|
30 | + * @throws InvalidInterfaceException |
|
31 | + * @throws ReflectionException |
|
32 | + */ |
|
33 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
34 | + public function get_query(): EEM_Venue |
|
35 | + { |
|
36 | + return EEM_Venue::instance(); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Return an array of item IDs from the query |
|
42 | + * |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | + public function get_ids(): array |
|
47 | + { |
|
48 | + $results = $this->query->get_col($this->query_args); |
|
49 | + |
|
50 | + return ! empty($results) ? $results : []; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
56 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
57 | + * handle batch resolution of the posts. |
|
58 | + * |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
62 | + public function get_query_args(): array |
|
63 | + { |
|
64 | + $where_params = []; |
|
65 | + $query_args = []; |
|
66 | + |
|
67 | + $query_args['limit'] = $this->getLimit(); |
|
68 | + |
|
69 | + // Avoid multiple entries by join. |
|
70 | + $query_args['group_by'] = 'VNU_ID'; |
|
71 | + |
|
72 | + $query_args['default_where_conditions'] = 'minimum'; |
|
73 | + |
|
74 | + /** |
|
75 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
76 | + */ |
|
77 | + $input_fields = []; |
|
78 | + if (! empty($this->args['where'])) { |
|
79 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
84 | + * For example, if we're querying for datetime as a field of event query, this will automatically |
|
85 | + * set the query to pull datetimes that belong to that event. |
|
86 | + * We can set more cases for other source types. |
|
87 | + */ |
|
88 | + if (is_object($this->source)) { |
|
89 | + switch (true) { |
|
90 | + // Assumed to be an event |
|
91 | + case $this->source instanceof Post: |
|
92 | + $where_params['Event.EVT_ID'] = $this->source->ID; |
|
93 | + break; |
|
94 | + case $this->source instanceof EE_Event: |
|
95 | + $where_params['Event.EVT_ID'] = $this->source->ID(); |
|
96 | + break; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Merge the input_fields with the default query_args |
|
102 | + */ |
|
103 | + if (! empty($input_fields)) { |
|
104 | + $where_params = array_merge($where_params, $input_fields); |
|
105 | + } |
|
106 | + |
|
107 | + [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'VNU_ID'); |
|
108 | + |
|
109 | + $where_params = apply_filters( |
|
110 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__venue_where_params', |
|
111 | + $where_params, |
|
112 | + $this->source, |
|
113 | + $this->args |
|
114 | + ); |
|
115 | + |
|
116 | + $query_args[] = $where_params; |
|
117 | + |
|
118 | + /** |
|
119 | + * Return the $query_args |
|
120 | + */ |
|
121 | + return apply_filters( |
|
122 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__venue_query_args', |
|
123 | + $query_args, |
|
124 | + $this->source, |
|
125 | + $this->args |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
132 | + * friendly keys. |
|
133 | + * |
|
134 | + * @param array $where_args |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function sanitizeInputFields(array $where_args): array |
|
138 | + { |
|
139 | + return $this->sanitizeWhereArgsForInputFields( |
|
140 | + $where_args, |
|
141 | + [], |
|
142 | + [] |
|
143 | + ); |
|
144 | + } |
|
145 | 145 | } |
@@ -14,79 +14,79 @@ |
||
14 | 14 | */ |
15 | 15 | class PriceTypeConnectionResolver extends AbstractConnectionResolver |
16 | 16 | { |
17 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | - public function get_loader_name(): string |
|
19 | - { |
|
20 | - return 'espresso_priceType'; |
|
21 | - } |
|
17 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | + public function get_loader_name(): string |
|
19 | + { |
|
20 | + return 'espresso_priceType'; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return EEM_Price_Type |
|
25 | - * @throws EE_Error |
|
26 | - * @throws InvalidArgumentException |
|
27 | - * @throws InvalidDataTypeException |
|
28 | - * @throws InvalidInterfaceException |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | - public function get_query(): EEM_Price_Type |
|
33 | - { |
|
34 | - return EEM_Price_Type::instance(); |
|
35 | - } |
|
23 | + /** |
|
24 | + * @return EEM_Price_Type |
|
25 | + * @throws EE_Error |
|
26 | + * @throws InvalidArgumentException |
|
27 | + * @throws InvalidDataTypeException |
|
28 | + * @throws InvalidInterfaceException |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | + public function get_query(): EEM_Price_Type |
|
33 | + { |
|
34 | + return EEM_Price_Type::instance(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Return an array of item IDs from the query |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | - public function get_ids(): array |
|
45 | - { |
|
46 | - $results = $this->query->get_col($this->query_args); |
|
38 | + /** |
|
39 | + * Return an array of item IDs from the query |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | + public function get_ids(): array |
|
45 | + { |
|
46 | + $results = $this->query->get_col($this->query_args); |
|
47 | 47 | |
48 | - return ! empty($results) ? $results : []; |
|
49 | - } |
|
48 | + return ! empty($results) ? $results : []; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
54 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
55 | - * handle batch resolution of the posts. |
|
56 | - * |
|
57 | - * @return array |
|
58 | - * @throws InvalidArgumentException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - * @throws InvalidInterfaceException |
|
61 | - */ |
|
62 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
63 | - public function get_query_args(): array |
|
64 | - { |
|
65 | - $where_params = []; |
|
66 | - $query_args = []; |
|
52 | + /** |
|
53 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
54 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
55 | + * handle batch resolution of the posts. |
|
56 | + * |
|
57 | + * @return array |
|
58 | + * @throws InvalidArgumentException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + * @throws InvalidInterfaceException |
|
61 | + */ |
|
62 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
63 | + public function get_query_args(): array |
|
64 | + { |
|
65 | + $where_params = []; |
|
66 | + $query_args = []; |
|
67 | 67 | |
68 | - $query_args['limit'] = $this->getLimit(); |
|
68 | + $query_args['limit'] = $this->getLimit(); |
|
69 | 69 | |
70 | - // Avoid multiple entries by join. |
|
71 | - $query_args['group_by'] = 'PRT_ID'; |
|
70 | + // Avoid multiple entries by join. |
|
71 | + $query_args['group_by'] = 'PRT_ID'; |
|
72 | 72 | |
73 | - $where_params = apply_filters( |
|
74 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_where_params', |
|
75 | - $where_params, |
|
76 | - $this->source, |
|
77 | - $this->args |
|
78 | - ); |
|
73 | + $where_params = apply_filters( |
|
74 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_where_params', |
|
75 | + $where_params, |
|
76 | + $this->source, |
|
77 | + $this->args |
|
78 | + ); |
|
79 | 79 | |
80 | - $query_args[] = $where_params; |
|
80 | + $query_args[] = $where_params; |
|
81 | 81 | |
82 | - /** |
|
83 | - * Return the $query_args |
|
84 | - */ |
|
85 | - return apply_filters( |
|
86 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_query_args', |
|
87 | - $query_args, |
|
88 | - $this->source, |
|
89 | - $this->args |
|
90 | - ); |
|
91 | - } |
|
82 | + /** |
|
83 | + * Return the $query_args |
|
84 | + */ |
|
85 | + return apply_filters( |
|
86 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_query_args', |
|
87 | + $query_args, |
|
88 | + $this->source, |
|
89 | + $this->args |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | } |
@@ -19,193 +19,193 @@ |
||
19 | 19 | */ |
20 | 20 | class DatetimeConnectionResolver extends AbstractConnectionResolver |
21 | 21 | { |
22 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | - public function get_loader_name(): string |
|
24 | - { |
|
25 | - return 'espresso_datetime'; |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @return EEM_Datetime |
|
30 | - * @throws EE_Error |
|
31 | - * @throws InvalidArgumentException |
|
32 | - * @throws InvalidDataTypeException |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - * @throws ReflectionException |
|
35 | - */ |
|
36 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
37 | - public function get_query(): EEM_Datetime |
|
38 | - { |
|
39 | - return EEM_Datetime::instance(); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Return an array of item IDs from the query |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
48 | - public function get_ids(): array |
|
49 | - { |
|
50 | - $results = $this->query->get_col($this->query_args); |
|
51 | - |
|
52 | - return ! empty($results) ? $results : []; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
57 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
58 | - * handle batch resolution of the posts. |
|
59 | - * |
|
60 | - * @return array |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
68 | - public function get_query_args(): array |
|
69 | - { |
|
70 | - $where_params = ['DTT_deleted' => ['IN', [true, false]]]; |
|
71 | - $query_args = []; |
|
72 | - |
|
73 | - $query_args['limit'] = $this->getLimit(); |
|
74 | - |
|
75 | - // Avoid multiple entries by join. |
|
76 | - $query_args['group_by'] = 'DTT_ID'; |
|
77 | - |
|
78 | - $query_args['default_where_conditions'] = 'minimum'; |
|
79 | - |
|
80 | - /** |
|
81 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
82 | - */ |
|
83 | - $input_fields = []; |
|
84 | - if (! empty($this->args['where'])) { |
|
85 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
86 | - |
|
87 | - // Use the proper operator. |
|
88 | - if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) { |
|
89 | - $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']]; |
|
90 | - } |
|
91 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
92 | - $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
98 | - * |
|
99 | - * For example, if we're querying for datetime as a field of event query, this will automatically |
|
100 | - * set the query to pull datetimes that belong to that event. |
|
101 | - * We can set more cases for other source types. |
|
102 | - */ |
|
103 | - if (is_object($this->source)) { |
|
104 | - switch (true) { |
|
105 | - // It's surely an event |
|
106 | - case $this->source instanceof Post: |
|
107 | - $where_params['EVT_ID'] = $this->source->ID; |
|
108 | - break; |
|
109 | - case $this->source instanceof EE_Event: |
|
110 | - $where_params['EVT_ID'] = $this->source->ID(); |
|
111 | - break; |
|
112 | - case $this->source instanceof EE_Ticket: |
|
113 | - $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
114 | - break; |
|
115 | - case $this->source instanceof EE_Checkin: |
|
116 | - $where_params['Checkin.CHK_ID'] = $this->source->ID(); |
|
117 | - break; |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Merge the input_fields with the default query_args |
|
123 | - */ |
|
124 | - if (! empty($input_fields)) { |
|
125 | - $where_params = array_merge($where_params, $input_fields); |
|
126 | - } |
|
127 | - |
|
128 | - [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID'); |
|
129 | - |
|
130 | - $search = isset($this->args['where']) ? $this->getSearchKeywords($this->args['where']) : ''; |
|
131 | - |
|
132 | - if (! empty($search)) { |
|
133 | - // use OR operator to search in any of the fields |
|
134 | - $where_params['OR'] = array( |
|
135 | - 'DTT_name' => array('LIKE', '%' . $search . '%'), |
|
136 | - 'DTT_description' => array('LIKE', '%' . $search . '%'), |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - if (! empty($this->args['where']['upcoming'])) { |
|
141 | - $where_params['DTT_EVT_start'] = array( |
|
142 | - '>', |
|
143 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
144 | - ); |
|
145 | - } |
|
146 | - |
|
147 | - if (! empty($this->args['where']['active'])) { |
|
148 | - $where_params['DTT_EVT_start'] = array( |
|
149 | - '<', |
|
150 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
151 | - ); |
|
152 | - $where_params['DTT_EVT_end'] = array( |
|
153 | - '>', |
|
154 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - if (! empty($this->args['where']['expired'])) { |
|
159 | - $where_params['DTT_EVT_end'] = array( |
|
160 | - '<', |
|
161 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - $where_params = apply_filters( |
|
166 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__datetime_where_params', |
|
167 | - $where_params, |
|
168 | - $this->source, |
|
169 | - $this->args |
|
170 | - ); |
|
171 | - |
|
172 | - $query_args[] = $where_params; |
|
173 | - |
|
174 | - /** |
|
175 | - * Return the $query_args |
|
176 | - */ |
|
177 | - return apply_filters( |
|
178 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__datetime_query_args', |
|
179 | - $query_args, |
|
180 | - $this->source, |
|
181 | - $this->args |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
188 | - * friendly keys. |
|
189 | - * |
|
190 | - * @param array $where_args |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function sanitizeInputFields(array $where_args): array |
|
194 | - { |
|
195 | - $arg_mapping = [ |
|
196 | - 'event' => 'EVT_ID', |
|
197 | - 'eventIn' => 'EVT_ID', |
|
198 | - 'eventId' => 'EVT_ID', |
|
199 | - 'eventIdIn' => 'EVT_ID', |
|
200 | - 'ticket' => 'Ticket.TKT_ID', |
|
201 | - 'ticketIn' => 'Ticket.TKT_ID', |
|
202 | - 'ticketId' => 'Ticket.TKT_ID', |
|
203 | - 'ticketIdIn' => 'Ticket.TKT_ID', |
|
204 | - ]; |
|
205 | - return $this->sanitizeWhereArgsForInputFields( |
|
206 | - $where_args, |
|
207 | - $arg_mapping, |
|
208 | - ['event', 'eventIn', 'ticket', 'ticketIn'] |
|
209 | - ); |
|
210 | - } |
|
22 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | + public function get_loader_name(): string |
|
24 | + { |
|
25 | + return 'espresso_datetime'; |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @return EEM_Datetime |
|
30 | + * @throws EE_Error |
|
31 | + * @throws InvalidArgumentException |
|
32 | + * @throws InvalidDataTypeException |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + * @throws ReflectionException |
|
35 | + */ |
|
36 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
37 | + public function get_query(): EEM_Datetime |
|
38 | + { |
|
39 | + return EEM_Datetime::instance(); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Return an array of item IDs from the query |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
48 | + public function get_ids(): array |
|
49 | + { |
|
50 | + $results = $this->query->get_col($this->query_args); |
|
51 | + |
|
52 | + return ! empty($results) ? $results : []; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
57 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
58 | + * handle batch resolution of the posts. |
|
59 | + * |
|
60 | + * @return array |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
68 | + public function get_query_args(): array |
|
69 | + { |
|
70 | + $where_params = ['DTT_deleted' => ['IN', [true, false]]]; |
|
71 | + $query_args = []; |
|
72 | + |
|
73 | + $query_args['limit'] = $this->getLimit(); |
|
74 | + |
|
75 | + // Avoid multiple entries by join. |
|
76 | + $query_args['group_by'] = 'DTT_ID'; |
|
77 | + |
|
78 | + $query_args['default_where_conditions'] = 'minimum'; |
|
79 | + |
|
80 | + /** |
|
81 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
82 | + */ |
|
83 | + $input_fields = []; |
|
84 | + if (! empty($this->args['where'])) { |
|
85 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
86 | + |
|
87 | + // Use the proper operator. |
|
88 | + if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) { |
|
89 | + $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']]; |
|
90 | + } |
|
91 | + if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
92 | + $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
98 | + * |
|
99 | + * For example, if we're querying for datetime as a field of event query, this will automatically |
|
100 | + * set the query to pull datetimes that belong to that event. |
|
101 | + * We can set more cases for other source types. |
|
102 | + */ |
|
103 | + if (is_object($this->source)) { |
|
104 | + switch (true) { |
|
105 | + // It's surely an event |
|
106 | + case $this->source instanceof Post: |
|
107 | + $where_params['EVT_ID'] = $this->source->ID; |
|
108 | + break; |
|
109 | + case $this->source instanceof EE_Event: |
|
110 | + $where_params['EVT_ID'] = $this->source->ID(); |
|
111 | + break; |
|
112 | + case $this->source instanceof EE_Ticket: |
|
113 | + $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
114 | + break; |
|
115 | + case $this->source instanceof EE_Checkin: |
|
116 | + $where_params['Checkin.CHK_ID'] = $this->source->ID(); |
|
117 | + break; |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Merge the input_fields with the default query_args |
|
123 | + */ |
|
124 | + if (! empty($input_fields)) { |
|
125 | + $where_params = array_merge($where_params, $input_fields); |
|
126 | + } |
|
127 | + |
|
128 | + [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID'); |
|
129 | + |
|
130 | + $search = isset($this->args['where']) ? $this->getSearchKeywords($this->args['where']) : ''; |
|
131 | + |
|
132 | + if (! empty($search)) { |
|
133 | + // use OR operator to search in any of the fields |
|
134 | + $where_params['OR'] = array( |
|
135 | + 'DTT_name' => array('LIKE', '%' . $search . '%'), |
|
136 | + 'DTT_description' => array('LIKE', '%' . $search . '%'), |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + if (! empty($this->args['where']['upcoming'])) { |
|
141 | + $where_params['DTT_EVT_start'] = array( |
|
142 | + '>', |
|
143 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
144 | + ); |
|
145 | + } |
|
146 | + |
|
147 | + if (! empty($this->args['where']['active'])) { |
|
148 | + $where_params['DTT_EVT_start'] = array( |
|
149 | + '<', |
|
150 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
151 | + ); |
|
152 | + $where_params['DTT_EVT_end'] = array( |
|
153 | + '>', |
|
154 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + if (! empty($this->args['where']['expired'])) { |
|
159 | + $where_params['DTT_EVT_end'] = array( |
|
160 | + '<', |
|
161 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + $where_params = apply_filters( |
|
166 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__datetime_where_params', |
|
167 | + $where_params, |
|
168 | + $this->source, |
|
169 | + $this->args |
|
170 | + ); |
|
171 | + |
|
172 | + $query_args[] = $where_params; |
|
173 | + |
|
174 | + /** |
|
175 | + * Return the $query_args |
|
176 | + */ |
|
177 | + return apply_filters( |
|
178 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__datetime_query_args', |
|
179 | + $query_args, |
|
180 | + $this->source, |
|
181 | + $this->args |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
188 | + * friendly keys. |
|
189 | + * |
|
190 | + * @param array $where_args |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function sanitizeInputFields(array $where_args): array |
|
194 | + { |
|
195 | + $arg_mapping = [ |
|
196 | + 'event' => 'EVT_ID', |
|
197 | + 'eventIn' => 'EVT_ID', |
|
198 | + 'eventId' => 'EVT_ID', |
|
199 | + 'eventIdIn' => 'EVT_ID', |
|
200 | + 'ticket' => 'Ticket.TKT_ID', |
|
201 | + 'ticketIn' => 'Ticket.TKT_ID', |
|
202 | + 'ticketId' => 'Ticket.TKT_ID', |
|
203 | + 'ticketIdIn' => 'Ticket.TKT_ID', |
|
204 | + ]; |
|
205 | + return $this->sanitizeWhereArgsForInputFields( |
|
206 | + $where_args, |
|
207 | + $arg_mapping, |
|
208 | + ['event', 'eventIn', 'ticket', 'ticketIn'] |
|
209 | + ); |
|
210 | + } |
|
211 | 211 | } |
@@ -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 | } |
@@ -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); |
@@ -5,152 +5,152 @@ |
||
5 | 5 | class EE_Form_Submission extends EE_Base_Class |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @param array $props_n_values |
|
10 | - * @return EE_Form_Submission |
|
11 | - * @throws EE_Error |
|
12 | - * @throws ReflectionException |
|
13 | - */ |
|
14 | - public static function new_instance(array $props_n_values = []): EE_Form_Submission |
|
15 | - { |
|
16 | - $props_n_values['FSB_submitted'] = new DateTime(); |
|
17 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
18 | - return $has_object ?: new self($props_n_values); |
|
19 | - } |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param array $props_n_values |
|
24 | - * @return EE_Form_Submission |
|
25 | - * @throws EE_Error |
|
26 | - * @throws ReflectionException |
|
27 | - */ |
|
28 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Submission |
|
29 | - { |
|
30 | - return new self($props_n_values, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Form Section UUID (universally unique identifier) |
|
36 | - * |
|
37 | - * @return string |
|
38 | - * @throws EE_Error |
|
39 | - * @throws ReflectionException |
|
40 | - */ |
|
41 | - public function UUID(): string |
|
42 | - { |
|
43 | - return $this->get('FSB_UUID'); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param string $UUID |
|
49 | - * @throws EE_Error |
|
50 | - * @throws ReflectionException |
|
51 | - */ |
|
52 | - public function setUUID(string $UUID) |
|
53 | - { |
|
54 | - $this->set('FSB_UUID', $UUID); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * UUID or ID of related entity this form submission belongs to. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - * @throws EE_Error |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public function formSection(): string |
|
66 | - { |
|
67 | - return $this->get('FSC_UUID'); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $form_section_UUID |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public function setFormSection(string $form_section_UUID) |
|
77 | - { |
|
78 | - $this->set('FSC_UUID', $form_section_UUID); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns the related EE_Transaction this form submission belongs to. |
|
84 | - * |
|
85 | - * @return EE_Transaction |
|
86 | - * @throws EE_Error |
|
87 | - * @throws EntityNotFoundException |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - public function transaction(): EE_Transaction |
|
91 | - { |
|
92 | - $transaction = $this->get_first_related('Transaction'); |
|
93 | - if (! $transaction instanceof EE_Transaction) { |
|
94 | - throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
|
95 | - } |
|
96 | - return $transaction; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return int |
|
102 | - * @throws EE_Error |
|
103 | - * @throws ReflectionException |
|
104 | - */ |
|
105 | - public function transactionID(): int |
|
106 | - { |
|
107 | - return $this->get('TXN_ID'); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param int $TXN_ID |
|
113 | - * @throws EE_Error |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public function setTransactionID(int $TXN_ID = 0) |
|
117 | - { |
|
118 | - $this->set('TXN_ID', $TXN_ID); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return mixed |
|
124 | - * @throws EE_Error |
|
125 | - * @throws ReflectionException |
|
126 | - */ |
|
127 | - public function data() |
|
128 | - { |
|
129 | - return $this->get('FSB_data'); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param array|string $data |
|
135 | - * @throws EE_Error |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function setData($data) |
|
139 | - { |
|
140 | - $this->set('FSB_data', $data); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param bool $raw |
|
146 | - * @return int |
|
147 | - * @throws EE_Error |
|
148 | - * @throws ReflectionException |
|
149 | - */ |
|
150 | - public function submitted(bool $raw = false): int |
|
151 | - { |
|
152 | - return $raw |
|
153 | - ? $this->get_raw('FSB_submitted') |
|
154 | - : $this->get('FSB_submitted'); |
|
155 | - } |
|
8 | + /** |
|
9 | + * @param array $props_n_values |
|
10 | + * @return EE_Form_Submission |
|
11 | + * @throws EE_Error |
|
12 | + * @throws ReflectionException |
|
13 | + */ |
|
14 | + public static function new_instance(array $props_n_values = []): EE_Form_Submission |
|
15 | + { |
|
16 | + $props_n_values['FSB_submitted'] = new DateTime(); |
|
17 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
18 | + return $has_object ?: new self($props_n_values); |
|
19 | + } |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param array $props_n_values |
|
24 | + * @return EE_Form_Submission |
|
25 | + * @throws EE_Error |
|
26 | + * @throws ReflectionException |
|
27 | + */ |
|
28 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Submission |
|
29 | + { |
|
30 | + return new self($props_n_values, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Form Section UUID (universally unique identifier) |
|
36 | + * |
|
37 | + * @return string |
|
38 | + * @throws EE_Error |
|
39 | + * @throws ReflectionException |
|
40 | + */ |
|
41 | + public function UUID(): string |
|
42 | + { |
|
43 | + return $this->get('FSB_UUID'); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param string $UUID |
|
49 | + * @throws EE_Error |
|
50 | + * @throws ReflectionException |
|
51 | + */ |
|
52 | + public function setUUID(string $UUID) |
|
53 | + { |
|
54 | + $this->set('FSB_UUID', $UUID); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * UUID or ID of related entity this form submission belongs to. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + * @throws EE_Error |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public function formSection(): string |
|
66 | + { |
|
67 | + return $this->get('FSC_UUID'); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $form_section_UUID |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public function setFormSection(string $form_section_UUID) |
|
77 | + { |
|
78 | + $this->set('FSC_UUID', $form_section_UUID); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns the related EE_Transaction this form submission belongs to. |
|
84 | + * |
|
85 | + * @return EE_Transaction |
|
86 | + * @throws EE_Error |
|
87 | + * @throws EntityNotFoundException |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + public function transaction(): EE_Transaction |
|
91 | + { |
|
92 | + $transaction = $this->get_first_related('Transaction'); |
|
93 | + if (! $transaction instanceof EE_Transaction) { |
|
94 | + throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
|
95 | + } |
|
96 | + return $transaction; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return int |
|
102 | + * @throws EE_Error |
|
103 | + * @throws ReflectionException |
|
104 | + */ |
|
105 | + public function transactionID(): int |
|
106 | + { |
|
107 | + return $this->get('TXN_ID'); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param int $TXN_ID |
|
113 | + * @throws EE_Error |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public function setTransactionID(int $TXN_ID = 0) |
|
117 | + { |
|
118 | + $this->set('TXN_ID', $TXN_ID); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return mixed |
|
124 | + * @throws EE_Error |
|
125 | + * @throws ReflectionException |
|
126 | + */ |
|
127 | + public function data() |
|
128 | + { |
|
129 | + return $this->get('FSB_data'); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param array|string $data |
|
135 | + * @throws EE_Error |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function setData($data) |
|
139 | + { |
|
140 | + $this->set('FSB_data', $data); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param bool $raw |
|
146 | + * @return int |
|
147 | + * @throws EE_Error |
|
148 | + * @throws ReflectionException |
|
149 | + */ |
|
150 | + public function submitted(bool $raw = false): int |
|
151 | + { |
|
152 | + return $raw |
|
153 | + ? $this->get_raw('FSB_submitted') |
|
154 | + : $this->get('FSB_submitted'); |
|
155 | + } |
|
156 | 156 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | public function transaction(): EE_Transaction |
91 | 91 | { |
92 | 92 | $transaction = $this->get_first_related('Transaction'); |
93 | - if (! $transaction instanceof EE_Transaction) { |
|
93 | + if ( ! $transaction instanceof EE_Transaction) { |
|
94 | 94 | throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
95 | 95 | } |
96 | 96 | return $transaction; |