Completed
Branch fix-wp-gql-for-plain-urls (809337)
by
unknown
55:28 queued 46:00
created
core/domain/entities/routing/data_nodes/core/Api.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -18,38 +18,38 @@
 block discarded – undo
18 18
  */
19 19
 class Api extends JsonDataNode
20 20
 {
21
-    const NODE_NAME = 'api';
22
-
23
-
24
-    /**
25
-     * @param JsonDataNodeValidator $validator
26
-     */
27
-    public function __construct(JsonDataNodeValidator $validator)
28
-    {
29
-        parent::__construct($validator);
30
-        $this->setNodeName(Api::NODE_NAME);
31
-    }
32
-
33
-
34
-    /**
35
-     * @throws DomainException
36
-     * @since $VID:$
37
-     */
38
-    public function initialize()
39
-    {
40
-        $this->addData('restApiNonce', wp_create_nonce('wp_rest'));
41
-        $this->addData('restApiBaseUrl', rest_url());
42
-        $this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/'));
43
-        $this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName());
44
-        $this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName());
45
-
46
-        // route can be something like 'graphql'
47
-        $route = trim(Router::$route, '/');
48
-        // make sure we are dealing with sane folks
49
-        $has_pretty_permalinks = (bool) get_option('permalink_structure');
50
-        // if pretty permalinks, use '/graphql' otherwise '?graphql=1'
51
-        $graphqlEndpoint = $has_pretty_permalinks ? site_url($route) : add_query_arg($route, 1, site_url());
52
-        $this->addData('graphqlEndpoint', esc_url($graphqlEndpoint));
53
-        $this->setInitialized(true);
54
-    }
21
+	const NODE_NAME = 'api';
22
+
23
+
24
+	/**
25
+	 * @param JsonDataNodeValidator $validator
26
+	 */
27
+	public function __construct(JsonDataNodeValidator $validator)
28
+	{
29
+		parent::__construct($validator);
30
+		$this->setNodeName(Api::NODE_NAME);
31
+	}
32
+
33
+
34
+	/**
35
+	 * @throws DomainException
36
+	 * @since $VID:$
37
+	 */
38
+	public function initialize()
39
+	{
40
+		$this->addData('restApiNonce', wp_create_nonce('wp_rest'));
41
+		$this->addData('restApiBaseUrl', rest_url());
42
+		$this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/'));
43
+		$this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName());
44
+		$this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName());
45
+
46
+		// route can be something like 'graphql'
47
+		$route = trim(Router::$route, '/');
48
+		// make sure we are dealing with sane folks
49
+		$has_pretty_permalinks = (bool) get_option('permalink_structure');
50
+		// if pretty permalinks, use '/graphql' otherwise '?graphql=1'
51
+		$graphqlEndpoint = $has_pretty_permalinks ? site_url($route) : add_query_arg($route, 1, site_url());
52
+		$this->addData('graphqlEndpoint', esc_url($graphqlEndpoint));
53
+		$this->setInitialized(true);
54
+	}
55 55
 }
Please login to merge, or discard this patch.
core/domain/services/contexts/RequestTypeContextDetector.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 
68 68
     /**
69 69
      * @param string $globalRouteCondition
70
-     * @param mixed  $default
70
+     * @param boolean  $default
71 71
      * @return mixed
72 72
      */
73 73
     private function getGlobalRouteCondition(string $globalRouteCondition, $default)
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
7 7
 use EventEspresso\core\services\request\RequestInterface;
8 8
 use EventEspresso\core\domain\entities\contexts\RequestTypeContext;
9 9
 use InvalidArgumentException;
10
-use WPGraphQL\Router;
11 10
 
12 11
 /**
13 12
  * Class RequestTypeContextDetector
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -20,250 +20,250 @@
 block discarded – undo
20 20
 class RequestTypeContextDetector
21 21
 {
22 22
 
23
-    /**
24
-     * @var GraphQLEndpoint $gql_endpoint
25
-     */
26
-    private $gql_endpoint;
23
+	/**
24
+	 * @var GraphQLEndpoint $gql_endpoint
25
+	 */
26
+	private $gql_endpoint;
27 27
 
28
-    /**
29
-     * @var RequestTypeContextFactoryInterface $factory
30
-     */
31
-    private $factory;
28
+	/**
29
+	 * @var RequestTypeContextFactoryInterface $factory
30
+	 */
31
+	private $factory;
32 32
 
33
-    /**
34
-     * @var RequestInterface $request
35
-     */
36
-    private $request;
33
+	/**
34
+	 * @var RequestInterface $request
35
+	 */
36
+	private $request;
37 37
 
38
-    /**
39
-     * @var array $globalRouteConditions
40
-     */
41
-    private $globalRouteConditions;
38
+	/**
39
+	 * @var array $globalRouteConditions
40
+	 */
41
+	private $globalRouteConditions;
42 42
 
43 43
 
44
-    /**
45
-     * RequestTypeContextDetector constructor.
46
-     *
47
-     * @param GraphQLEndpoint                    $gql_endpoint
48
-     * @param RequestInterface                   $request
49
-     * @param RequestTypeContextFactoryInterface $factory
50
-     * @param array                              $globalRouteConditions an array for injecting values that would
51
-     *                                                                  otherwise be defined as global constants
52
-     *                                                                  or other global variables for the current
53
-     *                                                                  request route such as DOING_AJAX
54
-     */
55
-    public function __construct(
56
-        GraphQLEndpoint $gql_endpoint,
57
-        RequestInterface $request,
58
-        RequestTypeContextFactoryInterface $factory,
59
-        array $globalRouteConditions = []
60
-    ) {
61
-        $this->gql_endpoint = $gql_endpoint;
62
-        $this->request = $request;
63
-        $this->factory = $factory;
64
-        $this->globalRouteConditions = $globalRouteConditions;
65
-    }
44
+	/**
45
+	 * RequestTypeContextDetector constructor.
46
+	 *
47
+	 * @param GraphQLEndpoint                    $gql_endpoint
48
+	 * @param RequestInterface                   $request
49
+	 * @param RequestTypeContextFactoryInterface $factory
50
+	 * @param array                              $globalRouteConditions an array for injecting values that would
51
+	 *                                                                  otherwise be defined as global constants
52
+	 *                                                                  or other global variables for the current
53
+	 *                                                                  request route such as DOING_AJAX
54
+	 */
55
+	public function __construct(
56
+		GraphQLEndpoint $gql_endpoint,
57
+		RequestInterface $request,
58
+		RequestTypeContextFactoryInterface $factory,
59
+		array $globalRouteConditions = []
60
+	) {
61
+		$this->gql_endpoint = $gql_endpoint;
62
+		$this->request = $request;
63
+		$this->factory = $factory;
64
+		$this->globalRouteConditions = $globalRouteConditions;
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     * @param string $globalRouteCondition
70
-     * @param mixed  $default
71
-     * @return mixed
72
-     */
73
-    private function getGlobalRouteCondition(string $globalRouteCondition, $default)
74
-    {
75
-        return isset($this->globalRouteConditions[ $globalRouteCondition ])
76
-            ? $this->globalRouteConditions[ $globalRouteCondition ]
77
-            : $default;
78
-    }
68
+	/**
69
+	 * @param string $globalRouteCondition
70
+	 * @param mixed  $default
71
+	 * @return mixed
72
+	 */
73
+	private function getGlobalRouteCondition(string $globalRouteCondition, $default)
74
+	{
75
+		return isset($this->globalRouteConditions[ $globalRouteCondition ])
76
+			? $this->globalRouteConditions[ $globalRouteCondition ]
77
+			: $default;
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * @return RequestTypeContext
83
-     * @throws InvalidArgumentException
84
-     */
85
-    public function detectRequestTypeContext()
86
-    {
87
-        // Detect error scrapes
88
-        if ($this->isWordPressErrorScrape()) {
89
-            return $this->factory->create(RequestTypeContext::WP_SCRAPE);
90
-        }
91
-        // Detect activations
92
-        if ($this->isWordPressActivationRequest()) {
93
-            return $this->factory->create(RequestTypeContext::ACTIVATION);
94
-        }
95
-        // Detect EE REST API
96
-        if ($this->isEspressoRestApiRequest()) {
97
-            return $this->factory->create(RequestTypeContext::API);
98
-        }
99
-        // Detect WP REST API
100
-        if ($this->isWordPressRestApiRequest()) {
101
-            return $this->factory->create(RequestTypeContext::WP_API);
102
-        }
103
-        // Detect EE GraphQL
104
-        if ($this->isEspressoGraphQLRequest()) {
105
-            return $this->factory->create(RequestTypeContext::GQL);
106
-        }
107
-        // Detect AJAX
108
-        if ($this->getGlobalRouteCondition('DOING_AJAX', false)) {
109
-            if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) {
110
-                return $this->factory->create(RequestTypeContext::AJAX_FRONT);
111
-            }
112
-            if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) {
113
-                return $this->factory->create(RequestTypeContext::AJAX_ADMIN);
114
-            }
115
-            if ($this->request->getRequestParam('action') === 'heartbeat') {
116
-                return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT);
117
-            }
118
-            return $this->factory->create(RequestTypeContext::AJAX_OTHER);
119
-        }
120
-        // Detect WP_Cron
121
-        if ($this->isCronRequest()) {
122
-            return $this->factory->create(RequestTypeContext::CRON);
123
-        }
124
-        // Detect command line requests
125
-        if ($this->getGlobalRouteCondition('WP_CLI', false)) {
126
-            return $this->factory->create(RequestTypeContext::CLI);
127
-        }
128
-        // detect WordPress admin (ie: "Dashboard")
129
-        if ($this->getGlobalRouteCondition('is_admin', false)) {
130
-            return $this->factory->create(RequestTypeContext::ADMIN);
131
-        }
132
-        // Detect iFrames
133
-        if ($this->isIframeRoute()) {
134
-            return $this->factory->create(RequestTypeContext::IFRAME);
135
-        }
136
-        // Detect Feeds
137
-        if ($this->isFeedRequest()) {
138
-            return $this->factory->create(RequestTypeContext::FEED);
139
-        }
140
-        // and by process of elimination...
141
-        return $this->factory->create(RequestTypeContext::FRONTEND);
142
-    }
81
+	/**
82
+	 * @return RequestTypeContext
83
+	 * @throws InvalidArgumentException
84
+	 */
85
+	public function detectRequestTypeContext()
86
+	{
87
+		// Detect error scrapes
88
+		if ($this->isWordPressErrorScrape()) {
89
+			return $this->factory->create(RequestTypeContext::WP_SCRAPE);
90
+		}
91
+		// Detect activations
92
+		if ($this->isWordPressActivationRequest()) {
93
+			return $this->factory->create(RequestTypeContext::ACTIVATION);
94
+		}
95
+		// Detect EE REST API
96
+		if ($this->isEspressoRestApiRequest()) {
97
+			return $this->factory->create(RequestTypeContext::API);
98
+		}
99
+		// Detect WP REST API
100
+		if ($this->isWordPressRestApiRequest()) {
101
+			return $this->factory->create(RequestTypeContext::WP_API);
102
+		}
103
+		// Detect EE GraphQL
104
+		if ($this->isEspressoGraphQLRequest()) {
105
+			return $this->factory->create(RequestTypeContext::GQL);
106
+		}
107
+		// Detect AJAX
108
+		if ($this->getGlobalRouteCondition('DOING_AJAX', false)) {
109
+			if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) {
110
+				return $this->factory->create(RequestTypeContext::AJAX_FRONT);
111
+			}
112
+			if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) {
113
+				return $this->factory->create(RequestTypeContext::AJAX_ADMIN);
114
+			}
115
+			if ($this->request->getRequestParam('action') === 'heartbeat') {
116
+				return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT);
117
+			}
118
+			return $this->factory->create(RequestTypeContext::AJAX_OTHER);
119
+		}
120
+		// Detect WP_Cron
121
+		if ($this->isCronRequest()) {
122
+			return $this->factory->create(RequestTypeContext::CRON);
123
+		}
124
+		// Detect command line requests
125
+		if ($this->getGlobalRouteCondition('WP_CLI', false)) {
126
+			return $this->factory->create(RequestTypeContext::CLI);
127
+		}
128
+		// detect WordPress admin (ie: "Dashboard")
129
+		if ($this->getGlobalRouteCondition('is_admin', false)) {
130
+			return $this->factory->create(RequestTypeContext::ADMIN);
131
+		}
132
+		// Detect iFrames
133
+		if ($this->isIframeRoute()) {
134
+			return $this->factory->create(RequestTypeContext::IFRAME);
135
+		}
136
+		// Detect Feeds
137
+		if ($this->isFeedRequest()) {
138
+			return $this->factory->create(RequestTypeContext::FEED);
139
+		}
140
+		// and by process of elimination...
141
+		return $this->factory->create(RequestTypeContext::FRONTEND);
142
+	}
143 143
 
144 144
 
145
-    /**
146
-     * @return bool
147
-     */
148
-    private function isWordPressErrorScrape()
149
-    {
150
-        return (
151
-                   $this->request->getRequestParam('wp_scrape_key') !== null
152
-                   && $this->request->getRequestParam('wp_scrape_nonce') !== null
153
-               )
154
-               || (
155
-                   $this->request->getRequestParam('action') === 'error_scrape'
156
-                   && $this->request->getRequestParam('_wpnonce') !== null
157
-               );
158
-    }
145
+	/**
146
+	 * @return bool
147
+	 */
148
+	private function isWordPressErrorScrape()
149
+	{
150
+		return (
151
+				   $this->request->getRequestParam('wp_scrape_key') !== null
152
+				   && $this->request->getRequestParam('wp_scrape_nonce') !== null
153
+			   )
154
+			   || (
155
+				   $this->request->getRequestParam('action') === 'error_scrape'
156
+				   && $this->request->getRequestParam('_wpnonce') !== null
157
+			   );
158
+	}
159 159
 
160 160
 
161
-    /**
162
-     * @return bool
163
-     */
164
-    private function isWordPressActivationRequest()
165
-    {
166
-        $action = $this->request->getRequestParam('action');
167
-        $plugins_page_actions = [
168
-            'activate',
169
-            'activate-multi',
170
-            'activate-selected',
171
-            'deactivate',
172
-            'deactivate-multi',
173
-            'deactivate-selected',
174
-            'delete-selected',
175
-            'disable-auto-update-selected',
176
-            'enable-auto-update-selected',
177
-            'update-selected',
178
-        ];
179
-        return $this->uriPathMatches('wp-admin/plugins.php')
180
-               && ($action === 'true' || in_array($action, $plugins_page_actions, true));
181
-    }
161
+	/**
162
+	 * @return bool
163
+	 */
164
+	private function isWordPressActivationRequest()
165
+	{
166
+		$action = $this->request->getRequestParam('action');
167
+		$plugins_page_actions = [
168
+			'activate',
169
+			'activate-multi',
170
+			'activate-selected',
171
+			'deactivate',
172
+			'deactivate-multi',
173
+			'deactivate-selected',
174
+			'delete-selected',
175
+			'disable-auto-update-selected',
176
+			'enable-auto-update-selected',
177
+			'update-selected',
178
+		];
179
+		return $this->uriPathMatches('wp-admin/plugins.php')
180
+			   && ($action === 'true' || in_array($action, $plugins_page_actions, true));
181
+	}
182 182
 
183 183
 
184
-    /**
185
-     * @return bool
186
-     */
187
-    private function isEspressoRestApiRequest()
188
-    {
189
-        // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/...
190
-        return strpos(
191
-            $this->request->getRequestParam('rest_route', false),
192
-            '/' . Domain::API_NAMESPACE
193
-        ) === 0
194
-            || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE);
195
-    }
184
+	/**
185
+	 * @return bool
186
+	 */
187
+	private function isEspressoRestApiRequest()
188
+	{
189
+		// Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/...
190
+		return strpos(
191
+			$this->request->getRequestParam('rest_route', false),
192
+			'/' . Domain::API_NAMESPACE
193
+		) === 0
194
+			|| $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE);
195
+	}
196 196
 
197 197
 
198
-    /**
199
-     * Checks for URLs like https://mysite.com/graphql
200
-     *
201
-     * @return bool
202
-     */
203
-    private function isEspressoGraphQLRequest()
204
-    {
205
-        if ($this->gql_endpoint->isGraphqlRequest()) {
206
-            return true;
207
-        }
208
-        $gql_endpoint = $this->gql_endpoint->getEndpoint();
209
-        return $this->uriPathMatches($gql_endpoint) || $this->request->requestParamIsSet($gql_endpoint);
210
-    }
198
+	/**
199
+	 * Checks for URLs like https://mysite.com/graphql
200
+	 *
201
+	 * @return bool
202
+	 */
203
+	private function isEspressoGraphQLRequest()
204
+	{
205
+		if ($this->gql_endpoint->isGraphqlRequest()) {
206
+			return true;
207
+		}
208
+		$gql_endpoint = $this->gql_endpoint->getEndpoint();
209
+		return $this->uriPathMatches($gql_endpoint) || $this->request->requestParamIsSet($gql_endpoint);
210
+	}
211 211
 
212 212
 
213
-    /**
214
-     * @return bool
215
-     */
216
-    private function isWordPressRestApiRequest()
217
-    {
218
-        // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/...
219
-        return $this->request->getRequestParam('rest_route', false)
220
-               || $this->uriPathMatches(trim(rest_get_url_prefix(), '/'));
221
-    }
213
+	/**
214
+	 * @return bool
215
+	 */
216
+	private function isWordPressRestApiRequest()
217
+	{
218
+		// Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/...
219
+		return $this->request->getRequestParam('rest_route', false)
220
+			   || $this->uriPathMatches(trim(rest_get_url_prefix(), '/'));
221
+	}
222 222
 
223 223
 
224
-    /**
225
-     * @return bool
226
-     */
227
-    private function isCronRequest()
228
-    {
229
-        return $this->uriPathMatches('wp-cron.php');
230
-    }
224
+	/**
225
+	 * @return bool
226
+	 */
227
+	private function isCronRequest()
228
+	{
229
+		return $this->uriPathMatches('wp-cron.php');
230
+	}
231 231
 
232 232
 
233
-    /**
234
-     * @return bool
235
-     */
236
-    private function isFeedRequest()
237
-    {
238
-        return $this->uriPathMatches('feed');
239
-    }
233
+	/**
234
+	 * @return bool
235
+	 */
236
+	private function isFeedRequest()
237
+	{
238
+		return $this->uriPathMatches('feed');
239
+	}
240 240
 
241 241
 
242
-    /**
243
-     * @param string $component
244
-     * @return bool
245
-     */
246
-    private function uriPathMatches($component)
247
-    {
248
-        $request_uri = $this->request->requestUri(true);
249
-        $parts = explode('?', $request_uri);
250
-        $path = trim(reset($parts), '/');
251
-        return strpos($path, $component) === 0;
252
-    }
242
+	/**
243
+	 * @param string $component
244
+	 * @return bool
245
+	 */
246
+	private function uriPathMatches($component)
247
+	{
248
+		$request_uri = $this->request->requestUri(true);
249
+		$parts = explode('?', $request_uri);
250
+		$path = trim(reset($parts), '/');
251
+		return strpos($path, $component) === 0;
252
+	}
253 253
 
254 254
 
255
-    /**
256
-     * @return bool
257
-     */
258
-    private function isIframeRoute()
259
-    {
260
-        $is_iframe_route = apply_filters(
261
-            'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute',
262
-            $this->request->getRequestParam('event_list', '') === 'iframe'
263
-            || $this->request->getRequestParam('ticket_selector', '') === 'iframe'
264
-            || $this->request->getRequestParam('calendar', '') === 'iframe',
265
-            $this
266
-        );
267
-        return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN);
268
-    }
255
+	/**
256
+	 * @return bool
257
+	 */
258
+	private function isIframeRoute()
259
+	{
260
+		$is_iframe_route = apply_filters(
261
+			'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute',
262
+			$this->request->getRequestParam('event_list', '') === 'iframe'
263
+			|| $this->request->getRequestParam('ticket_selector', '') === 'iframe'
264
+			|| $this->request->getRequestParam('calendar', '') === 'iframe',
265
+			$this
266
+		);
267
+		return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN);
268
+	}
269 269
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
      */
73 73
     private function getGlobalRouteCondition(string $globalRouteCondition, $default)
74 74
     {
75
-        return isset($this->globalRouteConditions[ $globalRouteCondition ])
76
-            ? $this->globalRouteConditions[ $globalRouteCondition ]
75
+        return isset($this->globalRouteConditions[$globalRouteCondition])
76
+            ? $this->globalRouteConditions[$globalRouteCondition]
77 77
             : $default;
78 78
     }
79 79
 
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
         // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/...
190 190
         return strpos(
191 191
             $this->request->getRequestParam('rest_route', false),
192
-            '/' . Domain::API_NAMESPACE
192
+            '/'.Domain::API_NAMESPACE
193 193
         ) === 0
194
-            || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE);
194
+            || $this->uriPathMatches(trim(rest_get_url_prefix(), '/').'/'.Domain::API_NAMESPACE);
195 195
     }
196 196
 
197 197
 
Please login to merge, or discard this patch.
core/services/graphql/GraphQLEndpoint.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
 
41 41
     /**
42
-     * @return false|mixed|void
42
+     * @return string
43 43
      */
44 44
     public function getEndpoint()
45 45
     {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 
50 50
     /**
51
-     * @return mixed|void|bool
51
+     * @return boolean
52 52
      */
53 53
     public function isGraphqlRequest()
54 54
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 use EventEspresso\core\services\database\WordPressOption;
6 6
 use Throwable;
7 7
 use WPGraphQL;
8
-use WPGraphQL\Data\Config;
9 8
 use WPGraphQL\Router;
10 9
 
11 10
 /**
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -18,82 +18,82 @@
 block discarded – undo
18 18
  */
19 19
 class GraphQLEndpoint extends WordPressOption
20 20
 {
21
-    const DEFAULT_ENDPOINT = 'graphql';
21
+	const DEFAULT_ENDPOINT = 'graphql';
22 22
 
23
-    const OPTION_NAME      = 'ee-graphql-endpoint';
23
+	const OPTION_NAME      = 'ee-graphql-endpoint';
24 24
 
25
-    /**
26
-     * @var boolean
27
-     */
28
-    private $is_gql_request;
25
+	/**
26
+	 * @var boolean
27
+	 */
28
+	private $is_gql_request;
29 29
 
30 30
 
31
-    /**
32
-     * GraphQLEndpoint constructor.
33
-     */
34
-    public function __construct()
35
-    {
36
-        parent::__construct(GraphQLEndpoint::OPTION_NAME, GraphQLEndpoint::DEFAULT_ENDPOINT, true);
37
-        add_action('graphql_register_settings', [$this, 'verifyAndSetEndpoint'], 20);
38
-    }
31
+	/**
32
+	 * GraphQLEndpoint constructor.
33
+	 */
34
+	public function __construct()
35
+	{
36
+		parent::__construct(GraphQLEndpoint::OPTION_NAME, GraphQLEndpoint::DEFAULT_ENDPOINT, true);
37
+		add_action('graphql_register_settings', [$this, 'verifyAndSetEndpoint'], 20);
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * @return false|mixed|void
43
-     */
44
-    public function getEndpoint()
45
-    {
46
-        return $this->loadOption();
47
-    }
41
+	/**
42
+	 * @return false|mixed|void
43
+	 */
44
+	public function getEndpoint()
45
+	{
46
+		return $this->loadOption();
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * @return mixed|void|bool
52
-     */
53
-    public function isGraphqlRequest()
54
-    {
55
-        if (! isset($this->is_gql_request)) {
56
-            // grab the GQL endpoint that we saved in the future... wait... wut?
57
-            $endpoint = $this->getEndpoint();
58
-            if (! class_exists('WPGraphQL')) {
59
-                require_once EE_THIRD_PARTY . 'wp-graphql/src/Router.php';
60
-            }
61
-            // set our saved endpoint on the WP GQL Pouter class
62
-            // don't worry, this is a static property that they overwrite when they initialize things,
63
-            // and we are essentially getting the value from them anyways, so it should be ok (fingers crossed)
64
-            Router::$route = $endpoint;
65
-            // now call their function for checking if this is a GQL request
66
-            // because they use a bunch of filters and stuff we don't want to duplicate here
67
-            $this->is_gql_request = Router::is_graphql_http_request();
68
-        }
69
-        return $this->is_gql_request;
70
-    }
50
+	/**
51
+	 * @return mixed|void|bool
52
+	 */
53
+	public function isGraphqlRequest()
54
+	{
55
+		if (! isset($this->is_gql_request)) {
56
+			// grab the GQL endpoint that we saved in the future... wait... wut?
57
+			$endpoint = $this->getEndpoint();
58
+			if (! class_exists('WPGraphQL')) {
59
+				require_once EE_THIRD_PARTY . 'wp-graphql/src/Router.php';
60
+			}
61
+			// set our saved endpoint on the WP GQL Pouter class
62
+			// don't worry, this is a static property that they overwrite when they initialize things,
63
+			// and we are essentially getting the value from them anyways, so it should be ok (fingers crossed)
64
+			Router::$route = $endpoint;
65
+			// now call their function for checking if this is a GQL request
66
+			// because they use a bunch of filters and stuff we don't want to duplicate here
67
+			$this->is_gql_request = Router::is_graphql_http_request();
68
+		}
69
+		return $this->is_gql_request;
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * callback hooked into the graphql_register_settings action
75
-     * basically grabs the value for the 'graphql_endpoint' setting and saves it to our own WP option.
76
-     *
77
-     * i know, i know, i know...
78
-     * WHY are we saving the graphql_endpoint to a WP option if WP GraphQL is already doing the same ?!?!
79
-     *
80
-     * Because we perform our request type detection during `plugins_loaded`,
81
-     * but they don't settle on their endpoint until `after_setup_theme` has run,
82
-     * which is too late for us, so we are just going to save this separately so that we have it.
83
-     * Oh, and this will essentially recheck this value on EVERY request
84
-     * but will only update our saved value if it has actually changed
85
-     */
86
-    public function verifyAndSetEndpoint()
87
-    {
88
-        try {
89
-            $this->updateOption(
90
-                get_graphql_setting(
91
-                    'graphql_endpoint',
92
-                    apply_filters('graphql_endpoint', GraphQLEndpoint::DEFAULT_ENDPOINT)
93
-                )
94
-            );
95
-        } catch (Throwable $t) {
96
-            // eat it
97
-        }
98
-    }
73
+	/**
74
+	 * callback hooked into the graphql_register_settings action
75
+	 * basically grabs the value for the 'graphql_endpoint' setting and saves it to our own WP option.
76
+	 *
77
+	 * i know, i know, i know...
78
+	 * WHY are we saving the graphql_endpoint to a WP option if WP GraphQL is already doing the same ?!?!
79
+	 *
80
+	 * Because we perform our request type detection during `plugins_loaded`,
81
+	 * but they don't settle on their endpoint until `after_setup_theme` has run,
82
+	 * which is too late for us, so we are just going to save this separately so that we have it.
83
+	 * Oh, and this will essentially recheck this value on EVERY request
84
+	 * but will only update our saved value if it has actually changed
85
+	 */
86
+	public function verifyAndSetEndpoint()
87
+	{
88
+		try {
89
+			$this->updateOption(
90
+				get_graphql_setting(
91
+					'graphql_endpoint',
92
+					apply_filters('graphql_endpoint', GraphQLEndpoint::DEFAULT_ENDPOINT)
93
+				)
94
+			);
95
+		} catch (Throwable $t) {
96
+			// eat it
97
+		}
98
+	}
99 99
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,11 +52,11 @@
 block discarded – undo
52 52
      */
53 53
     public function isGraphqlRequest()
54 54
     {
55
-        if (! isset($this->is_gql_request)) {
55
+        if ( ! isset($this->is_gql_request)) {
56 56
             // grab the GQL endpoint that we saved in the future... wait... wut?
57 57
             $endpoint = $this->getEndpoint();
58
-            if (! class_exists('WPGraphQL')) {
59
-                require_once EE_THIRD_PARTY . 'wp-graphql/src/Router.php';
58
+            if ( ! class_exists('WPGraphQL')) {
59
+                require_once EE_THIRD_PARTY.'wp-graphql/src/Router.php';
60 60
             }
61 61
             // set our saved endpoint on the WP GQL Pouter class
62 62
             // don't worry, this is a static property that they overwrite when they initialize things,
Please login to merge, or discard this patch.
core/services/database/WordPressOption.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -15,134 +15,134 @@
 block discarded – undo
15 15
  */
16 16
 abstract class WordPressOption
17 17
 {
18
-    const NOT_SET_YET    = 'wordpress-option-value-not-yet-set';
19
-
20
-    /**
21
-     * WordPress makes it difficult to determine if an option was successfully saved or not
22
-     * which is sometimes really important to know if the information you are saving is critical.
23
-     * The following options allow us to have a better chance of knowing when an update actually failed
24
-     * or when it just didn't update because the value hasn't changed, but everything is safe.
25
-     */
26
-    const UPDATE_SUCCESS = 1;
27
-
28
-    const UPDATE_NONE    = 0;
29
-
30
-    const UPDATE_ERROR   = -1;
31
-
32
-    /**
33
-     * @var boolean
34
-     */
35
-    private $autoload;
36
-
37
-    /**
38
-     * @var mixed
39
-     */
40
-    private $default_value;
41
-
42
-    /**
43
-     * @var string
44
-     */
45
-    private $option_name;
46
-
47
-    /**
48
-     * @var mixed
49
-     */
50
-    private $value = WordPressOption::NOT_SET_YET;
51
-
52
-
53
-    /**
54
-     * WordPressOption constructor.
55
-     *
56
-     * @param bool   $autoload
57
-     * @param mixed  $default_value
58
-     * @param string $option_name
59
-     */
60
-    public function __construct(string $option_name, $default_value, bool $autoload = false)
61
-    {
62
-        $this->setAutoload($autoload);
63
-        $this->setDefaultValue($default_value);
64
-        $this->setOptionName($option_name);
65
-    }
66
-
67
-
68
-    /**
69
-     * @param bool|string $autoload
70
-     */
71
-    public function setAutoload($autoload): void
72
-    {
73
-        $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN);
74
-    }
75
-
76
-
77
-    /**
78
-     * @param mixed $default_value
79
-     */
80
-    public function setDefaultValue($default_value): void
81
-    {
82
-        $this->default_value = $default_value;
83
-    }
84
-
85
-
86
-    /**
87
-     * @param string $option_name
88
-     */
89
-    public function setOptionName(string $option_name): void
90
-    {
91
-        $this->option_name = sanitize_key($option_name);
92
-    }
93
-
94
-
95
-    /**
96
-     * @return string
97
-     */
98
-    public function getOptionName(): string
99
-    {
100
-        return $this->option_name;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return false|mixed|void
106
-     */
107
-    public function loadOption()
108
-    {
109
-        if ($this->value === WordPressOption::NOT_SET_YET) {
110
-            $this->value = get_option($this->option_name, $this->default_value);
111
-        }
112
-        return $this->value;
113
-    }
114
-
115
-
116
-    /**
117
-     * @param $value
118
-     * @return int
119
-     */
120
-    public function updateOption($value) : int
121
-    {
122
-        // don't update if value has not changed since last update
123
-        if ($value === $this->value) {
124
-            return WordPressOption::UPDATE_NONE;
125
-        }
126
-        // because the options for updating differ when adding an option for the first time
127
-        // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db
128
-        if (get_option($this->option_name, WordPressOption::NOT_SET_YET) === WordPressOption::NOT_SET_YET) {
129
-            $updated = add_option($this->option_name, $value, '', $this->autoload());
130
-        } else {
131
-            $updated = update_option($this->option_name, $value);
132
-        }
133
-        if ($updated) {
134
-            $this->value = $value;
135
-            return WordPressOption::UPDATE_SUCCESS;
136
-        }
137
-        return WordPressOption::UPDATE_ERROR;
138
-    }
139
-
140
-
141
-    /**
142
-     * @return string
143
-     */
144
-    private function autoload() : string
145
-    {
146
-        return $this->autoload ? 'yes' : 'no';
147
-    }
18
+	const NOT_SET_YET    = 'wordpress-option-value-not-yet-set';
19
+
20
+	/**
21
+	 * WordPress makes it difficult to determine if an option was successfully saved or not
22
+	 * which is sometimes really important to know if the information you are saving is critical.
23
+	 * The following options allow us to have a better chance of knowing when an update actually failed
24
+	 * or when it just didn't update because the value hasn't changed, but everything is safe.
25
+	 */
26
+	const UPDATE_SUCCESS = 1;
27
+
28
+	const UPDATE_NONE    = 0;
29
+
30
+	const UPDATE_ERROR   = -1;
31
+
32
+	/**
33
+	 * @var boolean
34
+	 */
35
+	private $autoload;
36
+
37
+	/**
38
+	 * @var mixed
39
+	 */
40
+	private $default_value;
41
+
42
+	/**
43
+	 * @var string
44
+	 */
45
+	private $option_name;
46
+
47
+	/**
48
+	 * @var mixed
49
+	 */
50
+	private $value = WordPressOption::NOT_SET_YET;
51
+
52
+
53
+	/**
54
+	 * WordPressOption constructor.
55
+	 *
56
+	 * @param bool   $autoload
57
+	 * @param mixed  $default_value
58
+	 * @param string $option_name
59
+	 */
60
+	public function __construct(string $option_name, $default_value, bool $autoload = false)
61
+	{
62
+		$this->setAutoload($autoload);
63
+		$this->setDefaultValue($default_value);
64
+		$this->setOptionName($option_name);
65
+	}
66
+
67
+
68
+	/**
69
+	 * @param bool|string $autoload
70
+	 */
71
+	public function setAutoload($autoload): void
72
+	{
73
+		$this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN);
74
+	}
75
+
76
+
77
+	/**
78
+	 * @param mixed $default_value
79
+	 */
80
+	public function setDefaultValue($default_value): void
81
+	{
82
+		$this->default_value = $default_value;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @param string $option_name
88
+	 */
89
+	public function setOptionName(string $option_name): void
90
+	{
91
+		$this->option_name = sanitize_key($option_name);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return string
97
+	 */
98
+	public function getOptionName(): string
99
+	{
100
+		return $this->option_name;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return false|mixed|void
106
+	 */
107
+	public function loadOption()
108
+	{
109
+		if ($this->value === WordPressOption::NOT_SET_YET) {
110
+			$this->value = get_option($this->option_name, $this->default_value);
111
+		}
112
+		return $this->value;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param $value
118
+	 * @return int
119
+	 */
120
+	public function updateOption($value) : int
121
+	{
122
+		// don't update if value has not changed since last update
123
+		if ($value === $this->value) {
124
+			return WordPressOption::UPDATE_NONE;
125
+		}
126
+		// because the options for updating differ when adding an option for the first time
127
+		// we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db
128
+		if (get_option($this->option_name, WordPressOption::NOT_SET_YET) === WordPressOption::NOT_SET_YET) {
129
+			$updated = add_option($this->option_name, $value, '', $this->autoload());
130
+		} else {
131
+			$updated = update_option($this->option_name, $value);
132
+		}
133
+		if ($updated) {
134
+			$this->value = $value;
135
+			return WordPressOption::UPDATE_SUCCESS;
136
+		}
137
+		return WordPressOption::UPDATE_ERROR;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @return string
143
+	 */
144
+	private function autoload() : string
145
+	{
146
+		return $this->autoload ? 'yes' : 'no';
147
+	}
148 148
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
  */
16 16
 abstract class WordPressOption
17 17
 {
18
-    const NOT_SET_YET    = 'wordpress-option-value-not-yet-set';
18
+    const NOT_SET_YET = 'wordpress-option-value-not-yet-set';
19 19
 
20 20
     /**
21 21
      * WordPress makes it difficult to determine if an option was successfully saved or not
Please login to merge, or discard this patch.
core/services/json/JsonDataHandler.php 2 patches
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -14,297 +14,297 @@
 block discarded – undo
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
-    /**
24
-     * @var string
25
-     */
26
-    private $data_type;
27
-
28
-    /**
29
-     * @var array|stdClass
30
-     */
31
-    private $decoded_data;
32
-
33
-    /**
34
-     * JSON_BIGINT_AS_STRING,
35
-     * JSON_INVALID_UTF8_IGNORE,
36
-     * JSON_INVALID_UTF8_SUBSTITUTE,
37
-     * JSON_OBJECT_AS_ARRAY,
38
-     * JSON_THROW_ON_ERROR
39
-     *
40
-     * @var int
41
-     */
42
-    private $decode_flags;
43
-
44
-    /**
45
-     * @var int
46
-     */
47
-    private $depth;
48
-
49
-    /**
50
-     * @var string
51
-     */
52
-    private $encoded_data;
53
-
54
-    /**
55
-     * JSON_FORCE_OBJECT,
56
-     * JSON_HEX_QUOT,
57
-     * JSON_HEX_TAG,
58
-     * JSON_HEX_AMP,
59
-     * JSON_HEX_APOS,
60
-     * JSON_INVALID_UTF8_IGNORE,
61
-     * JSON_INVALID_UTF8_SUBSTITUTE,
62
-     * JSON_NUMERIC_CHECK,
63
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
64
-     * JSON_PRESERVE_ZERO_FRACTION,
65
-     * JSON_PRETTY_PRINT,
66
-     * JSON_UNESCAPED_LINE_TERMINATORS,
67
-     * JSON_UNESCAPED_SLASHES,
68
-     * JSON_UNESCAPED_UNICODE,
69
-     * JSON_THROW_ON_ERROR.
70
-     *
71
-     * @var int
72
-     */
73
-    private $encode_flags;
74
-
75
-    /**
76
-     * @var int
77
-     */
78
-    private $last_error_code;
79
-
80
-    /**
81
-     * @var string
82
-     */
83
-    private $last_error_msg;
84
-
85
-
86
-    /**
87
-     * JsonDataHandler constructor.
88
-     */
89
-    public function __construct()
90
-    {
91
-        if (!defined('JSON_INVALID_UTF8_IGNORE')) {
92
-            define('JSON_INVALID_UTF8_IGNORE', 1048576);
93
-        }
94
-        if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
95
-            define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
96
-        }
97
-        if (!defined('JSON_THROW_ON_ERROR')) {
98
-            define('JSON_THROW_ON_ERROR', 4194304);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
105
-     *
106
-     * @param string $data_type
107
-     * @param int    $decode_flags
108
-     * @param int    $encode_flags
109
-     * @param int    $depth
110
-     */
111
-    public function configure(
112
-        string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
113
-        int $decode_flags = 0,
114
-        int $encode_flags = 0,
115
-        int $depth = 512
116
-    ) {
117
-        $this->setDataType($data_type);
118
-        $this->setDecodeFlags($decode_flags);
119
-        $this->setDepth($depth);
120
-        $this->setEncodeFlags($encode_flags);
121
-    }
122
-
123
-
124
-    /**
125
-     * @param string $data_type
126
-     */
127
-    public function setDataType(string $data_type): void
128
-    {
129
-        $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
130
-                           || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
131
-                           || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
132
-            ? $data_type
133
-            : JsonDataHandler::DATA_TYPE_USE_FLAGS;
134
-    }
135
-
136
-
137
-    /**
138
-     * One or more Bitmask values:
139
-     * JSON_BIGINT_AS_STRING,
140
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
141
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
142
-     * JSON_OBJECT_AS_ARRAY,
143
-     * JSON_THROW_ON_ERROR              PHP >= 7.3
144
-     *
145
-     * pass multiple values separated with |
146
-     * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
147
-     *
148
-     * @param int $decode_flags
149
-     */
150
-    public function setDecodeFlags(int $decode_flags): void
151
-    {
152
-        $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
153
-                              || $decode_flags === JSON_OBJECT_AS_ARRAY
154
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
155
-                              || $decode_flags === JSON_INVALID_UTF8_IGNORE
156
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
157
-                              || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
158
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
159
-                              || $decode_flags === JSON_THROW_ON_ERROR
160
-            ? $decode_flags
161
-            : 0;
162
-    }
163
-
164
-
165
-    /**
166
-     * @param int $depth
167
-     */
168
-    public function setDepth(int $depth): void
169
-    {
170
-        $depth = absint($depth);
171
-        $this->depth = $depth ? $depth : 512;
172
-    }
173
-
174
-
175
-    /**
176
-     * One or more Bitmask values:
177
-     * JSON_FORCE_OBJECT,
178
-     * JSON_HEX_QUOT,
179
-     * JSON_HEX_TAG,
180
-     * JSON_HEX_AMP,
181
-     * JSON_HEX_APOS,
182
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
183
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
184
-     * JSON_NUMERIC_CHECK,
185
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
186
-     * JSON_PRESERVE_ZERO_FRACTION,
187
-     * JSON_PRETTY_PRINT,
188
-     * JSON_UNESCAPED_LINE_TERMINATORS,
189
-     * JSON_UNESCAPED_SLASHES,
190
-     * JSON_UNESCAPED_UNICODE,
191
-     * JSON_THROW_ON_ERROR.             PHP >= 7.3
192
-     *
193
-     * pass multiple values separated with |
194
-     * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
195
-     *
196
-     * @param int $encode_flags
197
-     */
198
-    public function setEncodeFlags(int $encode_flags): void
199
-    {
200
-        $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
201
-                              || $encode_flags === JSON_HEX_QUOT
202
-                              || $encode_flags === JSON_HEX_TAG
203
-                              || $encode_flags === JSON_HEX_AMP
204
-                              || $encode_flags === JSON_HEX_APOS
205
-                              || $encode_flags === JSON_NUMERIC_CHECK
206
-                              || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
207
-                              || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
208
-                              || $encode_flags === JSON_PRETTY_PRINT
209
-                              || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
210
-                              || $encode_flags === JSON_UNESCAPED_SLASHES
211
-                              || $encode_flags === JSON_UNESCAPED_UNICODE
212
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
213
-                              || $encode_flags === JSON_INVALID_UTF8_IGNORE
214
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
215
-                              || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
216
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
217
-                              || $encode_flags === JSON_THROW_ON_ERROR
218
-            ? $encode_flags
219
-            : 0;
220
-    }
221
-
222
-
223
-    /**
224
-     * @return bool|null
225
-     */
226
-    private function asAssociative()
227
-    {
228
-        switch ($this->data_type) {
229
-            case JsonDataHandler::DATA_TYPE_ARRAY:
230
-                return true;
231
-            case JsonDataHandler::DATA_TYPE_OBJECT:
232
-                return false;
233
-            case JsonDataHandler::DATA_TYPE_USE_FLAGS:
234
-                return null;
235
-        }
236
-        return null;
237
-    }
238
-
239
-
240
-    /**
241
-     * @param string $json
242
-     * @return array|mixed|stdClass
243
-     */
244
-    public function decodeJson(string $json)
245
-    {
246
-        $this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
247
-        $this->last_error_code = json_last_error();
248
-        $this->last_error_msg  = json_last_error_msg();
249
-        return $this->decoded_data;
250
-    }
251
-
252
-
253
-    /**
254
-     * @param $data
255
-     * @return false|string
256
-     */
257
-    public function encodeData($data)
258
-    {
259
-        $this->encoded_data    = json_encode($data, $this->encode_flags, $this->depth);
260
-        $this->last_error_code = json_last_error();
261
-        $this->last_error_msg  = json_last_error_msg();
262
-        return $this->encoded_data;
263
-    }
264
-
265
-
266
-    /**
267
-     * @return array|stdClass
268
-     */
269
-    public function getDecodedData()
270
-    {
271
-        return $this->decoded_data;
272
-    }
273
-
274
-
275
-    /**
276
-     * @return string
277
-     */
278
-    public function getEncodedData(): string
279
-    {
280
-        return $this->encoded_data;
281
-    }
282
-
283
-
284
-    /**
285
-     * @param false $reset
286
-     * @return int
287
-     */
288
-    public function getLastErrorCode($reset = false)
289
-    {
290
-        $last_error = $this->last_error_code;
291
-        if ($reset) {
292
-            $this->last_error_code = JSON_ERROR_NONE;
293
-        }
294
-        return $last_error;
295
-    }
296
-
297
-
298
-    /**
299
-     * @param false $reset
300
-     * @return string
301
-     */
302
-    public function getLastErrorMessage($reset = false)
303
-    {
304
-        $last_error = $this->last_error_msg;
305
-        if ($reset) {
306
-            $this->last_error_msg = '';
307
-        }
308
-        return $last_error;
309
-    }
17
+	const DATA_TYPE_ARRAY     = 'array';
18
+
19
+	const DATA_TYPE_OBJECT    = 'object';
20
+
21
+	const DATA_TYPE_USE_FLAGS = 'flags';
22
+
23
+	/**
24
+	 * @var string
25
+	 */
26
+	private $data_type;
27
+
28
+	/**
29
+	 * @var array|stdClass
30
+	 */
31
+	private $decoded_data;
32
+
33
+	/**
34
+	 * JSON_BIGINT_AS_STRING,
35
+	 * JSON_INVALID_UTF8_IGNORE,
36
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
37
+	 * JSON_OBJECT_AS_ARRAY,
38
+	 * JSON_THROW_ON_ERROR
39
+	 *
40
+	 * @var int
41
+	 */
42
+	private $decode_flags;
43
+
44
+	/**
45
+	 * @var int
46
+	 */
47
+	private $depth;
48
+
49
+	/**
50
+	 * @var string
51
+	 */
52
+	private $encoded_data;
53
+
54
+	/**
55
+	 * JSON_FORCE_OBJECT,
56
+	 * JSON_HEX_QUOT,
57
+	 * JSON_HEX_TAG,
58
+	 * JSON_HEX_AMP,
59
+	 * JSON_HEX_APOS,
60
+	 * JSON_INVALID_UTF8_IGNORE,
61
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
62
+	 * JSON_NUMERIC_CHECK,
63
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
64
+	 * JSON_PRESERVE_ZERO_FRACTION,
65
+	 * JSON_PRETTY_PRINT,
66
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
67
+	 * JSON_UNESCAPED_SLASHES,
68
+	 * JSON_UNESCAPED_UNICODE,
69
+	 * JSON_THROW_ON_ERROR.
70
+	 *
71
+	 * @var int
72
+	 */
73
+	private $encode_flags;
74
+
75
+	/**
76
+	 * @var int
77
+	 */
78
+	private $last_error_code;
79
+
80
+	/**
81
+	 * @var string
82
+	 */
83
+	private $last_error_msg;
84
+
85
+
86
+	/**
87
+	 * JsonDataHandler constructor.
88
+	 */
89
+	public function __construct()
90
+	{
91
+		if (!defined('JSON_INVALID_UTF8_IGNORE')) {
92
+			define('JSON_INVALID_UTF8_IGNORE', 1048576);
93
+		}
94
+		if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
95
+			define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
96
+		}
97
+		if (!defined('JSON_THROW_ON_ERROR')) {
98
+			define('JSON_THROW_ON_ERROR', 4194304);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
105
+	 *
106
+	 * @param string $data_type
107
+	 * @param int    $decode_flags
108
+	 * @param int    $encode_flags
109
+	 * @param int    $depth
110
+	 */
111
+	public function configure(
112
+		string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
113
+		int $decode_flags = 0,
114
+		int $encode_flags = 0,
115
+		int $depth = 512
116
+	) {
117
+		$this->setDataType($data_type);
118
+		$this->setDecodeFlags($decode_flags);
119
+		$this->setDepth($depth);
120
+		$this->setEncodeFlags($encode_flags);
121
+	}
122
+
123
+
124
+	/**
125
+	 * @param string $data_type
126
+	 */
127
+	public function setDataType(string $data_type): void
128
+	{
129
+		$this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
130
+						   || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
131
+						   || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
132
+			? $data_type
133
+			: JsonDataHandler::DATA_TYPE_USE_FLAGS;
134
+	}
135
+
136
+
137
+	/**
138
+	 * One or more Bitmask values:
139
+	 * JSON_BIGINT_AS_STRING,
140
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
141
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
142
+	 * JSON_OBJECT_AS_ARRAY,
143
+	 * JSON_THROW_ON_ERROR              PHP >= 7.3
144
+	 *
145
+	 * pass multiple values separated with |
146
+	 * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
147
+	 *
148
+	 * @param int $decode_flags
149
+	 */
150
+	public function setDecodeFlags(int $decode_flags): void
151
+	{
152
+		$this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
153
+							  || $decode_flags === JSON_OBJECT_AS_ARRAY
154
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
155
+							  || $decode_flags === JSON_INVALID_UTF8_IGNORE
156
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
157
+							  || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
158
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
159
+							  || $decode_flags === JSON_THROW_ON_ERROR
160
+			? $decode_flags
161
+			: 0;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param int $depth
167
+	 */
168
+	public function setDepth(int $depth): void
169
+	{
170
+		$depth = absint($depth);
171
+		$this->depth = $depth ? $depth : 512;
172
+	}
173
+
174
+
175
+	/**
176
+	 * One or more Bitmask values:
177
+	 * JSON_FORCE_OBJECT,
178
+	 * JSON_HEX_QUOT,
179
+	 * JSON_HEX_TAG,
180
+	 * JSON_HEX_AMP,
181
+	 * JSON_HEX_APOS,
182
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
183
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
184
+	 * JSON_NUMERIC_CHECK,
185
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
186
+	 * JSON_PRESERVE_ZERO_FRACTION,
187
+	 * JSON_PRETTY_PRINT,
188
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
189
+	 * JSON_UNESCAPED_SLASHES,
190
+	 * JSON_UNESCAPED_UNICODE,
191
+	 * JSON_THROW_ON_ERROR.             PHP >= 7.3
192
+	 *
193
+	 * pass multiple values separated with |
194
+	 * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
195
+	 *
196
+	 * @param int $encode_flags
197
+	 */
198
+	public function setEncodeFlags(int $encode_flags): void
199
+	{
200
+		$this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
201
+							  || $encode_flags === JSON_HEX_QUOT
202
+							  || $encode_flags === JSON_HEX_TAG
203
+							  || $encode_flags === JSON_HEX_AMP
204
+							  || $encode_flags === JSON_HEX_APOS
205
+							  || $encode_flags === JSON_NUMERIC_CHECK
206
+							  || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
207
+							  || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
208
+							  || $encode_flags === JSON_PRETTY_PRINT
209
+							  || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
210
+							  || $encode_flags === JSON_UNESCAPED_SLASHES
211
+							  || $encode_flags === JSON_UNESCAPED_UNICODE
212
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
213
+							  || $encode_flags === JSON_INVALID_UTF8_IGNORE
214
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
215
+							  || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
216
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
217
+							  || $encode_flags === JSON_THROW_ON_ERROR
218
+			? $encode_flags
219
+			: 0;
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return bool|null
225
+	 */
226
+	private function asAssociative()
227
+	{
228
+		switch ($this->data_type) {
229
+			case JsonDataHandler::DATA_TYPE_ARRAY:
230
+				return true;
231
+			case JsonDataHandler::DATA_TYPE_OBJECT:
232
+				return false;
233
+			case JsonDataHandler::DATA_TYPE_USE_FLAGS:
234
+				return null;
235
+		}
236
+		return null;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param string $json
242
+	 * @return array|mixed|stdClass
243
+	 */
244
+	public function decodeJson(string $json)
245
+	{
246
+		$this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
247
+		$this->last_error_code = json_last_error();
248
+		$this->last_error_msg  = json_last_error_msg();
249
+		return $this->decoded_data;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @param $data
255
+	 * @return false|string
256
+	 */
257
+	public function encodeData($data)
258
+	{
259
+		$this->encoded_data    = json_encode($data, $this->encode_flags, $this->depth);
260
+		$this->last_error_code = json_last_error();
261
+		$this->last_error_msg  = json_last_error_msg();
262
+		return $this->encoded_data;
263
+	}
264
+
265
+
266
+	/**
267
+	 * @return array|stdClass
268
+	 */
269
+	public function getDecodedData()
270
+	{
271
+		return $this->decoded_data;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return string
277
+	 */
278
+	public function getEncodedData(): string
279
+	{
280
+		return $this->encoded_data;
281
+	}
282
+
283
+
284
+	/**
285
+	 * @param false $reset
286
+	 * @return int
287
+	 */
288
+	public function getLastErrorCode($reset = false)
289
+	{
290
+		$last_error = $this->last_error_code;
291
+		if ($reset) {
292
+			$this->last_error_code = JSON_ERROR_NONE;
293
+		}
294
+		return $last_error;
295
+	}
296
+
297
+
298
+	/**
299
+	 * @param false $reset
300
+	 * @return string
301
+	 */
302
+	public function getLastErrorMessage($reset = false)
303
+	{
304
+		$last_error = $this->last_error_msg;
305
+		if ($reset) {
306
+			$this->last_error_msg = '';
307
+		}
308
+		return $last_error;
309
+	}
310 310
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -88,13 +88,13 @@
 block discarded – undo
88 88
      */
89 89
     public function __construct()
90 90
     {
91
-        if (!defined('JSON_INVALID_UTF8_IGNORE')) {
91
+        if ( ! defined('JSON_INVALID_UTF8_IGNORE')) {
92 92
             define('JSON_INVALID_UTF8_IGNORE', 1048576);
93 93
         }
94
-        if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
94
+        if ( ! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
95 95
             define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
96 96
         }
97
-        if (!defined('JSON_THROW_ON_ERROR')) {
97
+        if ( ! defined('JSON_THROW_ON_ERROR')) {
98 98
             define('JSON_THROW_ON_ERROR', 4194304);
99 99
         }
100 100
     }
Please login to merge, or discard this patch.
core/services/json/JsonDataWordpressOption.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -16,87 +16,87 @@
 block discarded – undo
16 16
 abstract class JsonDataWordpressOption extends WordPressOption
17 17
 {
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    private $options;
23
-
24
-    /**
25
-     * @var JsonDataHandler
26
-     */
27
-    private $json_data_handler;
28
-
29
-
30
-    /**
31
-     * JsonDataWordpressOption constructor.
32
-     *
33
-     * @param JsonDataHandler $json_data_handler
34
-     * @param string          $option_name
35
-     * @param                 $default_value
36
-     */
37
-    public function __construct(JsonDataHandler $json_data_handler, string $option_name, $default_value)
38
-    {
39
-        $this->json_data_handler = $json_data_handler;
40
-        $this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
41
-        parent::__construct($option_name, $default_value);
42
-    }
43
-
44
-
45
-    /**
46
-     * @param $options
47
-     */
48
-    private function update($options)
49
-    {
50
-        if ($this->updateOption($this->json_data_handler->encodeData($options))) {
51
-            $this->options = $options;
52
-        }
53
-    }
54
-
55
-
56
-    /**
57
-     * @param string $property
58
-     * @param mixed  $value
59
-     * @return void
60
-     */
61
-    public function addProperty(string $property, $value)
62
-    {
63
-        $options = $this->getAll();
64
-        $options->{$property} = $value;
65
-        $this->update($options);
66
-    }
67
-
68
-
69
-    /**
70
-     * @param string $property
71
-     * @return mixed
72
-     */
73
-    public function getProperty(string $property)
74
-    {
75
-        $options = $this->getAll();
76
-        return property_exists($options, $property) ? $options->{$property} : null;
77
-    }
78
-
79
-
80
-    /**
81
-     * @return array|mixed|stdClass
82
-     */
83
-    public function getAll()
84
-    {
85
-        if (empty($this->options)) {
86
-            $this->options = $this->json_data_handler->decodeJson($this->loadOption());
87
-        }
88
-        return $this->options;
89
-    }
90
-
91
-
92
-    /**
93
-     * @param string $property
94
-     * @return void
95
-     */
96
-    public function removeProperty(string $property)
97
-    {
98
-        $options = $this->getAll();
99
-        unset($options->{$property});
100
-        $this->update($options);
101
-    }
19
+	/**
20
+	 * @var array
21
+	 */
22
+	private $options;
23
+
24
+	/**
25
+	 * @var JsonDataHandler
26
+	 */
27
+	private $json_data_handler;
28
+
29
+
30
+	/**
31
+	 * JsonDataWordpressOption constructor.
32
+	 *
33
+	 * @param JsonDataHandler $json_data_handler
34
+	 * @param string          $option_name
35
+	 * @param                 $default_value
36
+	 */
37
+	public function __construct(JsonDataHandler $json_data_handler, string $option_name, $default_value)
38
+	{
39
+		$this->json_data_handler = $json_data_handler;
40
+		$this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
41
+		parent::__construct($option_name, $default_value);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @param $options
47
+	 */
48
+	private function update($options)
49
+	{
50
+		if ($this->updateOption($this->json_data_handler->encodeData($options))) {
51
+			$this->options = $options;
52
+		}
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param string $property
58
+	 * @param mixed  $value
59
+	 * @return void
60
+	 */
61
+	public function addProperty(string $property, $value)
62
+	{
63
+		$options = $this->getAll();
64
+		$options->{$property} = $value;
65
+		$this->update($options);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param string $property
71
+	 * @return mixed
72
+	 */
73
+	public function getProperty(string $property)
74
+	{
75
+		$options = $this->getAll();
76
+		return property_exists($options, $property) ? $options->{$property} : null;
77
+	}
78
+
79
+
80
+	/**
81
+	 * @return array|mixed|stdClass
82
+	 */
83
+	public function getAll()
84
+	{
85
+		if (empty($this->options)) {
86
+			$this->options = $this->json_data_handler->decodeJson($this->loadOption());
87
+		}
88
+		return $this->options;
89
+	}
90
+
91
+
92
+	/**
93
+	 * @param string $property
94
+	 * @return void
95
+	 */
96
+	public function removeProperty(string $property)
97
+	{
98
+		$options = $this->getAll();
99
+		unset($options->{$property});
100
+		$this->update($options);
101
+	}
102 102
 }
Please login to merge, or discard this patch.
core/services/request/middleware/SetRequestTypeContextChecker.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -20,47 +20,47 @@
 block discarded – undo
20 20
 class SetRequestTypeContextChecker extends Middleware
21 21
 {
22 22
 
23
-    /**
24
-     * converts a Request to a Response
25
-     *
26
-     * @param RequestInterface  $request
27
-     * @param ResponseInterface $response
28
-     * @return ResponseInterface
29
-     * @throws InvalidArgumentException
30
-     */
31
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
32
-    {
33
-        $this->request = $request;
34
-        $this->response = $response;
35
-        /** @var GraphQLEndpoint $gql_endpoint */
36
-        $gql_endpoint = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLEndpoint');
37
-        /** @var RequestTypeContextFactoryInterface $request_type_context_factory */
38
-        $request_type_context_factory = $this->loader->getShared(
39
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
40
-            [$this->loader]
41
-        );
42
-        /** @var RequestTypeContextDetector $request_type_context_detector */
43
-        $request_type_context_detector = $this->loader->getShared(
44
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
45
-            [
46
-                $gql_endpoint,
47
-                $this->request,
48
-                $request_type_context_factory,
49
-                [
50
-                    'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX,
51
-                    'WP_CLI'     => defined('WP_CLI') && WP_CLI,
52
-                    'is_admin'   => is_admin(),
53
-                ],
54
-            ]
55
-        );
56
-        $request_type_context = $request_type_context_detector->detectRequestTypeContext();
57
-        $request_type_context->setIsUnitTesting(defined('EE_TESTS_DIR'));
58
-        $request_type_context_checker = $this->loader->getShared(
59
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
60
-            [$request_type_context]
61
-        );
62
-        $this->request->setRequestTypeContextChecker($request_type_context_checker);
63
-        $this->response = $this->processRequestStack($this->request, $this->response);
64
-        return $this->response;
65
-    }
23
+	/**
24
+	 * converts a Request to a Response
25
+	 *
26
+	 * @param RequestInterface  $request
27
+	 * @param ResponseInterface $response
28
+	 * @return ResponseInterface
29
+	 * @throws InvalidArgumentException
30
+	 */
31
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
32
+	{
33
+		$this->request = $request;
34
+		$this->response = $response;
35
+		/** @var GraphQLEndpoint $gql_endpoint */
36
+		$gql_endpoint = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLEndpoint');
37
+		/** @var RequestTypeContextFactoryInterface $request_type_context_factory */
38
+		$request_type_context_factory = $this->loader->getShared(
39
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
40
+			[$this->loader]
41
+		);
42
+		/** @var RequestTypeContextDetector $request_type_context_detector */
43
+		$request_type_context_detector = $this->loader->getShared(
44
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
45
+			[
46
+				$gql_endpoint,
47
+				$this->request,
48
+				$request_type_context_factory,
49
+				[
50
+					'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX,
51
+					'WP_CLI'     => defined('WP_CLI') && WP_CLI,
52
+					'is_admin'   => is_admin(),
53
+				],
54
+			]
55
+		);
56
+		$request_type_context = $request_type_context_detector->detectRequestTypeContext();
57
+		$request_type_context->setIsUnitTesting(defined('EE_TESTS_DIR'));
58
+		$request_type_context_checker = $this->loader->getShared(
59
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
60
+			[$request_type_context]
61
+		);
62
+		$this->request->setRequestTypeContextChecker($request_type_context_checker);
63
+		$this->response = $this->processRequestStack($this->request, $this->response);
64
+		return $this->response;
65
+	}
66 66
 }
Please login to merge, or discard this patch.