@@ -76,22 +76,22 @@ discard block |
||
76 | 76 | public function getModelSchemaForFields(array $model_fields, array $schema) |
77 | 77 | { |
78 | 78 | foreach ($model_fields as $field => $model_field) { |
79 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
79 | + if ( ! $model_field instanceof EE_Model_Field_Base) { |
|
80 | 80 | continue; |
81 | 81 | } |
82 | - $schema['properties'][ $field ] = $model_field->getSchema(); |
|
82 | + $schema['properties'][$field] = $model_field->getSchema(); |
|
83 | 83 | |
84 | 84 | // if this is a primary key field add the primary key item |
85 | 85 | if ($model_field instanceof EE_Primary_Key_Field_Base) { |
86 | - $schema['properties'][ $field ]['primary_key'] = true; |
|
86 | + $schema['properties'][$field]['primary_key'] = true; |
|
87 | 87 | if ($model_field instanceof EE_Primary_Key_Int_Field) { |
88 | - $schema['properties'][ $field ]['readonly'] = true; |
|
88 | + $schema['properties'][$field]['readonly'] = true; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | 92 | // if this is a foreign key field add the foreign key item |
93 | 93 | if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
94 | - $schema['properties'][ $field ]['foreign_key'] = array( |
|
94 | + $schema['properties'][$field]['foreign_key'] = array( |
|
95 | 95 | 'description' => esc_html__( |
96 | 96 | 'This is a foreign key the points to the given models.', |
97 | 97 | 'event_espresso' |
@@ -115,18 +115,18 @@ discard block |
||
115 | 115 | public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
116 | 116 | { |
117 | 117 | foreach ($relations_on_model as $model_name => $relation) { |
118 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
118 | + if ( ! $relation instanceof EE_Model_Relation_Base) { |
|
119 | 119 | continue; |
120 | 120 | } |
121 | 121 | $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
122 | 122 | ? strtolower($model_name) |
123 | 123 | : EEH_Inflector::pluralize_and_lower($model_name); |
124 | - $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
125 | - $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
124 | + $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
125 | + $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
126 | 126 | |
127 | 127 | // links schema |
128 | - $links_key = 'https://api.eventespresso.com/' . strtolower($model_name); |
|
129 | - $schema['properties']['_links']['properties'][ $links_key ] = array( |
|
128 | + $links_key = 'https://api.eventespresso.com/'.strtolower($model_name); |
|
129 | + $schema['properties']['_links']['properties'][$links_key] = array( |
|
130 | 130 | 'description' => esc_html__( |
131 | 131 | 'Array of objects describing the link(s) for this relation resource.', |
132 | 132 | 'event_espresso' |
@@ -24,256 +24,256 @@ |
||
24 | 24 | */ |
25 | 25 | class JsonModelSchema |
26 | 26 | { |
27 | - /** |
|
28 | - * @var EEM_Base |
|
29 | - */ |
|
30 | - protected $model; |
|
27 | + /** |
|
28 | + * @var EEM_Base |
|
29 | + */ |
|
30 | + protected $model; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var CalculatedModelFields |
|
34 | - */ |
|
35 | - protected $fields_calculator; |
|
32 | + /** |
|
33 | + * @var CalculatedModelFields |
|
34 | + */ |
|
35 | + protected $fields_calculator; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * JsonModelSchema constructor. |
|
40 | - * |
|
41 | - * @param EEM_Base $model |
|
42 | - * @param CalculatedModelFields $fields_calculator |
|
43 | - */ |
|
44 | - public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator) |
|
45 | - { |
|
46 | - $this->model = $model; |
|
47 | - $this->fields_calculator = $fields_calculator; |
|
48 | - } |
|
38 | + /** |
|
39 | + * JsonModelSchema constructor. |
|
40 | + * |
|
41 | + * @param EEM_Base $model |
|
42 | + * @param CalculatedModelFields $fields_calculator |
|
43 | + */ |
|
44 | + public function __construct(EEM_Base $model, CalculatedModelFields $fields_calculator) |
|
45 | + { |
|
46 | + $this->model = $model; |
|
47 | + $this->fields_calculator = $fields_calculator; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * Return the schema for a given model from a given model. |
|
53 | - * |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - public function getModelSchema() |
|
57 | - { |
|
58 | - return $this->getModelSchemaForRelations( |
|
59 | - $this->model->relation_settings(), |
|
60 | - $this->getModelSchemaForFields( |
|
61 | - $this->model->field_settings(), |
|
62 | - $this->getInitialSchemaStructure() |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
51 | + /** |
|
52 | + * Return the schema for a given model from a given model. |
|
53 | + * |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + public function getModelSchema() |
|
57 | + { |
|
58 | + return $this->getModelSchemaForRelations( |
|
59 | + $this->model->relation_settings(), |
|
60 | + $this->getModelSchemaForFields( |
|
61 | + $this->model->field_settings(), |
|
62 | + $this->getInitialSchemaStructure() |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Get the schema for a given set of model fields. |
|
70 | - * |
|
71 | - * @param EE_Model_Field_Base[] $model_fields |
|
72 | - * @param array $schema |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function getModelSchemaForFields(array $model_fields, array $schema) |
|
76 | - { |
|
77 | - foreach ($model_fields as $field => $model_field) { |
|
78 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - $schema['properties'][ $field ] = $model_field->getSchema(); |
|
68 | + /** |
|
69 | + * Get the schema for a given set of model fields. |
|
70 | + * |
|
71 | + * @param EE_Model_Field_Base[] $model_fields |
|
72 | + * @param array $schema |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function getModelSchemaForFields(array $model_fields, array $schema) |
|
76 | + { |
|
77 | + foreach ($model_fields as $field => $model_field) { |
|
78 | + if (! $model_field instanceof EE_Model_Field_Base) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + $schema['properties'][ $field ] = $model_field->getSchema(); |
|
82 | 82 | |
83 | - // if this is a primary key field add the primary key item |
|
84 | - if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
85 | - $schema['properties'][ $field ]['primary_key'] = true; |
|
86 | - if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
87 | - $schema['properties'][ $field ]['readonly'] = true; |
|
88 | - } |
|
89 | - } |
|
83 | + // if this is a primary key field add the primary key item |
|
84 | + if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
85 | + $schema['properties'][ $field ]['primary_key'] = true; |
|
86 | + if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
87 | + $schema['properties'][ $field ]['readonly'] = true; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - // if this is a foreign key field add the foreign key item |
|
92 | - if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
93 | - $schema['properties'][ $field ]['foreign_key'] = array( |
|
94 | - 'description' => esc_html__( |
|
95 | - 'This is a foreign key the points to the given models.', |
|
96 | - 'event_espresso' |
|
97 | - ), |
|
98 | - 'type' => 'array', |
|
99 | - 'enum' => $model_field->get_model_class_names_pointed_to(), |
|
100 | - ); |
|
101 | - } |
|
102 | - } |
|
103 | - return $schema; |
|
104 | - } |
|
91 | + // if this is a foreign key field add the foreign key item |
|
92 | + if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
93 | + $schema['properties'][ $field ]['foreign_key'] = array( |
|
94 | + 'description' => esc_html__( |
|
95 | + 'This is a foreign key the points to the given models.', |
|
96 | + 'event_espresso' |
|
97 | + ), |
|
98 | + 'type' => 'array', |
|
99 | + 'enum' => $model_field->get_model_class_names_pointed_to(), |
|
100 | + ); |
|
101 | + } |
|
102 | + } |
|
103 | + return $schema; |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * Get the schema for a given set of model relations |
|
109 | - * |
|
110 | - * @param EE_Model_Relation_Base[] $relations_on_model |
|
111 | - * @param array $schema |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
115 | - { |
|
116 | - foreach ($relations_on_model as $model_name => $relation) { |
|
117 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
118 | - continue; |
|
119 | - } |
|
120 | - $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
121 | - ? strtolower($model_name) |
|
122 | - : EEH_Inflector::pluralize_and_lower($model_name); |
|
123 | - $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
124 | - $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
107 | + /** |
|
108 | + * Get the schema for a given set of model relations |
|
109 | + * |
|
110 | + * @param EE_Model_Relation_Base[] $relations_on_model |
|
111 | + * @param array $schema |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
115 | + { |
|
116 | + foreach ($relations_on_model as $model_name => $relation) { |
|
117 | + if (! $relation instanceof EE_Model_Relation_Base) { |
|
118 | + continue; |
|
119 | + } |
|
120 | + $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
121 | + ? strtolower($model_name) |
|
122 | + : EEH_Inflector::pluralize_and_lower($model_name); |
|
123 | + $schema['properties'][ $model_name_for_schema ] = $relation->getSchema(); |
|
124 | + $schema['properties'][ $model_name_for_schema ]['relation_model'] = $model_name; |
|
125 | 125 | |
126 | - // links schema |
|
127 | - $links_key = 'https://api.eventespresso.com/' . strtolower($model_name); |
|
128 | - $schema['properties']['_links']['properties'][ $links_key ] = array( |
|
129 | - 'description' => esc_html__( |
|
130 | - 'Array of objects describing the link(s) for this relation resource.', |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - 'type' => 'array', |
|
134 | - 'readonly' => true, |
|
135 | - 'items' => array( |
|
136 | - 'type' => 'object', |
|
137 | - 'properties' => array( |
|
138 | - 'href' => array( |
|
139 | - 'type' => 'string', |
|
140 | - 'description' => sprintf( |
|
141 | - // translators: placeholder is the model name for the relation. |
|
142 | - esc_html__( |
|
143 | - 'The link to the resource for the %s relation(s) to this entity', |
|
144 | - 'event_espresso' |
|
145 | - ), |
|
146 | - $model_name |
|
147 | - ), |
|
148 | - ), |
|
149 | - 'single' => array( |
|
150 | - 'type' => 'boolean', |
|
151 | - 'description' => sprintf( |
|
152 | - // translators: placeholder is the model name for the relation. |
|
153 | - esc_html__( |
|
154 | - 'Whether or not there is only a single %s relation to this entity', |
|
155 | - 'event_espresso' |
|
156 | - ), |
|
157 | - $model_name |
|
158 | - ), |
|
159 | - ), |
|
160 | - ), |
|
161 | - 'additionalProperties' => false |
|
162 | - ), |
|
163 | - ); |
|
164 | - } |
|
165 | - return $schema; |
|
166 | - } |
|
126 | + // links schema |
|
127 | + $links_key = 'https://api.eventespresso.com/' . strtolower($model_name); |
|
128 | + $schema['properties']['_links']['properties'][ $links_key ] = array( |
|
129 | + 'description' => esc_html__( |
|
130 | + 'Array of objects describing the link(s) for this relation resource.', |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + 'type' => 'array', |
|
134 | + 'readonly' => true, |
|
135 | + 'items' => array( |
|
136 | + 'type' => 'object', |
|
137 | + 'properties' => array( |
|
138 | + 'href' => array( |
|
139 | + 'type' => 'string', |
|
140 | + 'description' => sprintf( |
|
141 | + // translators: placeholder is the model name for the relation. |
|
142 | + esc_html__( |
|
143 | + 'The link to the resource for the %s relation(s) to this entity', |
|
144 | + 'event_espresso' |
|
145 | + ), |
|
146 | + $model_name |
|
147 | + ), |
|
148 | + ), |
|
149 | + 'single' => array( |
|
150 | + 'type' => 'boolean', |
|
151 | + 'description' => sprintf( |
|
152 | + // translators: placeholder is the model name for the relation. |
|
153 | + esc_html__( |
|
154 | + 'Whether or not there is only a single %s relation to this entity', |
|
155 | + 'event_espresso' |
|
156 | + ), |
|
157 | + $model_name |
|
158 | + ), |
|
159 | + ), |
|
160 | + ), |
|
161 | + 'additionalProperties' => false |
|
162 | + ), |
|
163 | + ); |
|
164 | + } |
|
165 | + return $schema; |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * Outputs the schema header for a model. |
|
171 | - * |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public function getInitialSchemaStructure() |
|
175 | - { |
|
176 | - return array( |
|
177 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
178 | - 'title' => $this->model->get_this_model_name(), |
|
179 | - 'type' => 'object', |
|
180 | - 'properties' => array( |
|
181 | - 'link' => array( |
|
182 | - 'description' => esc_html__( |
|
183 | - 'Link to event on WordPress site hosting events.', |
|
184 | - 'event_espresso' |
|
185 | - ), |
|
186 | - 'type' => 'string', |
|
187 | - 'readonly' => true, |
|
188 | - ), |
|
189 | - '_links' => array( |
|
190 | - 'description' => esc_html__( |
|
191 | - 'Various links for resources related to the entity.', |
|
192 | - 'event_espresso' |
|
193 | - ), |
|
194 | - 'type' => 'object', |
|
195 | - 'readonly' => true, |
|
196 | - 'properties' => array( |
|
197 | - 'self' => array( |
|
198 | - 'description' => esc_html__( |
|
199 | - 'Link to this entities resource.', |
|
200 | - 'event_espresso' |
|
201 | - ), |
|
202 | - 'type' => 'array', |
|
203 | - 'items' => array( |
|
204 | - 'type' => 'object', |
|
205 | - 'properties' => array( |
|
206 | - 'href' => array( |
|
207 | - 'type' => 'string', |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'additionalProperties' => false |
|
211 | - ), |
|
212 | - 'readonly' => true |
|
213 | - ), |
|
214 | - 'collection' => array( |
|
215 | - 'description' => esc_html__( |
|
216 | - 'Link to this entities collection resource.', |
|
217 | - 'event_espresso' |
|
218 | - ), |
|
219 | - 'type' => 'array', |
|
220 | - 'items' => array( |
|
221 | - 'type' => 'object', |
|
222 | - 'properties' => array( |
|
223 | - 'href' => array( |
|
224 | - 'type' => 'string' |
|
225 | - ), |
|
226 | - ), |
|
227 | - 'additionalProperties' => false |
|
228 | - ), |
|
229 | - 'readonly' => true |
|
230 | - ), |
|
231 | - ), |
|
232 | - 'additionalProperties' => false, |
|
233 | - ), |
|
234 | - '_calculated_fields' => array_merge( |
|
235 | - $this->fields_calculator->getJsonSchemaForModel($this->model), |
|
236 | - array( |
|
237 | - '_protected' => $this->getProtectedFieldsSchema() |
|
238 | - ) |
|
239 | - ), |
|
240 | - '_protected' => $this->getProtectedFieldsSchema() |
|
241 | - ), |
|
242 | - 'additionalProperties' => false, |
|
243 | - ); |
|
244 | - } |
|
169 | + /** |
|
170 | + * Outputs the schema header for a model. |
|
171 | + * |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public function getInitialSchemaStructure() |
|
175 | + { |
|
176 | + return array( |
|
177 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
178 | + 'title' => $this->model->get_this_model_name(), |
|
179 | + 'type' => 'object', |
|
180 | + 'properties' => array( |
|
181 | + 'link' => array( |
|
182 | + 'description' => esc_html__( |
|
183 | + 'Link to event on WordPress site hosting events.', |
|
184 | + 'event_espresso' |
|
185 | + ), |
|
186 | + 'type' => 'string', |
|
187 | + 'readonly' => true, |
|
188 | + ), |
|
189 | + '_links' => array( |
|
190 | + 'description' => esc_html__( |
|
191 | + 'Various links for resources related to the entity.', |
|
192 | + 'event_espresso' |
|
193 | + ), |
|
194 | + 'type' => 'object', |
|
195 | + 'readonly' => true, |
|
196 | + 'properties' => array( |
|
197 | + 'self' => array( |
|
198 | + 'description' => esc_html__( |
|
199 | + 'Link to this entities resource.', |
|
200 | + 'event_espresso' |
|
201 | + ), |
|
202 | + 'type' => 'array', |
|
203 | + 'items' => array( |
|
204 | + 'type' => 'object', |
|
205 | + 'properties' => array( |
|
206 | + 'href' => array( |
|
207 | + 'type' => 'string', |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'additionalProperties' => false |
|
211 | + ), |
|
212 | + 'readonly' => true |
|
213 | + ), |
|
214 | + 'collection' => array( |
|
215 | + 'description' => esc_html__( |
|
216 | + 'Link to this entities collection resource.', |
|
217 | + 'event_espresso' |
|
218 | + ), |
|
219 | + 'type' => 'array', |
|
220 | + 'items' => array( |
|
221 | + 'type' => 'object', |
|
222 | + 'properties' => array( |
|
223 | + 'href' => array( |
|
224 | + 'type' => 'string' |
|
225 | + ), |
|
226 | + ), |
|
227 | + 'additionalProperties' => false |
|
228 | + ), |
|
229 | + 'readonly' => true |
|
230 | + ), |
|
231 | + ), |
|
232 | + 'additionalProperties' => false, |
|
233 | + ), |
|
234 | + '_calculated_fields' => array_merge( |
|
235 | + $this->fields_calculator->getJsonSchemaForModel($this->model), |
|
236 | + array( |
|
237 | + '_protected' => $this->getProtectedFieldsSchema() |
|
238 | + ) |
|
239 | + ), |
|
240 | + '_protected' => $this->getProtectedFieldsSchema() |
|
241 | + ), |
|
242 | + 'additionalProperties' => false, |
|
243 | + ); |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Returns an array of JSON schema to describe the _protected property on responses |
|
248 | - * @since 4.9.74.p |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function getProtectedFieldsSchema() |
|
252 | - { |
|
253 | - return array( |
|
254 | - 'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'), |
|
255 | - 'type' => 'array', |
|
256 | - 'items' => array( |
|
257 | - 'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'), |
|
258 | - 'type' => 'string', |
|
259 | - 'readonly' => true, |
|
260 | - ), |
|
261 | - 'readonly' => true |
|
262 | - ); |
|
263 | - } |
|
246 | + /** |
|
247 | + * Returns an array of JSON schema to describe the _protected property on responses |
|
248 | + * @since 4.9.74.p |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function getProtectedFieldsSchema() |
|
252 | + { |
|
253 | + return array( |
|
254 | + 'description' => esc_html__('Array of property names whose values were replaced with their default (because they are related to a password-protected entity.)', 'event_espresso'), |
|
255 | + 'type' => 'array', |
|
256 | + 'items' => array( |
|
257 | + 'description' => esc_html__('Each name corresponds to a property that is protected by password for this entity and has its default value returned in the response.', 'event_espresso'), |
|
258 | + 'type' => 'string', |
|
259 | + 'readonly' => true, |
|
260 | + ), |
|
261 | + 'readonly' => true |
|
262 | + ); |
|
263 | + } |
|
264 | 264 | |
265 | 265 | |
266 | - /** |
|
267 | - * Allows one to just use the object as a string to get the json. |
|
268 | - * eg. |
|
269 | - * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields); |
|
270 | - * // if echoed, would convert schema to a json formatted string. |
|
271 | - * |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - public function __toString() |
|
275 | - { |
|
276 | - $schema = wp_json_encode($this->getModelSchema()); |
|
277 | - return is_string($schema) ? $schema : ''; |
|
278 | - } |
|
266 | + /** |
|
267 | + * Allows one to just use the object as a string to get the json. |
|
268 | + * eg. |
|
269 | + * $json_schema = new JsonModelSchema(EEM_Event::instance(), new CalculatedModelFields); |
|
270 | + * // if echoed, would convert schema to a json formatted string. |
|
271 | + * |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + public function __toString() |
|
275 | + { |
|
276 | + $schema = wp_json_encode($this->getModelSchema()); |
|
277 | + return is_string($schema) ? $schema : ''; |
|
278 | + } |
|
279 | 279 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function createFromModel($model_name) |
42 | 42 | { |
43 | - return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
|
43 | + return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\'.$model_name); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function createFromClassname($calculator_classname) |
52 | 52 | { |
53 | 53 | $calculator = $this->loader->getShared($calculator_classname); |
54 | - if (!$calculator instanceof Base) { |
|
54 | + if ( ! $calculator instanceof Base) { |
|
55 | 55 | throw new UnexpectedEntityException( |
56 | 56 | $calculator_classname, |
57 | 57 | 'EventEspresso\core\libraries\rest_api\calculations\Base' |
@@ -18,46 +18,46 @@ |
||
18 | 18 | */ |
19 | 19 | class CalculatedModelFieldsFactory |
20 | 20 | { |
21 | - private $loader; |
|
21 | + private $loader; |
|
22 | 22 | |
23 | - /** |
|
24 | - * CalculatedModelFieldsFactory constructor. |
|
25 | - * @param LoaderInterface $loader |
|
26 | - */ |
|
27 | - public function __construct(LoaderInterface $loader) |
|
28 | - { |
|
29 | - $this->loader = $loader; |
|
30 | - } |
|
23 | + /** |
|
24 | + * CalculatedModelFieldsFactory constructor. |
|
25 | + * @param LoaderInterface $loader |
|
26 | + */ |
|
27 | + public function __construct(LoaderInterface $loader) |
|
28 | + { |
|
29 | + $this->loader = $loader; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Creates the calculator class that corresponds to that particular model |
|
34 | - * @since 4.9.68.p |
|
35 | - * @param string $model_name |
|
36 | - * @return Base |
|
37 | - * @throws UnexpectedEntityException |
|
38 | - */ |
|
39 | - public function createFromModel($model_name) |
|
40 | - { |
|
41 | - return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
|
42 | - } |
|
32 | + /** |
|
33 | + * Creates the calculator class that corresponds to that particular model |
|
34 | + * @since 4.9.68.p |
|
35 | + * @param string $model_name |
|
36 | + * @return Base |
|
37 | + * @throws UnexpectedEntityException |
|
38 | + */ |
|
39 | + public function createFromModel($model_name) |
|
40 | + { |
|
41 | + return $this->createFromClassname('EventEspresso\core\libraries\rest_api\calculations\\' . $model_name); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Creates the calculator class that corresponds to that classname and verifies it's of the correct type |
|
46 | - * @param string $calculator_classname |
|
47 | - * @return Base |
|
48 | - * @throws UnexpectedEntityException |
|
49 | - */ |
|
50 | - public function createFromClassname($calculator_classname) |
|
51 | - { |
|
52 | - $calculator = $this->loader->getShared($calculator_classname); |
|
53 | - if (!$calculator instanceof Base) { |
|
54 | - throw new UnexpectedEntityException( |
|
55 | - $calculator_classname, |
|
56 | - 'EventEspresso\core\libraries\rest_api\calculations\Base' |
|
57 | - ); |
|
58 | - } |
|
59 | - return $calculator; |
|
60 | - } |
|
44 | + /** |
|
45 | + * Creates the calculator class that corresponds to that classname and verifies it's of the correct type |
|
46 | + * @param string $calculator_classname |
|
47 | + * @return Base |
|
48 | + * @throws UnexpectedEntityException |
|
49 | + */ |
|
50 | + public function createFromClassname($calculator_classname) |
|
51 | + { |
|
52 | + $calculator = $this->loader->getShared($calculator_classname); |
|
53 | + if (!$calculator instanceof Base) { |
|
54 | + throw new UnexpectedEntityException( |
|
55 | + $calculator_classname, |
|
56 | + 'EventEspresso\core\libraries\rest_api\calculations\Base' |
|
57 | + ); |
|
58 | + } |
|
59 | + return $calculator; |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | // End of file CalculationsFactory.php |
63 | 63 | // Location: EventEspresso\core\libraries\rest_api\calculations/CalculationsFactory.php |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | protected function verifyCurrentUserCan($required_permission, $attempted_calculation) |
25 | 25 | { |
26 | - if (! current_user_can($required_permission)) { |
|
26 | + if ( ! current_user_can($required_permission)) { |
|
27 | 27 | throw new RestException( |
28 | 28 | 'permission_denied', |
29 | 29 | sprintf( |
@@ -75,6 +75,6 @@ discard block |
||
75 | 75 | public function schemaForCalculation($calculation_index) |
76 | 76 | { |
77 | 77 | $schema_map = $this->schemaForCalculations(); |
78 | - return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array(); |
|
78 | + return isset($schema_map[$calculation_index]) ? $schema_map[$calculation_index] : array(); |
|
79 | 79 | } |
80 | 80 | } |
@@ -15,65 +15,65 @@ |
||
15 | 15 | */ |
16 | 16 | class Base |
17 | 17 | { |
18 | - /** |
|
19 | - * @param $required_permission |
|
20 | - * @param $attempted_calculation |
|
21 | - * @throws RestException |
|
22 | - */ |
|
23 | - protected function verifyCurrentUserCan($required_permission, $attempted_calculation) |
|
24 | - { |
|
25 | - if (! current_user_can($required_permission)) { |
|
26 | - throw new RestException( |
|
27 | - 'permission_denied', |
|
28 | - sprintf( |
|
29 | - esc_html__( |
|
30 | - // @codingStandardsIgnoreStart |
|
31 | - 'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', |
|
32 | - // @codingStandardsIgnoreEnd |
|
33 | - 'event_espresso' |
|
34 | - ), |
|
35 | - $attempted_calculation, |
|
36 | - EEH_Inflector::pluralize_and_lower($this->getResourceName()), |
|
37 | - $required_permission |
|
38 | - ) |
|
39 | - ); |
|
40 | - } |
|
41 | - } |
|
18 | + /** |
|
19 | + * @param $required_permission |
|
20 | + * @param $attempted_calculation |
|
21 | + * @throws RestException |
|
22 | + */ |
|
23 | + protected function verifyCurrentUserCan($required_permission, $attempted_calculation) |
|
24 | + { |
|
25 | + if (! current_user_can($required_permission)) { |
|
26 | + throw new RestException( |
|
27 | + 'permission_denied', |
|
28 | + sprintf( |
|
29 | + esc_html__( |
|
30 | + // @codingStandardsIgnoreStart |
|
31 | + 'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', |
|
32 | + // @codingStandardsIgnoreEnd |
|
33 | + 'event_espresso' |
|
34 | + ), |
|
35 | + $attempted_calculation, |
|
36 | + EEH_Inflector::pluralize_and_lower($this->getResourceName()), |
|
37 | + $required_permission |
|
38 | + ) |
|
39 | + ); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Gets the name of the resource of the called class |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getResourceName() |
|
50 | - { |
|
51 | - return substr(__CLASS__, strrpos(__CLASS__, '\\') + 1); |
|
52 | - } |
|
44 | + /** |
|
45 | + * Gets the name of the resource of the called class |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getResourceName() |
|
50 | + { |
|
51 | + return substr(__CLASS__, strrpos(__CLASS__, '\\') + 1); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns an array to be used for the schema for the calculated fields. |
|
56 | - * @since 4.9.68.p |
|
57 | - * @return array keys are calculated field names (eg "optimum_sales_at_start") values are arrays { |
|
58 | - * @type string $description |
|
59 | - * @type string $type, eg "string", "int", "boolean", "object", "array", etc |
|
60 | - * } |
|
61 | - */ |
|
62 | - public function schemaForCalculations() |
|
63 | - { |
|
64 | - return array(); |
|
65 | - } |
|
54 | + /** |
|
55 | + * Returns an array to be used for the schema for the calculated fields. |
|
56 | + * @since 4.9.68.p |
|
57 | + * @return array keys are calculated field names (eg "optimum_sales_at_start") values are arrays { |
|
58 | + * @type string $description |
|
59 | + * @type string $type, eg "string", "int", "boolean", "object", "array", etc |
|
60 | + * } |
|
61 | + */ |
|
62 | + public function schemaForCalculations() |
|
63 | + { |
|
64 | + return array(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns the json schema for the given calculation index. |
|
69 | - * |
|
70 | - * @since 4.9.68.p |
|
71 | - * @param $calculation_index |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function schemaForCalculation($calculation_index) |
|
75 | - { |
|
76 | - $schema_map = $this->schemaForCalculations(); |
|
77 | - return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array(); |
|
78 | - } |
|
67 | + /** |
|
68 | + * Returns the json schema for the given calculation index. |
|
69 | + * |
|
70 | + * @since 4.9.68.p |
|
71 | + * @param $calculation_index |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function schemaForCalculation($calculation_index) |
|
75 | + { |
|
76 | + $schema_map = $this->schemaForCalculations(); |
|
77 | + return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array(); |
|
78 | + } |
|
79 | 79 | } |
@@ -16,16 +16,16 @@ |
||
16 | 16 | */ |
17 | 17 | class URLValidator |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns whether or not the URL is valid |
|
21 | - * @since 4.9.68.p |
|
22 | - * @param $url |
|
23 | - * @return boolean |
|
24 | - */ |
|
25 | - public function isValid($url) |
|
26 | - { |
|
27 | - return esc_url_raw($url) === $url; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Returns whether or not the URL is valid |
|
21 | + * @since 4.9.68.p |
|
22 | + * @param $url |
|
23 | + * @return boolean |
|
24 | + */ |
|
25 | + public function isValid($url) |
|
26 | + { |
|
27 | + return esc_url_raw($url) === $url; |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | // End of file URLValidator.php |
31 | 31 | // Location: ${NAMESPACE}/URLValidator.php |
@@ -14,8 +14,8 @@ |
||
14 | 14 | */ |
15 | 15 | class AnyFrontendRequest extends RouteMatchSpecification |
16 | 16 | { |
17 | - public function isMatchingRoute() |
|
18 | - { |
|
19 | - return $this->request->isFrontend(); |
|
20 | - } |
|
17 | + public function isMatchingRoute() |
|
18 | + { |
|
19 | + return $this->request->isFrontend(); |
|
20 | + } |
|
21 | 21 | } |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function isValid($file, $func, $line) |
34 | 34 | { |
35 | - if (! defined('JSON_ERROR_RECURSION')) { |
|
35 | + if ( ! defined('JSON_ERROR_RECURSION')) { |
|
36 | 36 | define('JSON_ERROR_RECURSION', 6); |
37 | 37 | } |
38 | - if (! defined('JSON_ERROR_INF_OR_NAN')) { |
|
38 | + if ( ! defined('JSON_ERROR_INF_OR_NAN')) { |
|
39 | 39 | define('JSON_ERROR_INF_OR_NAN', 7); |
40 | 40 | } |
41 | - if (! defined('JSON_ERROR_UNSUPPORTED_TYPE')) { |
|
41 | + if ( ! defined('JSON_ERROR_UNSUPPORTED_TYPE')) { |
|
42 | 42 | define('JSON_ERROR_UNSUPPORTED_TYPE', 8); |
43 | 43 | } |
44 | - if (! defined('JSON_ERROR_INVALID_PROPERTY_NAME')) { |
|
44 | + if ( ! defined('JSON_ERROR_INVALID_PROPERTY_NAME')) { |
|
45 | 45 | define('JSON_ERROR_INVALID_PROPERTY_NAME', 9); |
46 | 46 | } |
47 | - if (! defined('JSON_ERROR_UTF16')) { |
|
47 | + if ( ! defined('JSON_ERROR_UTF16')) { |
|
48 | 48 | define('JSON_ERROR_UTF16', 10); |
49 | 49 | } |
50 | 50 | switch (json_last_error()) { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $error = ': Unknown error'; |
85 | 85 | break; |
86 | 86 | } |
87 | - EE_Error::add_error('JSON decoding failed' . $error, $file, $func, $line); |
|
87 | + EE_Error::add_error('JSON decoding failed'.$error, $file, $func, $line); |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 | } |
@@ -17,76 +17,76 @@ |
||
17 | 17 | */ |
18 | 18 | class JsonValidator |
19 | 19 | { |
20 | - /** |
|
21 | - * Call this method IMMEDIATELY after json_decode() and |
|
22 | - * it will will return true if the decoded JSON was valid, |
|
23 | - * or return false after adding an error if not valid. |
|
24 | - * The actual JSON file does not need to be supplied, |
|
25 | - * but details re: code execution location are required. |
|
26 | - * ex: |
|
27 | - * JsonValidator::isValid(__FILE__, __METHOD__, __LINE__) |
|
28 | - * |
|
29 | - * @param string $file |
|
30 | - * @param string $func |
|
31 | - * @param string $line |
|
32 | - * @return boolean |
|
33 | - * @since 4.9.70.p |
|
34 | - */ |
|
35 | - public function isValid($file, $func, $line) |
|
36 | - { |
|
37 | - if (! defined('JSON_ERROR_RECURSION')) { |
|
38 | - define('JSON_ERROR_RECURSION', 6); |
|
39 | - } |
|
40 | - if (! defined('JSON_ERROR_INF_OR_NAN')) { |
|
41 | - define('JSON_ERROR_INF_OR_NAN', 7); |
|
42 | - } |
|
43 | - if (! defined('JSON_ERROR_UNSUPPORTED_TYPE')) { |
|
44 | - define('JSON_ERROR_UNSUPPORTED_TYPE', 8); |
|
45 | - } |
|
46 | - if (! defined('JSON_ERROR_INVALID_PROPERTY_NAME')) { |
|
47 | - define('JSON_ERROR_INVALID_PROPERTY_NAME', 9); |
|
48 | - } |
|
49 | - if (! defined('JSON_ERROR_UTF16')) { |
|
50 | - define('JSON_ERROR_UTF16', 10); |
|
51 | - } |
|
52 | - switch (json_last_error()) { |
|
53 | - case JSON_ERROR_NONE: |
|
54 | - return true; |
|
55 | - case JSON_ERROR_DEPTH: |
|
56 | - $error = ': Maximum stack depth exceeded'; |
|
57 | - break; |
|
58 | - case JSON_ERROR_STATE_MISMATCH: |
|
59 | - $error = ': Invalid or malformed JSON'; |
|
60 | - break; |
|
61 | - case JSON_ERROR_CTRL_CHAR: |
|
62 | - $error = ': Control character error, possible malformed JSON'; |
|
63 | - break; |
|
64 | - case JSON_ERROR_SYNTAX: |
|
65 | - $error = ': Syntax error, malformed JSON'; |
|
66 | - break; |
|
67 | - case JSON_ERROR_UTF8: |
|
68 | - $error = ': Malformed UTF-8 characters, possible malformed JSON'; |
|
69 | - break; |
|
70 | - case JSON_ERROR_RECURSION: |
|
71 | - $error = ': One or more recursive references in the value to be encoded'; |
|
72 | - break; |
|
73 | - case JSON_ERROR_INF_OR_NAN: |
|
74 | - $error = ': One or more NAN or INF values in the value to be encoded'; |
|
75 | - break; |
|
76 | - case JSON_ERROR_UNSUPPORTED_TYPE: |
|
77 | - $error = ': A value of a type that cannot be encoded was given'; |
|
78 | - break; |
|
79 | - case JSON_ERROR_INVALID_PROPERTY_NAME: |
|
80 | - $error = ': A property name that cannot be encoded was given'; |
|
81 | - break; |
|
82 | - case JSON_ERROR_UTF16: |
|
83 | - $error = ': Malformed UTF-16 characters, possibly incorrectly encoded'; |
|
84 | - break; |
|
85 | - default: |
|
86 | - $error = ': Unknown error'; |
|
87 | - break; |
|
88 | - } |
|
89 | - EE_Error::add_error('JSON decoding failed' . $error, $file, $func, $line); |
|
90 | - return false; |
|
91 | - } |
|
20 | + /** |
|
21 | + * Call this method IMMEDIATELY after json_decode() and |
|
22 | + * it will will return true if the decoded JSON was valid, |
|
23 | + * or return false after adding an error if not valid. |
|
24 | + * The actual JSON file does not need to be supplied, |
|
25 | + * but details re: code execution location are required. |
|
26 | + * ex: |
|
27 | + * JsonValidator::isValid(__FILE__, __METHOD__, __LINE__) |
|
28 | + * |
|
29 | + * @param string $file |
|
30 | + * @param string $func |
|
31 | + * @param string $line |
|
32 | + * @return boolean |
|
33 | + * @since 4.9.70.p |
|
34 | + */ |
|
35 | + public function isValid($file, $func, $line) |
|
36 | + { |
|
37 | + if (! defined('JSON_ERROR_RECURSION')) { |
|
38 | + define('JSON_ERROR_RECURSION', 6); |
|
39 | + } |
|
40 | + if (! defined('JSON_ERROR_INF_OR_NAN')) { |
|
41 | + define('JSON_ERROR_INF_OR_NAN', 7); |
|
42 | + } |
|
43 | + if (! defined('JSON_ERROR_UNSUPPORTED_TYPE')) { |
|
44 | + define('JSON_ERROR_UNSUPPORTED_TYPE', 8); |
|
45 | + } |
|
46 | + if (! defined('JSON_ERROR_INVALID_PROPERTY_NAME')) { |
|
47 | + define('JSON_ERROR_INVALID_PROPERTY_NAME', 9); |
|
48 | + } |
|
49 | + if (! defined('JSON_ERROR_UTF16')) { |
|
50 | + define('JSON_ERROR_UTF16', 10); |
|
51 | + } |
|
52 | + switch (json_last_error()) { |
|
53 | + case JSON_ERROR_NONE: |
|
54 | + return true; |
|
55 | + case JSON_ERROR_DEPTH: |
|
56 | + $error = ': Maximum stack depth exceeded'; |
|
57 | + break; |
|
58 | + case JSON_ERROR_STATE_MISMATCH: |
|
59 | + $error = ': Invalid or malformed JSON'; |
|
60 | + break; |
|
61 | + case JSON_ERROR_CTRL_CHAR: |
|
62 | + $error = ': Control character error, possible malformed JSON'; |
|
63 | + break; |
|
64 | + case JSON_ERROR_SYNTAX: |
|
65 | + $error = ': Syntax error, malformed JSON'; |
|
66 | + break; |
|
67 | + case JSON_ERROR_UTF8: |
|
68 | + $error = ': Malformed UTF-8 characters, possible malformed JSON'; |
|
69 | + break; |
|
70 | + case JSON_ERROR_RECURSION: |
|
71 | + $error = ': One or more recursive references in the value to be encoded'; |
|
72 | + break; |
|
73 | + case JSON_ERROR_INF_OR_NAN: |
|
74 | + $error = ': One or more NAN or INF values in the value to be encoded'; |
|
75 | + break; |
|
76 | + case JSON_ERROR_UNSUPPORTED_TYPE: |
|
77 | + $error = ': A value of a type that cannot be encoded was given'; |
|
78 | + break; |
|
79 | + case JSON_ERROR_INVALID_PROPERTY_NAME: |
|
80 | + $error = ': A property name that cannot be encoded was given'; |
|
81 | + break; |
|
82 | + case JSON_ERROR_UTF16: |
|
83 | + $error = ': Malformed UTF-16 characters, possibly incorrectly encoded'; |
|
84 | + break; |
|
85 | + default: |
|
86 | + $error = ': Unknown error'; |
|
87 | + break; |
|
88 | + } |
|
89 | + EE_Error::add_error('JSON decoding failed' . $error, $file, $func, $line); |
|
90 | + return false; |
|
91 | + } |
|
92 | 92 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | private function setTemplateRootPath() |
44 | 44 | { |
45 | - $this->template_root_path = $this->domain->pluginPath() . 'ui/blocks/'; |
|
45 | + $this->template_root_path = $this->domain->pluginPath().'ui/blocks/'; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 |
@@ -15,57 +15,57 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class BlockRenderer implements BlockRendererInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * @var DomainInterface |
|
20 | - */ |
|
21 | - protected $domain; |
|
18 | + /** |
|
19 | + * @var DomainInterface |
|
20 | + */ |
|
21 | + protected $domain; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - private $template_root_path; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + private $template_root_path; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * BlockRenderer constructor. |
|
31 | - * |
|
32 | - * @param DomainInterface $domain |
|
33 | - */ |
|
34 | - public function __construct(DomainInterface $domain) |
|
35 | - { |
|
36 | - $this->domain = $domain; |
|
37 | - $this->setTemplateRootPath(); |
|
38 | - } |
|
29 | + /** |
|
30 | + * BlockRenderer constructor. |
|
31 | + * |
|
32 | + * @param DomainInterface $domain |
|
33 | + */ |
|
34 | + public function __construct(DomainInterface $domain) |
|
35 | + { |
|
36 | + $this->domain = $domain; |
|
37 | + $this->setTemplateRootPath(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Sets the root path to the main block template. |
|
43 | - */ |
|
44 | - private function setTemplateRootPath() |
|
45 | - { |
|
46 | - $this->template_root_path = $this->domain->pluginPath() . 'ui/blocks/'; |
|
47 | - } |
|
41 | + /** |
|
42 | + * Sets the root path to the main block template. |
|
43 | + */ |
|
44 | + private function setTemplateRootPath() |
|
45 | + { |
|
46 | + $this->template_root_path = $this->domain->pluginPath() . 'ui/blocks/'; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Exposes the root path for the main block template. |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function templateRootPath() |
|
55 | - { |
|
56 | - return $this->template_root_path; |
|
57 | - } |
|
50 | + /** |
|
51 | + * Exposes the root path for the main block template. |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function templateRootPath() |
|
55 | + { |
|
56 | + return $this->template_root_path; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * converts GraphQL GUID into EE DB ID |
|
62 | - * |
|
63 | - * @param string $GUID |
|
64 | - * @return int |
|
65 | - */ |
|
66 | - protected function parseGUID($GUID) |
|
67 | - { |
|
68 | - $parts = Relay::fromGlobalId($GUID); |
|
69 | - return ! empty($parts['id']) ? $parts['id'] : 0; |
|
70 | - } |
|
60 | + /** |
|
61 | + * converts GraphQL GUID into EE DB ID |
|
62 | + * |
|
63 | + * @param string $GUID |
|
64 | + * @return int |
|
65 | + */ |
|
66 | + protected function parseGUID($GUID) |
|
67 | + { |
|
68 | + $parts = Relay::fromGlobalId($GUID); |
|
69 | + return ! empty($parts['id']) ? $parts['id'] : 0; |
|
70 | + } |
|
71 | 71 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | public static function instance() |
40 | 40 | { |
41 | 41 | // check if class object is instantiated, and instantiated properly |
42 | - if (! self::$_instance instanceof EE_Network_Config) { |
|
42 | + if ( ! self::$_instance instanceof EE_Network_Config) { |
|
43 | 43 | self::$_instance = new self(); |
44 | 44 | } |
45 | 45 | return self::$_instance; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | // need to bust cache for comparing original if this is a multisite install |
137 | 137 | if (is_multisite()) { |
138 | 138 | global $current_site; |
139 | - $cache_key = $current_site->id . ':ee_network_config'; |
|
139 | + $cache_key = $current_site->id.':ee_network_config'; |
|
140 | 140 | wp_cache_delete($cache_key, 'site-options'); |
141 | 141 | } |
142 | 142 |
@@ -13,180 +13,180 @@ discard block |
||
13 | 13 | */ |
14 | 14 | final class EE_Network_Config |
15 | 15 | { |
16 | - /** |
|
17 | - * @var EE_Network_Config $_instance |
|
18 | - */ |
|
19 | - private static $_instance; |
|
20 | - |
|
21 | - /** |
|
22 | - * addons can add their specific network_config objects to this property |
|
23 | - * |
|
24 | - * @var EE_Config_Base[] $addons |
|
25 | - */ |
|
26 | - public $addons; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var EE_Network_Core_Config $core |
|
30 | - */ |
|
31 | - public $core; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @singleton method used to instantiate class object |
|
36 | - * @return EE_Network_Config instance |
|
37 | - */ |
|
38 | - public static function instance() |
|
39 | - { |
|
40 | - // check if class object is instantiated, and instantiated properly |
|
41 | - if (! self::$_instance instanceof EE_Network_Config) { |
|
42 | - self::$_instance = new self(); |
|
43 | - } |
|
44 | - return self::$_instance; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * class constructor |
|
50 | - */ |
|
51 | - private function __construct() |
|
52 | - { |
|
53 | - do_action('AHEE__EE_Network_Config__construct__begin', $this); |
|
54 | - // set defaults |
|
55 | - $this->core = apply_filters('FHEE__EE_Network_Config___construct__core', new EE_Network_Core_Config()); |
|
56 | - $this->addons = array(); |
|
57 | - |
|
58 | - $this->_load_config(); |
|
59 | - |
|
60 | - // construct__end hook |
|
61 | - do_action('AHEE__EE_Network_Config__construct__end', $this); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * load EE Network Config options |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - private function _load_config() |
|
71 | - { |
|
72 | - // load network config start hook |
|
73 | - do_action('AHEE__EE_Network_Config___load_config__start', $this); |
|
74 | - $config = $this->get_config(); |
|
75 | - foreach ($config as $config_prop => $settings) { |
|
76 | - if ($config_prop === 'core' && ! $settings instanceof EE_Network_Core_Config) { |
|
77 | - $core = new EE_Network_Core_Config(); |
|
78 | - foreach ($settings as $prop => $setting) { |
|
79 | - if (property_exists($core, $prop)) { |
|
80 | - $core->{$prop} = $setting; |
|
81 | - } |
|
82 | - } |
|
83 | - $settings = $core; |
|
84 | - add_filter('FHEE__EE_Network_Config___load_config__update_network_config', '__return_true'); |
|
85 | - } |
|
86 | - if (is_object($settings) && property_exists($this, $config_prop)) { |
|
87 | - $this->{$config_prop} = apply_filters( |
|
88 | - 'FHEE__EE_Network_Config___load_config__config_settings', |
|
89 | - $settings, |
|
90 | - $config_prop, |
|
91 | - $this |
|
92 | - ); |
|
93 | - if (method_exists($settings, 'populate')) { |
|
94 | - $this->{$config_prop}->populate(); |
|
95 | - } |
|
96 | - if (method_exists($settings, 'do_hooks')) { |
|
97 | - $this->{$config_prop}->do_hooks(); |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - if (apply_filters('FHEE__EE_Network_Config___load_config__update_network_config', false)) { |
|
102 | - $this->update_config(); |
|
103 | - } |
|
104 | - |
|
105 | - // load network config end hook |
|
106 | - do_action('AHEE__EE_Network_Config___load_config__end', $this); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * get_config |
|
112 | - * |
|
113 | - * @return array of network config stuff |
|
114 | - */ |
|
115 | - public function get_config() |
|
116 | - { |
|
117 | - // grab network configuration |
|
118 | - $CFG = get_site_option('ee_network_config', array()); |
|
119 | - $CFG = apply_filters('FHEE__EE_Network_Config__get_config__CFG', $CFG); |
|
120 | - return $CFG; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * update_config |
|
126 | - * |
|
127 | - * @param bool $add_success |
|
128 | - * @param bool $add_error |
|
129 | - * @return bool success |
|
130 | - */ |
|
131 | - public function update_config($add_success = false, $add_error = true) |
|
132 | - { |
|
133 | - do_action('AHEE__EE_Network_Config__update_config__begin', $this); |
|
134 | - |
|
135 | - // need to bust cache for comparing original if this is a multisite install |
|
136 | - if (is_multisite()) { |
|
137 | - global $current_site; |
|
138 | - $cache_key = $current_site->id . ':ee_network_config'; |
|
139 | - wp_cache_delete($cache_key, 'site-options'); |
|
140 | - } |
|
141 | - |
|
142 | - // we have to compare existing saved config with config in memory because if there is no difference that means |
|
143 | - // that the method executed fine but there just was no update. WordPress doesn't distinguish between false because |
|
144 | - // there were 0 records updated because of no change vs false because some error produced problems with the update. |
|
145 | - $original = get_site_option('ee_network_config'); |
|
146 | - |
|
147 | - if ($original == $this) { |
|
148 | - return true; |
|
149 | - } |
|
150 | - // update |
|
151 | - $saved = update_site_option('ee_network_config', $this); |
|
152 | - |
|
153 | - do_action('AHEE__EE_Network_Config__update_config__end', $this, $saved); |
|
154 | - // if config remains the same or was updated successfully |
|
155 | - if ($saved) { |
|
156 | - if ($add_success) { |
|
157 | - $msg = is_multisite() ? esc_html__( |
|
158 | - 'The Event Espresso Network Configuration Settings have been successfully updated.', |
|
159 | - 'event_espresso' |
|
160 | - ) : esc_html__('Extra Event Espresso Configuration settings were successfully updated.', 'event_espresso'); |
|
161 | - EE_Error::add_success($msg); |
|
162 | - } |
|
163 | - return true; |
|
164 | - } |
|
165 | - if ($add_error) { |
|
166 | - $msg = is_multisite() ? esc_html__( |
|
167 | - 'The Event Espresso Network Configuration Settings were not updated.', |
|
168 | - 'event_espresso' |
|
169 | - ) : esc_html__('Extra Event Espresso Network Configuration settings were not updated.', 'event_espresso'); |
|
170 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
171 | - } |
|
172 | - return false; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * __sleep |
|
178 | - * |
|
179 | - * @return array |
|
180 | - */ |
|
181 | - public function __sleep() |
|
182 | - { |
|
183 | - return apply_filters( |
|
184 | - 'FHEE__EE_Network_Config__sleep', |
|
185 | - array( |
|
186 | - 'core', |
|
187 | - ) |
|
188 | - ); |
|
189 | - } |
|
16 | + /** |
|
17 | + * @var EE_Network_Config $_instance |
|
18 | + */ |
|
19 | + private static $_instance; |
|
20 | + |
|
21 | + /** |
|
22 | + * addons can add their specific network_config objects to this property |
|
23 | + * |
|
24 | + * @var EE_Config_Base[] $addons |
|
25 | + */ |
|
26 | + public $addons; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var EE_Network_Core_Config $core |
|
30 | + */ |
|
31 | + public $core; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @singleton method used to instantiate class object |
|
36 | + * @return EE_Network_Config instance |
|
37 | + */ |
|
38 | + public static function instance() |
|
39 | + { |
|
40 | + // check if class object is instantiated, and instantiated properly |
|
41 | + if (! self::$_instance instanceof EE_Network_Config) { |
|
42 | + self::$_instance = new self(); |
|
43 | + } |
|
44 | + return self::$_instance; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * class constructor |
|
50 | + */ |
|
51 | + private function __construct() |
|
52 | + { |
|
53 | + do_action('AHEE__EE_Network_Config__construct__begin', $this); |
|
54 | + // set defaults |
|
55 | + $this->core = apply_filters('FHEE__EE_Network_Config___construct__core', new EE_Network_Core_Config()); |
|
56 | + $this->addons = array(); |
|
57 | + |
|
58 | + $this->_load_config(); |
|
59 | + |
|
60 | + // construct__end hook |
|
61 | + do_action('AHEE__EE_Network_Config__construct__end', $this); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * load EE Network Config options |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + private function _load_config() |
|
71 | + { |
|
72 | + // load network config start hook |
|
73 | + do_action('AHEE__EE_Network_Config___load_config__start', $this); |
|
74 | + $config = $this->get_config(); |
|
75 | + foreach ($config as $config_prop => $settings) { |
|
76 | + if ($config_prop === 'core' && ! $settings instanceof EE_Network_Core_Config) { |
|
77 | + $core = new EE_Network_Core_Config(); |
|
78 | + foreach ($settings as $prop => $setting) { |
|
79 | + if (property_exists($core, $prop)) { |
|
80 | + $core->{$prop} = $setting; |
|
81 | + } |
|
82 | + } |
|
83 | + $settings = $core; |
|
84 | + add_filter('FHEE__EE_Network_Config___load_config__update_network_config', '__return_true'); |
|
85 | + } |
|
86 | + if (is_object($settings) && property_exists($this, $config_prop)) { |
|
87 | + $this->{$config_prop} = apply_filters( |
|
88 | + 'FHEE__EE_Network_Config___load_config__config_settings', |
|
89 | + $settings, |
|
90 | + $config_prop, |
|
91 | + $this |
|
92 | + ); |
|
93 | + if (method_exists($settings, 'populate')) { |
|
94 | + $this->{$config_prop}->populate(); |
|
95 | + } |
|
96 | + if (method_exists($settings, 'do_hooks')) { |
|
97 | + $this->{$config_prop}->do_hooks(); |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + if (apply_filters('FHEE__EE_Network_Config___load_config__update_network_config', false)) { |
|
102 | + $this->update_config(); |
|
103 | + } |
|
104 | + |
|
105 | + // load network config end hook |
|
106 | + do_action('AHEE__EE_Network_Config___load_config__end', $this); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * get_config |
|
112 | + * |
|
113 | + * @return array of network config stuff |
|
114 | + */ |
|
115 | + public function get_config() |
|
116 | + { |
|
117 | + // grab network configuration |
|
118 | + $CFG = get_site_option('ee_network_config', array()); |
|
119 | + $CFG = apply_filters('FHEE__EE_Network_Config__get_config__CFG', $CFG); |
|
120 | + return $CFG; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * update_config |
|
126 | + * |
|
127 | + * @param bool $add_success |
|
128 | + * @param bool $add_error |
|
129 | + * @return bool success |
|
130 | + */ |
|
131 | + public function update_config($add_success = false, $add_error = true) |
|
132 | + { |
|
133 | + do_action('AHEE__EE_Network_Config__update_config__begin', $this); |
|
134 | + |
|
135 | + // need to bust cache for comparing original if this is a multisite install |
|
136 | + if (is_multisite()) { |
|
137 | + global $current_site; |
|
138 | + $cache_key = $current_site->id . ':ee_network_config'; |
|
139 | + wp_cache_delete($cache_key, 'site-options'); |
|
140 | + } |
|
141 | + |
|
142 | + // we have to compare existing saved config with config in memory because if there is no difference that means |
|
143 | + // that the method executed fine but there just was no update. WordPress doesn't distinguish between false because |
|
144 | + // there were 0 records updated because of no change vs false because some error produced problems with the update. |
|
145 | + $original = get_site_option('ee_network_config'); |
|
146 | + |
|
147 | + if ($original == $this) { |
|
148 | + return true; |
|
149 | + } |
|
150 | + // update |
|
151 | + $saved = update_site_option('ee_network_config', $this); |
|
152 | + |
|
153 | + do_action('AHEE__EE_Network_Config__update_config__end', $this, $saved); |
|
154 | + // if config remains the same or was updated successfully |
|
155 | + if ($saved) { |
|
156 | + if ($add_success) { |
|
157 | + $msg = is_multisite() ? esc_html__( |
|
158 | + 'The Event Espresso Network Configuration Settings have been successfully updated.', |
|
159 | + 'event_espresso' |
|
160 | + ) : esc_html__('Extra Event Espresso Configuration settings were successfully updated.', 'event_espresso'); |
|
161 | + EE_Error::add_success($msg); |
|
162 | + } |
|
163 | + return true; |
|
164 | + } |
|
165 | + if ($add_error) { |
|
166 | + $msg = is_multisite() ? esc_html__( |
|
167 | + 'The Event Espresso Network Configuration Settings were not updated.', |
|
168 | + 'event_espresso' |
|
169 | + ) : esc_html__('Extra Event Espresso Network Configuration settings were not updated.', 'event_espresso'); |
|
170 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
171 | + } |
|
172 | + return false; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * __sleep |
|
178 | + * |
|
179 | + * @return array |
|
180 | + */ |
|
181 | + public function __sleep() |
|
182 | + { |
|
183 | + return apply_filters( |
|
184 | + 'FHEE__EE_Network_Config__sleep', |
|
185 | + array( |
|
186 | + 'core', |
|
187 | + ) |
|
188 | + ); |
|
189 | + } |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | |
@@ -195,27 +195,27 @@ discard block |
||
195 | 195 | */ |
196 | 196 | class EE_Network_Core_Config extends EE_Config_Base |
197 | 197 | { |
198 | - /** |
|
199 | - * PUE site license key |
|
200 | - * |
|
201 | - * @var string $site_license_key |
|
202 | - */ |
|
203 | - public $site_license_key; |
|
204 | - |
|
205 | - /** |
|
206 | - * This indicates whether messages system processing should be done on the same request or not. |
|
207 | - * |
|
208 | - * @var boolean $do_messages_on_same_request |
|
209 | - */ |
|
210 | - public $do_messages_on_same_request; |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * EE_Network_Core_Config constructor. |
|
215 | - */ |
|
216 | - public function __construct() |
|
217 | - { |
|
218 | - $this->site_license_key = ''; |
|
219 | - $this->do_messages_on_same_request = false; |
|
220 | - } |
|
198 | + /** |
|
199 | + * PUE site license key |
|
200 | + * |
|
201 | + * @var string $site_license_key |
|
202 | + */ |
|
203 | + public $site_license_key; |
|
204 | + |
|
205 | + /** |
|
206 | + * This indicates whether messages system processing should be done on the same request or not. |
|
207 | + * |
|
208 | + * @var boolean $do_messages_on_same_request |
|
209 | + */ |
|
210 | + public $do_messages_on_same_request; |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * EE_Network_Core_Config constructor. |
|
215 | + */ |
|
216 | + public function __construct() |
|
217 | + { |
|
218 | + $this->site_license_key = ''; |
|
219 | + $this->do_messages_on_same_request = false; |
|
220 | + } |
|
221 | 221 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPressPageEditorAddNew extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since 4.9.71.p |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - return strpos($this->request->requestUri(), 'wp-admin/post-new.php') !== false |
|
26 | - && $this->request->getRequestParam('post_type', 'post') === 'page'; |
|
27 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since 4.9.71.p |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + return strpos($this->request->requestUri(), 'wp-admin/post-new.php') !== false |
|
26 | + && $this->request->getRequestParam('post_type', 'post') === 'page'; |
|
27 | + } |
|
28 | 28 | } |