Completed
Branch new-admin-design (7f58b2)
by
unknown
02:54
created
core/domain/services/converters/json/DatetimeToJson.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         $jsonDates = [];
38 38
         foreach ($datetimes as $datetime) {
39 39
             if ($datetime instanceof EE_Datetime) {
40
-                $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
40
+                $jsonDates[$datetime->ID()] = $this->convertAndEncode($datetime);
41 41
             }
42 42
         }
43 43
         return $jsonDates;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $arrayOfDates = [];
76 76
         foreach ($datetimes as $datetime) {
77 77
             if ($datetime instanceof EE_Datetime) {
78
-                $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
78
+                $arrayOfDates[$datetime->ID()] = $this->convert($datetime);
79 79
             }
80 80
         }
81 81
         return $arrayOfDates;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $jsonDates = [];
128 128
         foreach ($datetimes as $datetime) {
129 129
             if ($datetime instanceof EE_Datetime) {
130
-                $jsonDates[ $datetime->ID() ] = $this->encode($datetime);
130
+                $jsonDates[$datetime->ID()] = $this->encode($datetime);
131 131
             }
132 132
         }
133 133
         return $jsonDates;
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -22,125 +22,125 @@
 block discarded – undo
22 22
 class DatetimeToJson implements ModelObjectToJsonConverterInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @param EE_Datetime[] $datetimes
27
-     * @return array
28
-     * @throws EE_Error
29
-     * @throws InvalidArgumentException
30
-     * @throws InvalidDataTypeException
31
-     * @throws InvalidInterfaceException
32
-     * @throws ReflectionException
33
-     * @since $VID:$
34
-     */
35
-    public function convertAndEncodeArrayOf(array $datetimes)
36
-    {
37
-        $jsonDates = [];
38
-        foreach ($datetimes as $datetime) {
39
-            if ($datetime instanceof EE_Datetime) {
40
-                $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
41
-            }
42
-        }
43
-        return $jsonDates;
44
-    }
25
+	/**
26
+	 * @param EE_Datetime[] $datetimes
27
+	 * @return array
28
+	 * @throws EE_Error
29
+	 * @throws InvalidArgumentException
30
+	 * @throws InvalidDataTypeException
31
+	 * @throws InvalidInterfaceException
32
+	 * @throws ReflectionException
33
+	 * @since $VID:$
34
+	 */
35
+	public function convertAndEncodeArrayOf(array $datetimes)
36
+	{
37
+		$jsonDates = [];
38
+		foreach ($datetimes as $datetime) {
39
+			if ($datetime instanceof EE_Datetime) {
40
+				$jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
41
+			}
42
+		}
43
+		return $jsonDates;
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * @param EE_Datetime $datetime
49
-     * @return false|string
50
-     * @throws EE_Error
51
-     * @throws InvalidArgumentException
52
-     * @throws InvalidDataTypeException
53
-     * @throws InvalidInterfaceException
54
-     * @throws ReflectionException
55
-     * @since $VID:$
56
-     */
57
-    public function convertAndEncode($datetime)
58
-    {
59
-        return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false;
60
-    }
47
+	/**
48
+	 * @param EE_Datetime $datetime
49
+	 * @return false|string
50
+	 * @throws EE_Error
51
+	 * @throws InvalidArgumentException
52
+	 * @throws InvalidDataTypeException
53
+	 * @throws InvalidInterfaceException
54
+	 * @throws ReflectionException
55
+	 * @since $VID:$
56
+	 */
57
+	public function convertAndEncode($datetime)
58
+	{
59
+		return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @param EE_Datetime[] $datetimes
65
-     * @return array
66
-     * @throws EE_Error
67
-     * @throws InvalidArgumentException
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     * @throws ReflectionException
71
-     * @since $VID:$
72
-     */
73
-    public function convertArrayOf(array $datetimes)
74
-    {
75
-        $arrayOfDates = [];
76
-        foreach ($datetimes as $datetime) {
77
-            if ($datetime instanceof EE_Datetime) {
78
-                $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
79
-            }
80
-        }
81
-        return $arrayOfDates;
82
-    }
63
+	/**
64
+	 * @param EE_Datetime[] $datetimes
65
+	 * @return array
66
+	 * @throws EE_Error
67
+	 * @throws InvalidArgumentException
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws ReflectionException
71
+	 * @since $VID:$
72
+	 */
73
+	public function convertArrayOf(array $datetimes)
74
+	{
75
+		$arrayOfDates = [];
76
+		foreach ($datetimes as $datetime) {
77
+			if ($datetime instanceof EE_Datetime) {
78
+				$arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
79
+			}
80
+		}
81
+		return $arrayOfDates;
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * @param EE_Datetime $datetime
87
-     * @return array
88
-     * @throws EE_Error
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @throws InvalidArgumentException
92
-     * @throws ReflectionException
93
-     * @since $VID:$
94
-     */
95
-    public function convert($datetime)
96
-    {
97
-        return $datetime instanceof EE_Datetime ? [
98
-            'DTT_ID'          => $datetime->ID(),
99
-            'EVT_ID'          => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0,
100
-            'DTT_name'        => $datetime->name(),
101
-            'DTT_description' => $datetime->description(),
102
-            'DTT_EVT_start'   => $datetime->start_date(DATE_ATOM),
103
-            'DTT_EVT_end'     => $datetime->end_date(DATE_ATOM),
104
-            'DTT_sold'        => $datetime->sold(),
105
-            'DTT_reserved'    => $datetime->reserved(),
106
-            'DTT_reg_limit'   => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(),
107
-            'DTT_is_primary'  => $datetime->get_active_status(),
108
-            'DTT_order'       => $datetime->order(),
109
-            'DTT_parent'      => $datetime->parent(),
110
-            'DTT_deleted'     => $datetime->get('DTT_deleted'),
111
-        ] : [];
112
-    }
85
+	/**
86
+	 * @param EE_Datetime $datetime
87
+	 * @return array
88
+	 * @throws EE_Error
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @throws InvalidArgumentException
92
+	 * @throws ReflectionException
93
+	 * @since $VID:$
94
+	 */
95
+	public function convert($datetime)
96
+	{
97
+		return $datetime instanceof EE_Datetime ? [
98
+			'DTT_ID'          => $datetime->ID(),
99
+			'EVT_ID'          => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0,
100
+			'DTT_name'        => $datetime->name(),
101
+			'DTT_description' => $datetime->description(),
102
+			'DTT_EVT_start'   => $datetime->start_date(DATE_ATOM),
103
+			'DTT_EVT_end'     => $datetime->end_date(DATE_ATOM),
104
+			'DTT_sold'        => $datetime->sold(),
105
+			'DTT_reserved'    => $datetime->reserved(),
106
+			'DTT_reg_limit'   => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(),
107
+			'DTT_is_primary'  => $datetime->get_active_status(),
108
+			'DTT_order'       => $datetime->order(),
109
+			'DTT_parent'      => $datetime->parent(),
110
+			'DTT_deleted'     => $datetime->get('DTT_deleted'),
111
+		] : [];
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * @param EE_Datetime[] $datetimes
117
-     * @return array
118
-     * @throws EE_Error
119
-     * @throws InvalidArgumentException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     * @throws ReflectionException
123
-     * @since $VID:$
124
-     */
125
-    public function encodeArrayOf(array $datetimes)
126
-    {
127
-        $jsonDates = [];
128
-        foreach ($datetimes as $datetime) {
129
-            if ($datetime instanceof EE_Datetime) {
130
-                $jsonDates[ $datetime->ID() ] = $this->encode($datetime);
131
-            }
132
-        }
133
-        return $jsonDates;
134
-    }
115
+	/**
116
+	 * @param EE_Datetime[] $datetimes
117
+	 * @return array
118
+	 * @throws EE_Error
119
+	 * @throws InvalidArgumentException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 * @throws ReflectionException
123
+	 * @since $VID:$
124
+	 */
125
+	public function encodeArrayOf(array $datetimes)
126
+	{
127
+		$jsonDates = [];
128
+		foreach ($datetimes as $datetime) {
129
+			if ($datetime instanceof EE_Datetime) {
130
+				$jsonDates[ $datetime->ID() ] = $this->encode($datetime);
131
+			}
132
+		}
133
+		return $jsonDates;
134
+	}
135 135
 
136 136
 
137
-    /**
138
-     * @param array $datetime_array
139
-     * @return false|string
140
-     * @since $VID:$
141
-     */
142
-    public function encode(array $datetime_array)
143
-    {
144
-        return wp_json_encode($datetime_array);
145
-    }
137
+	/**
138
+	 * @param array $datetime_array
139
+	 * @return false|string
140
+	 * @since $VID:$
141
+	 */
142
+	public function encode(array $datetime_array)
143
+	{
144
+		return wp_json_encode($datetime_array);
145
+	}
146 146
 }
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
         $version = ''
177 177
     ) {
178 178
         $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
179
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
180 180
         return $this->addJavascript(
181 181
             $handle,
182 182
             "{$vendor_path}{$handle}{$dev_suffix}.js",
Please login to merge, or discard this patch.
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -23,332 +23,332 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection|Asset[] $assets
28
-     */
29
-    protected $assets;
30
-
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
35
-
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
40
-
41
-
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        $this->registry->addAssetCollection($assets);
55
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return AssetCollection
62
-     */
63
-    public function getAssets()
64
-    {
65
-        return $this->assets;
66
-    }
67
-
68
-
69
-    /**
70
-     * @since 4.9.71.p
71
-     * @return string
72
-     */
73
-    public function assetNamespace()
74
-    {
75
-        return $this->domain->assetNamespace();
76
-    }
77
-
78
-
79
-    /**
80
-     * @param string $handle
81
-     * @param string $source
82
-     * @param array  $dependencies
83
-     * @param bool   $load_in_footer
84
-     * @param string $version
85
-     * @return JavascriptAsset
86
-     * @throws DuplicateCollectionIdentifierException
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidEntityException
89
-     * @throws DomainException
90
-     * @since 4.9.62.p
91
-     */
92
-    public function addJavascript(
93
-        $handle,
94
-        $source,
95
-        array $dependencies = array(),
96
-        $load_in_footer = true,
97
-        $version = ''
98
-    ) {
99
-        $asset = new JavascriptAsset(
100
-            $handle,
101
-            $source,
102
-            array_unique($dependencies),
103
-            $load_in_footer,
104
-            $this->domain,
105
-            $version
106
-        );
107
-        $this->assets->add($asset, $handle);
108
-        return $asset;
109
-    }
110
-
111
-
112
-    /**
113
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
-     *
115
-     * @param string       $handle
116
-     * @param string|array $extra_dependencies
117
-     * @return JavascriptAsset
118
-     * @throws DuplicateCollectionIdentifierException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidEntityException
121
-     * @throws DomainException
122
-     */
123
-    public function addJs($handle, $extra_dependencies = [])
124
-    {
125
-        $details = $this->getAssetDetails(
126
-            Asset::TYPE_JS,
127
-            $handle,
128
-            $extra_dependencies
129
-        );
130
-        $source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
-        return $this->addJavascript(
132
-            $handle,
133
-            $source,
134
-            $details['dependencies'],
135
-            true,
136
-            $details['version']
137
-        );
138
-    }
139
-
140
-
141
-    /**
142
-     * @param string $handle
143
-     * @param array  $dependencies
144
-     * @param bool   $load_in_footer
145
-     * @param string $version
146
-     * @return JavascriptAsset
147
-     * @throws DomainException
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @since 4.9.71.p
152
-     */
153
-    public function addVendorJavascript(
154
-        $handle,
155
-        array $dependencies = array(),
156
-        $load_in_footer = true,
157
-        $version = ''
158
-    ) {
159
-        $dev_suffix = wp_scripts_get_suffix('dev');
160
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
-        return $this->addJavascript(
162
-            $handle,
163
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
164
-            $dependencies,
165
-            $load_in_footer,
166
-            $version
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * @param string $handle
173
-     * @param string $source
174
-     * @param array  $dependencies
175
-     * @param string $media
176
-     * @param string $version
177
-     * @return StylesheetAsset
178
-     * @throws DomainException
179
-     * @throws DuplicateCollectionIdentifierException
180
-     * @throws InvalidDataTypeException
181
-     * @throws InvalidEntityException
182
-     * @since 4.9.62.p
183
-     */
184
-    public function addStylesheet(
185
-        $handle,
186
-        $source,
187
-        array $dependencies = array(),
188
-        $media = 'all',
189
-        $version = ''
190
-    ) {
191
-        $asset = new StylesheetAsset(
192
-            $handle,
193
-            $source,
194
-            array_unique($dependencies),
195
-            $this->domain,
196
-            $media,
197
-            $version
198
-        );
199
-        $this->assets->add($asset, $handle);
200
-        return $asset;
201
-    }
202
-
203
-
204
-    /**
205
-     * Used to register a css asset where everything is dynamically derived from the given handle.
206
-     *
207
-     * @param string       $handle
208
-     * @param string|array $extra_dependencies
209
-     * @return StylesheetAsset
210
-     * @throws DuplicateCollectionIdentifierException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidEntityException
213
-     * @throws DomainException
214
-     */
215
-    public function addCss($handle, $extra_dependencies = [])
216
-    {
217
-        $details = $this->getAssetDetails(
218
-            Asset::TYPE_CSS,
219
-            $handle,
220
-            $extra_dependencies
221
-        );
222
-        return $this->addStylesheet(
223
-            $handle,
224
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
-            $details['dependencies'],
226
-            'all',
227
-            $details['version']
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * @param string $handle
234
-     * @return bool
235
-     * @since 4.9.62.p
236
-     */
237
-    public function enqueueAsset($handle)
238
-    {
239
-        if ($this->assets->has($handle)) {
240
-            /** @var Asset $asset */
241
-            $asset = $this->assets->get($handle);
242
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
-                $asset->enqueueAsset();
244
-                return true;
245
-            }
246
-        }
247
-        return false;
248
-    }
249
-
250
-
251
-    /**
252
-     * @return  void
253
-     * @since   $VID:$
254
-     */
255
-    public function enqueueBrowserAssets()
256
-    {
257
-        foreach ($this->assets as $asset) {
258
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
-                $asset->enqueueAsset();
260
-            }
261
-        }
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $asset_type
267
-     * @param string $handle
268
-     * @param array  $extra_dependencies
269
-     * @return array
270
-     * @since 4.10.2.p
271
-     */
272
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
-    {
274
-        $getAssetDetails = '';
275
-        switch ($asset_type) {
276
-            case Asset::TYPE_JS :
277
-                $getAssetDetails = 'getJsAssetDetails';
278
-                break;
279
-            case Asset::TYPE_CSS :
280
-                $getAssetDetails = 'getCssAssetDetails';
281
-                break;
282
-        }
283
-        if ($getAssetDetails === '') {
284
-            return ['dependencies' => [], 'version' => ''];
285
-        }
286
-        $details = $this->registry->$getAssetDetails(
287
-            $this->domain->assetNamespace(),
288
-            $handle
289
-        );
290
-        $details['dependencies'] = isset($details['dependencies'])
291
-            ? $details['dependencies']
292
-            : [];
293
-        $details['version'] = isset($details['version'])
294
-            ? $details['version']
295
-            : '';
296
-        $details['dependencies'] = ! empty($extra_dependencies)
297
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
298
-            : $details['dependencies'];
299
-        return $details;
300
-
301
-    }
302
-
303
-
304
-    /**
305
-     * @param string $handle
306
-     * @return bool
307
-     * @throws DomainException
308
-     */
309
-    public function verifyAssetIsRegistered($handle)
310
-    {
311
-        if (wp_script_is($handle, 'registered')) {
312
-            return true;
313
-        }
314
-        if (WP_DEBUG) {
315
-            throw new DomainException(
316
-                sprintf(
317
-                    esc_html__(
318
-                        'The "%1$s" script is not registered when it should be!%2$s
26
+	/**
27
+	 * @var AssetCollection|Asset[] $assets
28
+	 */
29
+	protected $assets;
30
+
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35
+
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40
+
41
+
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		$this->registry->addAssetCollection($assets);
55
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return AssetCollection
62
+	 */
63
+	public function getAssets()
64
+	{
65
+		return $this->assets;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @since 4.9.71.p
71
+	 * @return string
72
+	 */
73
+	public function assetNamespace()
74
+	{
75
+		return $this->domain->assetNamespace();
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param string $handle
81
+	 * @param string $source
82
+	 * @param array  $dependencies
83
+	 * @param bool   $load_in_footer
84
+	 * @param string $version
85
+	 * @return JavascriptAsset
86
+	 * @throws DuplicateCollectionIdentifierException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidEntityException
89
+	 * @throws DomainException
90
+	 * @since 4.9.62.p
91
+	 */
92
+	public function addJavascript(
93
+		$handle,
94
+		$source,
95
+		array $dependencies = array(),
96
+		$load_in_footer = true,
97
+		$version = ''
98
+	) {
99
+		$asset = new JavascriptAsset(
100
+			$handle,
101
+			$source,
102
+			array_unique($dependencies),
103
+			$load_in_footer,
104
+			$this->domain,
105
+			$version
106
+		);
107
+		$this->assets->add($asset, $handle);
108
+		return $asset;
109
+	}
110
+
111
+
112
+	/**
113
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
+	 *
115
+	 * @param string       $handle
116
+	 * @param string|array $extra_dependencies
117
+	 * @return JavascriptAsset
118
+	 * @throws DuplicateCollectionIdentifierException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidEntityException
121
+	 * @throws DomainException
122
+	 */
123
+	public function addJs($handle, $extra_dependencies = [])
124
+	{
125
+		$details = $this->getAssetDetails(
126
+			Asset::TYPE_JS,
127
+			$handle,
128
+			$extra_dependencies
129
+		);
130
+		$source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
+		return $this->addJavascript(
132
+			$handle,
133
+			$source,
134
+			$details['dependencies'],
135
+			true,
136
+			$details['version']
137
+		);
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param string $handle
143
+	 * @param array  $dependencies
144
+	 * @param bool   $load_in_footer
145
+	 * @param string $version
146
+	 * @return JavascriptAsset
147
+	 * @throws DomainException
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @since 4.9.71.p
152
+	 */
153
+	public function addVendorJavascript(
154
+		$handle,
155
+		array $dependencies = array(),
156
+		$load_in_footer = true,
157
+		$version = ''
158
+	) {
159
+		$dev_suffix = wp_scripts_get_suffix('dev');
160
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
+		return $this->addJavascript(
162
+			$handle,
163
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
164
+			$dependencies,
165
+			$load_in_footer,
166
+			$version
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param string $handle
173
+	 * @param string $source
174
+	 * @param array  $dependencies
175
+	 * @param string $media
176
+	 * @param string $version
177
+	 * @return StylesheetAsset
178
+	 * @throws DomainException
179
+	 * @throws DuplicateCollectionIdentifierException
180
+	 * @throws InvalidDataTypeException
181
+	 * @throws InvalidEntityException
182
+	 * @since 4.9.62.p
183
+	 */
184
+	public function addStylesheet(
185
+		$handle,
186
+		$source,
187
+		array $dependencies = array(),
188
+		$media = 'all',
189
+		$version = ''
190
+	) {
191
+		$asset = new StylesheetAsset(
192
+			$handle,
193
+			$source,
194
+			array_unique($dependencies),
195
+			$this->domain,
196
+			$media,
197
+			$version
198
+		);
199
+		$this->assets->add($asset, $handle);
200
+		return $asset;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
206
+	 *
207
+	 * @param string       $handle
208
+	 * @param string|array $extra_dependencies
209
+	 * @return StylesheetAsset
210
+	 * @throws DuplicateCollectionIdentifierException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidEntityException
213
+	 * @throws DomainException
214
+	 */
215
+	public function addCss($handle, $extra_dependencies = [])
216
+	{
217
+		$details = $this->getAssetDetails(
218
+			Asset::TYPE_CSS,
219
+			$handle,
220
+			$extra_dependencies
221
+		);
222
+		return $this->addStylesheet(
223
+			$handle,
224
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
+			$details['dependencies'],
226
+			'all',
227
+			$details['version']
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param string $handle
234
+	 * @return bool
235
+	 * @since 4.9.62.p
236
+	 */
237
+	public function enqueueAsset($handle)
238
+	{
239
+		if ($this->assets->has($handle)) {
240
+			/** @var Asset $asset */
241
+			$asset = $this->assets->get($handle);
242
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
+				$asset->enqueueAsset();
244
+				return true;
245
+			}
246
+		}
247
+		return false;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @return  void
253
+	 * @since   $VID:$
254
+	 */
255
+	public function enqueueBrowserAssets()
256
+	{
257
+		foreach ($this->assets as $asset) {
258
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
+				$asset->enqueueAsset();
260
+			}
261
+		}
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $asset_type
267
+	 * @param string $handle
268
+	 * @param array  $extra_dependencies
269
+	 * @return array
270
+	 * @since 4.10.2.p
271
+	 */
272
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
+	{
274
+		$getAssetDetails = '';
275
+		switch ($asset_type) {
276
+			case Asset::TYPE_JS :
277
+				$getAssetDetails = 'getJsAssetDetails';
278
+				break;
279
+			case Asset::TYPE_CSS :
280
+				$getAssetDetails = 'getCssAssetDetails';
281
+				break;
282
+		}
283
+		if ($getAssetDetails === '') {
284
+			return ['dependencies' => [], 'version' => ''];
285
+		}
286
+		$details = $this->registry->$getAssetDetails(
287
+			$this->domain->assetNamespace(),
288
+			$handle
289
+		);
290
+		$details['dependencies'] = isset($details['dependencies'])
291
+			? $details['dependencies']
292
+			: [];
293
+		$details['version'] = isset($details['version'])
294
+			? $details['version']
295
+			: '';
296
+		$details['dependencies'] = ! empty($extra_dependencies)
297
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
298
+			: $details['dependencies'];
299
+		return $details;
300
+
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param string $handle
306
+	 * @return bool
307
+	 * @throws DomainException
308
+	 */
309
+	public function verifyAssetIsRegistered($handle)
310
+	{
311
+		if (wp_script_is($handle, 'registered')) {
312
+			return true;
313
+		}
314
+		if (WP_DEBUG) {
315
+			throw new DomainException(
316
+				sprintf(
317
+					esc_html__(
318
+						'The "%1$s" script is not registered when it should be!%2$s
319 319
                         Are you running the Barista plugin for development purposes? 
320 320
                         If so, then you need to build the appropriate assets for this domain.%2$s
321 321
                         If you are seeing this error on a live website, then you should not have 
322 322
                         the WP_DEBUG constant in your wp-config.php file set to "true". 
323 323
                         Please contact Event Espresso support for more information.',
324
-                        'event_espresso'
325
-                    ),
326
-                    $handle,
327
-                    '<br />'
328
-                )
329
-            );
330
-        }
331
-        return false;
332
-    }
333
-
334
-
335
-    /**************** deprecated ****************/
336
-
337
-
338
-    /**
339
-     * @return void
340
-     * @deprecated $VID:$
341
-     */
342
-    public function addManifestFile()
343
-    {
344
-    }
345
-
346
-
347
-    /**
348
-     * @return void
349
-     * @deprecated $VID:$
350
-     */
351
-    public function getManifestFile()
352
-    {
353
-    }
324
+						'event_espresso'
325
+					),
326
+					$handle,
327
+					'<br />'
328
+				)
329
+			);
330
+		}
331
+		return false;
332
+	}
333
+
334
+
335
+	/**************** deprecated ****************/
336
+
337
+
338
+	/**
339
+	 * @return void
340
+	 * @deprecated $VID:$
341
+	 */
342
+	public function addManifestFile()
343
+	{
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return void
349
+	 * @deprecated $VID:$
350
+	 */
351
+	public function getManifestFile()
352
+	{
353
+	}
354 354
 }
Please login to merge, or discard this patch.
core/services/graphql/fields/GraphQLField.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     public function shouldResolve()
136 136
     {
137 137
         foreach ($this->caps as $cap) {
138
-            if (! current_user_can($cap)) {
138
+            if ( ! current_user_can($cap)) {
139 139
                 return false;
140 140
             }
141 141
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
168 168
     {
169
-        if (! $this->hasInternalResolver()) {
169
+        if ( ! $this->hasInternalResolver()) {
170 170
             throw new LogicException('GraphQLField has no internal resolver.');
171 171
         }
172 172
         // dynamic methods using $this don't play nice
Please login to merge, or discard this patch.
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -20,262 +20,262 @@
 block discarded – undo
20 20
 class GraphQLField implements GraphQLFieldInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var string $name
25
-     */
26
-    protected $name;
27
-
28
-    /**
29
-     * @var string|string[] $type
30
-     */
31
-    protected $type;
32
-
33
-    /**
34
-     * @var string|null $key
35
-     */
36
-    protected $key;
37
-
38
-    /**
39
-     * @var string $description
40
-     */
41
-    protected $description;
42
-
43
-    /**
44
-     * @var callable $formatter
45
-     */
46
-    protected $formatter;
47
-
48
-    /**
49
-     * @var callable $resolve
50
-     */
51
-    protected $resolver;
52
-
53
-    /**
54
-     * @var array $caps
55
-     */
56
-    protected $caps;
57
-
58
-    /**
59
-     * @var array $args
60
-     */
61
-    protected $args;
62
-
63
-    /**
64
-     * @var bool $use_for_input
65
-     */
66
-    protected $use_for_input = true;
67
-
68
-    /**
69
-     * @var bool $use_for_output
70
-     */
71
-    protected $use_for_output = true;
72
-
73
-
74
-    /**
75
-     * @param string          $name
76
-     * @param string|string[] $type
77
-     * @param string|null     $key
78
-     * @param string          $description
79
-     * @param callable|null   $formatter
80
-     * @param callable|null   $resolver
81
-     * @param array           $args
82
-     * @param array           $caps
83
-     * @param array           $args
84
-     */
85
-    public function __construct(
86
-        $name,
87
-        $type,
88
-        $key = null,
89
-        $description = '',
90
-        callable $formatter = null,
91
-        callable $resolver = null,
92
-        array $caps = [],
93
-        array $args = []
94
-    ) {
95
-        $this->name = $name;
96
-        $this->type = $type;
97
-        $this->key = $key;
98
-        $this->description = $description;
99
-        $this->formatter = $formatter;
100
-        $this->resolver = $resolver;
101
-        $this->caps = $caps;
102
-        $this->args = $args;
103
-    }
104
-
105
-
106
-    /**
107
-     * @return array
108
-     */
109
-    public function caps()
110
-    {
111
-        return $this->caps;
112
-    }
113
-
114
-
115
-    /**
116
-     * @return string
117
-     */
118
-    public function description()
119
-    {
120
-        return $this->description;
121
-    }
122
-
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function key()
128
-    {
129
-        return $this->key;
130
-    }
131
-
132
-
133
-    /**
134
-     * @return string
135
-     */
136
-    public function name()
137
-    {
138
-        return $this->name;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return string|string[]
144
-     */
145
-    public function type()
146
-    {
147
-        return $this->type;
148
-    }
149
-
150
-
151
-    /**
152
-     * Convert the field to array to be
153
-     * able to pass as config to WP GraphQL
154
-     *
155
-     * @return array
156
-     */
157
-    public function toArray()
158
-    {
159
-        return get_object_vars($this);
160
-    }
161
-
162
-
163
-    /**
164
-     * Sets the value for use_for_input.
165
-     *
166
-     * @param bool $use_for_input
167
-     */
168
-    protected function setUseForInput($use_for_input)
169
-    {
170
-        $this->use_for_input = filter_var($use_for_input, FILTER_VALIDATE_BOOLEAN);
171
-    }
172
-
173
-
174
-    /**
175
-     * Whether the field should be used for
176
-     * mutation inputs.
177
-     *
178
-     * @return bool
179
-     */
180
-    public function useForInput()
181
-    {
182
-        return (bool) $this->use_for_input;
183
-    }
184
-
185
-
186
-    /**
187
-     * Whether the field should be used for
188
-     * query outputs.
189
-     *
190
-     * @return bool
191
-     */
192
-    public function useForOutput()
193
-    {
194
-        return (bool) $this->use_for_output;
195
-    }
196
-
197
-
198
-    /**
199
-     * Sets the value for use_for_output
200
-     *
201
-     * @param bool $use_for_output
202
-     */
203
-    protected function setUseForOutput($use_for_output)
204
-    {
205
-        $this->use_for_output = filter_var($use_for_output, FILTER_VALIDATE_BOOLEAN);
206
-    }
207
-
208
-
209
-    /**
210
-     * Whether the field should resolve
211
-     * based on the user caps etc.
212
-     *
213
-     * @return boolean
214
-     */
215
-    public function shouldResolve()
216
-    {
217
-        foreach ($this->caps as $cap) {
218
-            if (! current_user_can($cap)) {
219
-                return false;
220
-            }
221
-        }
222
-        return true;
223
-    }
224
-
225
-
226
-    /**
227
-     * Whether the field has an explicit resolver set.
228
-     *
229
-     * @return boolean
230
-     */
231
-    public function hasInternalResolver()
232
-    {
233
-        return is_callable($this->resolver);
234
-    }
235
-
236
-
237
-    /**
238
-     * Whether the field has an explicit resolver set.
239
-     *
240
-     * @param mixed       $source  The source that's passed down the GraphQL queries
241
-     * @param array       $args    The inputArgs on the field
242
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
243
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
244
-     * @return mixed
245
-     * @throws LogicException
246
-     */
247
-    public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
248
-    {
249
-        if (! $this->hasInternalResolver()) {
250
-            throw new LogicException('GraphQLField has no internal resolver.');
251
-        }
252
-        // dynamic methods using $this don't play nice
253
-        // so capture resolver to a single var first
254
-        $resolver = $this->resolver;
255
-        return $resolver($source, $args, $context, $info);
256
-    }
257
-
258
-
259
-    /**
260
-     * Checks if the format callback is set.
261
-     * If yes, then uses it to format the value.
262
-     *
263
-     * @param mixed         $value
264
-     * @param EE_Base_Class $source
265
-     * @return mixed The formatted value.
266
-     * @throws InvalidDataTypeException
267
-     * @throws InvalidInterfaceException
268
-     * @throws InvalidArgumentException
269
-     * @throws ReflectionException
270
-     */
271
-    public function mayBeFormatValue($value, EE_Base_Class $source)
272
-    {
273
-        if (is_callable($this->formatter)) {
274
-            // dynamic methods using $this don't play nice
275
-            // so capture formatter to a single var first
276
-            $formatter = $this->formatter;
277
-            return $formatter($value, $source);
278
-        }
279
-        return $value;
280
-    }
23
+	/**
24
+	 * @var string $name
25
+	 */
26
+	protected $name;
27
+
28
+	/**
29
+	 * @var string|string[] $type
30
+	 */
31
+	protected $type;
32
+
33
+	/**
34
+	 * @var string|null $key
35
+	 */
36
+	protected $key;
37
+
38
+	/**
39
+	 * @var string $description
40
+	 */
41
+	protected $description;
42
+
43
+	/**
44
+	 * @var callable $formatter
45
+	 */
46
+	protected $formatter;
47
+
48
+	/**
49
+	 * @var callable $resolve
50
+	 */
51
+	protected $resolver;
52
+
53
+	/**
54
+	 * @var array $caps
55
+	 */
56
+	protected $caps;
57
+
58
+	/**
59
+	 * @var array $args
60
+	 */
61
+	protected $args;
62
+
63
+	/**
64
+	 * @var bool $use_for_input
65
+	 */
66
+	protected $use_for_input = true;
67
+
68
+	/**
69
+	 * @var bool $use_for_output
70
+	 */
71
+	protected $use_for_output = true;
72
+
73
+
74
+	/**
75
+	 * @param string          $name
76
+	 * @param string|string[] $type
77
+	 * @param string|null     $key
78
+	 * @param string          $description
79
+	 * @param callable|null   $formatter
80
+	 * @param callable|null   $resolver
81
+	 * @param array           $args
82
+	 * @param array           $caps
83
+	 * @param array           $args
84
+	 */
85
+	public function __construct(
86
+		$name,
87
+		$type,
88
+		$key = null,
89
+		$description = '',
90
+		callable $formatter = null,
91
+		callable $resolver = null,
92
+		array $caps = [],
93
+		array $args = []
94
+	) {
95
+		$this->name = $name;
96
+		$this->type = $type;
97
+		$this->key = $key;
98
+		$this->description = $description;
99
+		$this->formatter = $formatter;
100
+		$this->resolver = $resolver;
101
+		$this->caps = $caps;
102
+		$this->args = $args;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function caps()
110
+	{
111
+		return $this->caps;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @return string
117
+	 */
118
+	public function description()
119
+	{
120
+		return $this->description;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function key()
128
+	{
129
+		return $this->key;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @return string
135
+	 */
136
+	public function name()
137
+	{
138
+		return $this->name;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return string|string[]
144
+	 */
145
+	public function type()
146
+	{
147
+		return $this->type;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Convert the field to array to be
153
+	 * able to pass as config to WP GraphQL
154
+	 *
155
+	 * @return array
156
+	 */
157
+	public function toArray()
158
+	{
159
+		return get_object_vars($this);
160
+	}
161
+
162
+
163
+	/**
164
+	 * Sets the value for use_for_input.
165
+	 *
166
+	 * @param bool $use_for_input
167
+	 */
168
+	protected function setUseForInput($use_for_input)
169
+	{
170
+		$this->use_for_input = filter_var($use_for_input, FILTER_VALIDATE_BOOLEAN);
171
+	}
172
+
173
+
174
+	/**
175
+	 * Whether the field should be used for
176
+	 * mutation inputs.
177
+	 *
178
+	 * @return bool
179
+	 */
180
+	public function useForInput()
181
+	{
182
+		return (bool) $this->use_for_input;
183
+	}
184
+
185
+
186
+	/**
187
+	 * Whether the field should be used for
188
+	 * query outputs.
189
+	 *
190
+	 * @return bool
191
+	 */
192
+	public function useForOutput()
193
+	{
194
+		return (bool) $this->use_for_output;
195
+	}
196
+
197
+
198
+	/**
199
+	 * Sets the value for use_for_output
200
+	 *
201
+	 * @param bool $use_for_output
202
+	 */
203
+	protected function setUseForOutput($use_for_output)
204
+	{
205
+		$this->use_for_output = filter_var($use_for_output, FILTER_VALIDATE_BOOLEAN);
206
+	}
207
+
208
+
209
+	/**
210
+	 * Whether the field should resolve
211
+	 * based on the user caps etc.
212
+	 *
213
+	 * @return boolean
214
+	 */
215
+	public function shouldResolve()
216
+	{
217
+		foreach ($this->caps as $cap) {
218
+			if (! current_user_can($cap)) {
219
+				return false;
220
+			}
221
+		}
222
+		return true;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Whether the field has an explicit resolver set.
228
+	 *
229
+	 * @return boolean
230
+	 */
231
+	public function hasInternalResolver()
232
+	{
233
+		return is_callable($this->resolver);
234
+	}
235
+
236
+
237
+	/**
238
+	 * Whether the field has an explicit resolver set.
239
+	 *
240
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
241
+	 * @param array       $args    The inputArgs on the field
242
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
243
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
244
+	 * @return mixed
245
+	 * @throws LogicException
246
+	 */
247
+	public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
248
+	{
249
+		if (! $this->hasInternalResolver()) {
250
+			throw new LogicException('GraphQLField has no internal resolver.');
251
+		}
252
+		// dynamic methods using $this don't play nice
253
+		// so capture resolver to a single var first
254
+		$resolver = $this->resolver;
255
+		return $resolver($source, $args, $context, $info);
256
+	}
257
+
258
+
259
+	/**
260
+	 * Checks if the format callback is set.
261
+	 * If yes, then uses it to format the value.
262
+	 *
263
+	 * @param mixed         $value
264
+	 * @param EE_Base_Class $source
265
+	 * @return mixed The formatted value.
266
+	 * @throws InvalidDataTypeException
267
+	 * @throws InvalidInterfaceException
268
+	 * @throws InvalidArgumentException
269
+	 * @throws ReflectionException
270
+	 */
271
+	public function mayBeFormatValue($value, EE_Base_Class $source)
272
+	{
273
+		if (is_callable($this->formatter)) {
274
+			// dynamic methods using $this don't play nice
275
+			// so capture formatter to a single var first
276
+			$formatter = $this->formatter;
277
+			return $formatter($value, $source);
278
+		}
279
+		return $value;
280
+	}
281 281
 }
Please login to merge, or discard this patch.
core/services/admin/AdminPageHeaderDecoratorInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@
 block discarded – undo
13 13
 interface AdminPageHeaderDecoratorInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @param string $text
18
-     * @return string
19
-     * @since 4.10.2.p
20
-     */
21
-    public function getHeaderText($text = '');
16
+	/**
17
+	 * @param string $text
18
+	 * @return string
19
+	 * @since 4.10.2.p
20
+	 */
21
+	public function getHeaderText($text = '');
22 22
 }
Please login to merge, or discard this patch.
core/domain/services/converters/RestApiSpoofer.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -49,137 +49,137 @@
 block discarded – undo
49 49
 class RestApiSpoofer
50 50
 {
51 51
 
52
-    /**
53
-     * @var WP_REST_Server $wp_rest_server
54
-     */
55
-    protected $wp_rest_server;
52
+	/**
53
+	 * @var WP_REST_Server $wp_rest_server
54
+	 */
55
+	protected $wp_rest_server;
56 56
 
57
-    /**
58
-     * @var Read
59
-     */
60
-    protected $rest_controller;
57
+	/**
58
+	 * @var Read
59
+	 */
60
+	protected $rest_controller;
61 61
 
62
-    /**
63
-     * @var EED_Core_Rest_Api $rest_module
64
-     */
65
-    protected $rest_module;
62
+	/**
63
+	 * @var EED_Core_Rest_Api $rest_module
64
+	 */
65
+	protected $rest_module;
66 66
 
67 67
 
68
-    /**
69
-     * RestApiSpoofer constructor.
70
-     *
71
-     * @param WP_REST_Server        $wp_rest_server
72
-     * @param EED_Core_Rest_Api $rest_module
73
-     * @param Read                  $rest_api
74
-     * @param string                $api_version
75
-     */
76
-    public function __construct(
77
-        WP_REST_Server $wp_rest_server,
78
-        EED_Core_Rest_Api $rest_module,
79
-        Read $rest_api,
80
-        $api_version = '4.8.36'
81
-    ) {
82
-        $this->wp_rest_server = $wp_rest_server;
83
-        $this->rest_module = $rest_module;
84
-        $this->rest_controller = $rest_api;
85
-        $this->rest_controller->setRequestedVersion($api_version);
86
-        $this->setUpRestServer();
87
-    }
68
+	/**
69
+	 * RestApiSpoofer constructor.
70
+	 *
71
+	 * @param WP_REST_Server        $wp_rest_server
72
+	 * @param EED_Core_Rest_Api $rest_module
73
+	 * @param Read                  $rest_api
74
+	 * @param string                $api_version
75
+	 */
76
+	public function __construct(
77
+		WP_REST_Server $wp_rest_server,
78
+		EED_Core_Rest_Api $rest_module,
79
+		Read $rest_api,
80
+		$api_version = '4.8.36'
81
+	) {
82
+		$this->wp_rest_server = $wp_rest_server;
83
+		$this->rest_module = $rest_module;
84
+		$this->rest_controller = $rest_api;
85
+		$this->rest_controller->setRequestedVersion($api_version);
86
+		$this->setUpRestServer();
87
+	}
88 88
 
89 89
 
90
-    private function setUpRestServer()
91
-    {
92
-        /* @var WP_REST_Server $wp_rest_server */
93
-        global $wp_rest_server;
94
-        $wp_rest_server = $this->wp_rest_server;
95
-        EED_Core_Rest_Api::set_hooks_both();
96
-        do_action('rest_api_init', $this->wp_rest_server);
97
-    }
90
+	private function setUpRestServer()
91
+	{
92
+		/* @var WP_REST_Server $wp_rest_server */
93
+		global $wp_rest_server;
94
+		$wp_rest_server = $this->wp_rest_server;
95
+		EED_Core_Rest_Api::set_hooks_both();
96
+		do_action('rest_api_init', $this->wp_rest_server);
97
+	}
98 98
 
99
-    /**
100
-     * @param EEM_Base $model
101
-     * @param array    $query_params
102
-     * @param string   $include
103
-     * @return array
104
-     * @throws EE_Error
105
-     * @throws InvalidArgumentException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     * @throws ModelConfigurationException
109
-     * @throws ReflectionException
110
-     * @throws RestException
111
-     * @throws RestPasswordIncorrectException
112
-     * @throws RestPasswordRequiredException
113
-     * @throws UnexpectedEntityException
114
-     * @throws DomainException
115
-     * @since $VID:$
116
-     */
117
-    public function getOneApiResult(EEM_Base $model, array $query_params, $include = '')
118
-    {
119
-        if (! array_key_exists('limit', $query_params)) {
120
-            $query_params['limit'] = 1;
121
-        }
122
-        $result = $this->getApiResults($model, $query_params, $include);
123
-        return is_array($result) && isset($result[0]) ? $result[0] : [];
124
-    }
99
+	/**
100
+	 * @param EEM_Base $model
101
+	 * @param array    $query_params
102
+	 * @param string   $include
103
+	 * @return array
104
+	 * @throws EE_Error
105
+	 * @throws InvalidArgumentException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 * @throws ModelConfigurationException
109
+	 * @throws ReflectionException
110
+	 * @throws RestException
111
+	 * @throws RestPasswordIncorrectException
112
+	 * @throws RestPasswordRequiredException
113
+	 * @throws UnexpectedEntityException
114
+	 * @throws DomainException
115
+	 * @since $VID:$
116
+	 */
117
+	public function getOneApiResult(EEM_Base $model, array $query_params, $include = '')
118
+	{
119
+		if (! array_key_exists('limit', $query_params)) {
120
+			$query_params['limit'] = 1;
121
+		}
122
+		$result = $this->getApiResults($model, $query_params, $include);
123
+		return is_array($result) && isset($result[0]) ? $result[0] : [];
124
+	}
125 125
 
126
-    /**
127
-     * @param EEM_Base $model
128
-     * @param array    $query_params
129
-     * @param string   $include
130
-     * @return array
131
-     * @throws EE_Error
132
-     * @throws InvalidArgumentException
133
-     * @throws InvalidDataTypeException
134
-     * @throws InvalidInterfaceException
135
-     * @throws ModelConfigurationException
136
-     * @throws ReflectionException
137
-     * @throws RestException
138
-     * @throws RestPasswordIncorrectException
139
-     * @throws RestPasswordRequiredException
140
-     * @throws UnexpectedEntityException
141
-     * @throws DomainException
142
-     * @since $VID:$
143
-     */
144
-    public function getApiResults(EEM_Base $model, array $query_params, $include = '')
145
-    {
146
-        if (! array_key_exists('caps', $query_params)) {
147
-            $query_params['caps'] = EEM_Base::caps_read_admin;
148
-        }
149
-        if (! array_key_exists('default_where_conditions', $query_params)) {
150
-            $query_params['default_where_conditions'] = 'none';
151
-        }
152
-        /** @type array $results */
153
-        $results = $model->get_all_wpdb_results($query_params);
154
-        $rest_request = new WP_REST_Request();
155
-        $rest_request->set_param('include', $include);
156
-        $rest_request->set_param('caps', 'edit');
157
-        $nice_results = array();
158
-        foreach ($results as $result) {
159
-            $nice_results[] = $this->rest_controller->createEntityFromWpdbResult(
160
-                $model,
161
-                $result,
162
-                $rest_request
163
-            );
164
-        }
165
-        return $nice_results;
166
-    }
126
+	/**
127
+	 * @param EEM_Base $model
128
+	 * @param array    $query_params
129
+	 * @param string   $include
130
+	 * @return array
131
+	 * @throws EE_Error
132
+	 * @throws InvalidArgumentException
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws InvalidInterfaceException
135
+	 * @throws ModelConfigurationException
136
+	 * @throws ReflectionException
137
+	 * @throws RestException
138
+	 * @throws RestPasswordIncorrectException
139
+	 * @throws RestPasswordRequiredException
140
+	 * @throws UnexpectedEntityException
141
+	 * @throws DomainException
142
+	 * @since $VID:$
143
+	 */
144
+	public function getApiResults(EEM_Base $model, array $query_params, $include = '')
145
+	{
146
+		if (! array_key_exists('caps', $query_params)) {
147
+			$query_params['caps'] = EEM_Base::caps_read_admin;
148
+		}
149
+		if (! array_key_exists('default_where_conditions', $query_params)) {
150
+			$query_params['default_where_conditions'] = 'none';
151
+		}
152
+		/** @type array $results */
153
+		$results = $model->get_all_wpdb_results($query_params);
154
+		$rest_request = new WP_REST_Request();
155
+		$rest_request->set_param('include', $include);
156
+		$rest_request->set_param('caps', 'edit');
157
+		$nice_results = array();
158
+		foreach ($results as $result) {
159
+			$nice_results[] = $this->rest_controller->createEntityFromWpdbResult(
160
+				$model,
161
+				$result,
162
+				$rest_request
163
+			);
164
+		}
165
+		return $nice_results;
166
+	}
167 167
 
168 168
 
169
-    /**
170
-     * @param string $endpoint
171
-     * @return array
172
-     * @throws EE_Error
173
-     * @since $VID:$
174
-     */
175
-    public function getModelSchema($endpoint)
176
-    {
177
-        $response = $this->wp_rest_server->dispatch(
178
-            new WP_REST_Request(
179
-                'OPTIONS',
180
-                "/ee/v4.8.36/{$endpoint}"
181
-            )
182
-        );
183
-        return $response->get_data();
184
-    }
169
+	/**
170
+	 * @param string $endpoint
171
+	 * @return array
172
+	 * @throws EE_Error
173
+	 * @since $VID:$
174
+	 */
175
+	public function getModelSchema($endpoint)
176
+	{
177
+		$response = $this->wp_rest_server->dispatch(
178
+			new WP_REST_Request(
179
+				'OPTIONS',
180
+				"/ee/v4.8.36/{$endpoint}"
181
+			)
182
+		);
183
+		return $response->get_data();
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function getOneApiResult(EEM_Base $model, array $query_params, $include = '')
118 118
     {
119
-        if (! array_key_exists('limit', $query_params)) {
119
+        if ( ! array_key_exists('limit', $query_params)) {
120 120
             $query_params['limit'] = 1;
121 121
         }
122 122
         $result = $this->getApiResults($model, $query_params, $include);
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function getApiResults(EEM_Base $model, array $query_params, $include = '')
145 145
     {
146
-        if (! array_key_exists('caps', $query_params)) {
146
+        if ( ! array_key_exists('caps', $query_params)) {
147 147
             $query_params['caps'] = EEM_Base::caps_read_admin;
148 148
         }
149
-        if (! array_key_exists('default_where_conditions', $query_params)) {
149
+        if ( ! array_key_exists('default_where_conditions', $query_params)) {
150 150
             $query_params['default_where_conditions'] = 'none';
151 151
         }
152 152
         /** @type array $results */
Please login to merge, or discard this patch.
core/services/converters/json/ModelObjectToJsonConverterInterface.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,50 +13,50 @@
 block discarded – undo
13 13
 interface ModelObjectToJsonConverterInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @param array $entities
18
-     * @return array
19
-     * @since $VID:$
20
-     */
21
-    public function convertAndEncodeArrayOf(array $entities);
22
-
23
-
24
-    /**
25
-     * @param $entity
26
-     * @return false|string
27
-     * @since $VID:$
28
-     */
29
-    public function convertAndEncode($entity);
30
-
31
-
32
-    /**
33
-     * @param array $entities
34
-     * @return array
35
-     * @since $VID:$
36
-     */
37
-    public function convertArrayOf(array $entities);
38
-
39
-
40
-    /**
41
-     * @param $entity
42
-     * @return array
43
-     * @since $VID:$
44
-     */
45
-    public function convert($entity);
46
-
47
-
48
-    /**
49
-     * @param array $entities
50
-     * @return array
51
-     * @since $VID:$
52
-     */
53
-    public function encodeArrayOf(array $entities);
54
-
55
-
56
-    /**
57
-     * @param array $entity_array
58
-     * @return false|string
59
-     * @since $VID:$
60
-     */
61
-    public function encode(array $entity_array);
16
+	/**
17
+	 * @param array $entities
18
+	 * @return array
19
+	 * @since $VID:$
20
+	 */
21
+	public function convertAndEncodeArrayOf(array $entities);
22
+
23
+
24
+	/**
25
+	 * @param $entity
26
+	 * @return false|string
27
+	 * @since $VID:$
28
+	 */
29
+	public function convertAndEncode($entity);
30
+
31
+
32
+	/**
33
+	 * @param array $entities
34
+	 * @return array
35
+	 * @since $VID:$
36
+	 */
37
+	public function convertArrayOf(array $entities);
38
+
39
+
40
+	/**
41
+	 * @param $entity
42
+	 * @return array
43
+	 * @since $VID:$
44
+	 */
45
+	public function convert($entity);
46
+
47
+
48
+	/**
49
+	 * @param array $entities
50
+	 * @return array
51
+	 * @since $VID:$
52
+	 */
53
+	public function encodeArrayOf(array $entities);
54
+
55
+
56
+	/**
57
+	 * @param array $entity_array
58
+	 * @return false|string
59
+	 * @since $VID:$
60
+	 */
61
+	public function encode(array $entity_array);
62 62
 }
Please login to merge, or discard this patch.
core/services/graphql/resolvers/ResolverInterface.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@
 block discarded – undo
16 16
 interface ResolverInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @param             $source
21
-     * @param array       $args
22
-     * @param AppContext  $context
23
-     * @param ResolveInfo $info
24
-     * @return mixed
25
-     * @since $VID:$
26
-     */
27
-    public function resolve($source, array $args, AppContext $context, ResolveInfo $info);
19
+	/**
20
+	 * @param             $source
21
+	 * @param array       $args
22
+	 * @param AppContext  $context
23
+	 * @param ResolveInfo $info
24
+	 * @return mixed
25
+	 * @since $VID:$
26
+	 */
27
+	public function resolve($source, array $args, AppContext $context, ResolveInfo $info);
28 28
 }
Please login to merge, or discard this patch.
core/services/graphql/TypesManager.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
             $config = $field->toArray();
76 76
             if ($field->useForInput()) {
77 77
                 // Register input fields for existing mutations.
78
-                register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config);
79
-                register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config);
78
+                register_graphql_field('Update'.$typeName.'Input', $fieldName, $config);
79
+                register_graphql_field('Create'.$typeName.'Input', $fieldName, $config);
80 80
             }
81 81
             if ($field->useForOutput()) {
82 82
                 $config['resolve'] = [$type, 'resolveField'];
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
             $fieldName = $field->name();
103 103
             $config = $field->toArray();
104 104
             if ($field->useForInput()) {
105
-                $inputFields[ $fieldName ] = $config;
105
+                $inputFields[$fieldName] = $config;
106 106
             }
107 107
             if ($field->useForOutput()) {
108 108
                 $config['resolve'] = [$type, 'resolveField'];
109
-                $outputFields[ $fieldName ] = $config;
109
+                $outputFields[$fieldName] = $config;
110 110
             }
111 111
         }
112 112
         $typeName = $type->name();
113
-        if (! empty($outputFields)) {
113
+        if ( ! empty($outputFields)) {
114 114
             // Register the object type.
115 115
             register_graphql_object_type(
116 116
                 $typeName,
Please login to merge, or discard this patch.
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -18,110 +18,110 @@
 block discarded – undo
18 18
 class TypesManager implements GQLManagerInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var TypeCollection|TypeInterface[] $types
23
-     */
24
-    private $types;
21
+	/**
22
+	 * @var TypeCollection|TypeInterface[] $types
23
+	 */
24
+	private $types;
25 25
 
26 26
 
27
-    /**
28
-     * TypesManager constructor.
29
-     *
30
-     * @param TypeCollection|TypeInterface[] $types
31
-     */
32
-    public function __construct(TypeCollection $types)
33
-    {
34
-        $this->types = $types;
35
-    }
27
+	/**
28
+	 * TypesManager constructor.
29
+	 *
30
+	 * @param TypeCollection|TypeInterface[] $types
31
+	 */
32
+	public function __construct(TypeCollection $types)
33
+	{
34
+		$this->types = $types;
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * @throws CollectionDetailsException
40
-     * @throws CollectionLoaderException
41
-     * @since $VID:$
42
-     */
43
-    public function init()
44
-    {
45
-        $this->types->loadTypes();
46
-        add_action('graphql_register_types', [$this, 'configureTypes'], 10);
47
-    }
38
+	/**
39
+	 * @throws CollectionDetailsException
40
+	 * @throws CollectionLoaderException
41
+	 * @since $VID:$
42
+	 */
43
+	public function init()
44
+	{
45
+		$this->types->loadTypes();
46
+		add_action('graphql_register_types', [$this, 'configureTypes'], 10);
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * @since $VID:$
52
-     */
53
-    public function configureTypes()
54
-    {
55
-        // loop through the collection of types and register their fields
56
-        foreach ($this->types as $type) {
57
-            if ($type->isCustomPostType()) {
58
-                $this->extendCustomPostType($type);
59
-            } else {
60
-                $this->registerType($type);
61
-            }
62
-        }
63
-    }
50
+	/**
51
+	 * @since $VID:$
52
+	 */
53
+	public function configureTypes()
54
+	{
55
+		// loop through the collection of types and register their fields
56
+		foreach ($this->types as $type) {
57
+			if ($type->isCustomPostType()) {
58
+				$this->extendCustomPostType($type);
59
+			} else {
60
+				$this->registerType($type);
61
+			}
62
+		}
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * @param TypeInterface $type
68
-     * @since $VID:$
69
-     */
70
-    public function extendCustomPostType(TypeInterface $type)
71
-    {
72
-        $typeName = $type->name();
73
-        foreach ($type->fields() as $field) {
74
-            $fieldName = $field->name();
75
-            $config = $field->toArray();
76
-            if ($field->useForInput()) {
77
-                // Register input fields for existing mutations.
78
-                register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config);
79
-                register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config);
80
-            }
81
-            if ($field->useForOutput()) {
82
-                $config['resolve'] = [$type, 'resolveField'];
83
-                // Register fields for queries.
84
-                register_graphql_field($typeName, $fieldName, $config);
85
-            }
86
-        }
87
-        if (is_callable([$type, 'extendMutations'])) {
88
-            $type->extendMutations();
89
-        }
90
-    }
66
+	/**
67
+	 * @param TypeInterface $type
68
+	 * @since $VID:$
69
+	 */
70
+	public function extendCustomPostType(TypeInterface $type)
71
+	{
72
+		$typeName = $type->name();
73
+		foreach ($type->fields() as $field) {
74
+			$fieldName = $field->name();
75
+			$config = $field->toArray();
76
+			if ($field->useForInput()) {
77
+				// Register input fields for existing mutations.
78
+				register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config);
79
+				register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config);
80
+			}
81
+			if ($field->useForOutput()) {
82
+				$config['resolve'] = [$type, 'resolveField'];
83
+				// Register fields for queries.
84
+				register_graphql_field($typeName, $fieldName, $config);
85
+			}
86
+		}
87
+		if (is_callable([$type, 'extendMutations'])) {
88
+			$type->extendMutations();
89
+		}
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * @param TypeInterface $type
95
-     * @since $VID:$
96
-     */
97
-    public function registerType(TypeInterface $type)
98
-    {
99
-        $outputFields = [];
100
-        $inputFields = [];
101
-        foreach ($type->fields() as $field) {
102
-            $fieldName = $field->name();
103
-            $config = $field->toArray();
104
-            if ($field->useForInput()) {
105
-                $inputFields[ $fieldName ] = $config;
106
-            }
107
-            if ($field->useForOutput()) {
108
-                $config['resolve'] = [$type, 'resolveField'];
109
-                $outputFields[ $fieldName ] = $config;
110
-            }
111
-        }
112
-        $typeName = $type->name();
113
-        if (! empty($outputFields)) {
114
-            // Register the object type.
115
-            register_graphql_object_type(
116
-                $typeName,
117
-                [
118
-                    'description' => $type->description(),
119
-                    'fields'      => $outputFields,
120
-                ]
121
-            );
122
-        }
123
-        if (is_callable([$type, 'registerMutations'])) {
124
-            $type->registerMutations($inputFields);
125
-        }
126
-    }
93
+	/**
94
+	 * @param TypeInterface $type
95
+	 * @since $VID:$
96
+	 */
97
+	public function registerType(TypeInterface $type)
98
+	{
99
+		$outputFields = [];
100
+		$inputFields = [];
101
+		foreach ($type->fields() as $field) {
102
+			$fieldName = $field->name();
103
+			$config = $field->toArray();
104
+			if ($field->useForInput()) {
105
+				$inputFields[ $fieldName ] = $config;
106
+			}
107
+			if ($field->useForOutput()) {
108
+				$config['resolve'] = [$type, 'resolveField'];
109
+				$outputFields[ $fieldName ] = $config;
110
+			}
111
+		}
112
+		$typeName = $type->name();
113
+		if (! empty($outputFields)) {
114
+			// Register the object type.
115
+			register_graphql_object_type(
116
+				$typeName,
117
+				[
118
+					'description' => $type->description(),
119
+					'fields'      => $outputFields,
120
+				]
121
+			);
122
+		}
123
+		if (is_callable([$type, 'registerMutations'])) {
124
+			$type->registerMutations($inputFields);
125
+		}
126
+	}
127 127
 }
Please login to merge, or discard this patch.
core/services/graphql/types/TypeBase.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
         $fields = [];
156 156
         foreach ($this->fields() as $field) {
157 157
             if ($field->useForOutput()) {
158
-                $fields[ $field->name() ] = $field;
158
+                $fields[$field->name()] = $field;
159 159
             }
160 160
         }
161 161
         return $fields;
Please login to merge, or discard this patch.
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -35,270 +35,270 @@
 block discarded – undo
35 35
 abstract class TypeBase implements TypeInterface
36 36
 {
37 37
 
38
-    /**
39
-     * @var string $namespace The graphql namespace/prefix.
40
-     */
41
-    protected $namespace = 'Espresso';
42
-
43
-    /**
44
-     * @var EEM_Base $model
45
-     */
46
-    protected $model;
47
-
48
-    /**
49
-     * @var string $name
50
-     */
51
-    protected $name = '';
52
-
53
-    /**
54
-     * @var string $description
55
-     */
56
-    protected $description = '';
57
-
58
-    /**
59
-     * @var GraphQLFieldInterface[] $fields
60
-     */
61
-    protected $fields = [];
62
-
63
-    /**
64
-     * @var array $graphql_to_model_map
65
-     */
66
-    protected $graphql_to_model_map = [];
67
-
68
-    /**
69
-     * @var FieldResolver $field_resolver
70
-     */
71
-    protected $field_resolver;
72
-
73
-    /**
74
-     * @var bool $is_custom_post_type
75
-     */
76
-    protected $is_custom_post_type = false;
77
-
78
-
79
-    /**
80
-     * TypeBase constructor.
81
-     *
82
-     * @param EEM_Base|null $model
83
-     */
84
-    public function __construct(EEM_Base $model = null)
85
-    {
86
-        $this->model = $model;
87
-        $this->setFields($this->getFields());
88
-        $this->field_resolver = new FieldResolver(
89
-            $this->model,
90
-            $this->getFieldsForResolver()
91
-        );
92
-    }
93
-
94
-
95
-    /**
96
-     * @return GraphQLFieldInterface[]
97
-     * @since $VID:$
98
-     */
99
-    abstract protected function getFields(): array;
100
-
101
-
102
-    /**
103
-     * @return string
104
-     */
105
-    public function name(): string
106
-    {
107
-        return $this->name;
108
-    }
109
-
110
-
111
-    /**
112
-     * @param string $name
113
-     */
114
-    protected function setName(string $name)
115
-    {
116
-        $this->name = $name;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function description(): string
124
-    {
125
-        return $this->description;
126
-    }
127
-
128
-
129
-    /**
130
-     * @param string $description
131
-     */
132
-    protected function setDescription(string $description)
133
-    {
134
-        $this->description = $description;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return GraphQLFieldInterface[]
140
-     * @since $VID:$
141
-     */
142
-    public function fields(): array
143
-    {
144
-        return (array) $this->fields;
145
-    }
146
-
147
-
148
-    /**
149
-     * @param GraphQLFieldInterface[] $fields
150
-     */
151
-    protected function setFields(array $fields)
152
-    {
153
-        foreach ($fields as $field) {
154
-            if ($field instanceof GraphQLField) {
155
-                $this->fields[] = $field;
156
-            }
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Creates a key map for internal resolver.
163
-     *
164
-     * @return array
165
-     * @since $VID:$
166
-     */
167
-    public function getFieldsForResolver(): array
168
-    {
169
-        $fields = [];
170
-        foreach ($this->fields() as $field) {
171
-            if ($field->useForOutput()) {
172
-                $fields[ $field->name() ] = $field;
173
-            }
174
-        }
175
-        return $fields;
176
-    }
177
-
178
-
179
-    /**
180
-     * @return bool
181
-     */
182
-    public function isCustomPostType(): bool
183
-    {
184
-        return $this->is_custom_post_type;
185
-    }
186
-
187
-
188
-    /**
189
-     * @param bool $is_custom_post_type
190
-     */
191
-    protected function setIsCustomPostType(bool $is_custom_post_type)
192
-    {
193
-        $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param int|float $value
199
-     * @return int
200
-     * @since $VID:$
201
-     */
202
-    public function parseInfiniteValue($value): int
203
-    {
204
-        $value = trim($value);
205
-        return $value === null
206
-               || $value === ''
207
-               || $value === '&infin;'
208
-               || $value === 'INF'
209
-               || $value === INF
210
-               || $value === EE_INF
211
-               || is_infinite((float) $value)
212
-            ? -1
213
-            : $value;
214
-    }
215
-
216
-
217
-    /**
218
-     * @param mixed $source
219
-     * @return EE_Base_Class|null
220
-     * @throws EE_Error
221
-     */
222
-    private function getModel($source): ?EE_Base_Class
223
-    {
224
-        // If it comes from a custom connection
225
-        // where the $source is already instantiated.
226
-        if ($source instanceof EE_Base_Class) {
227
-            return $source;
228
-        }
229
-        return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
230
-    }
231
-
232
-
233
-    /**
234
-     * @param mixed       $source  The source that's passed down the GraphQL queries
235
-     * @param array       $args    The inputArgs on the field
236
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
237
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
238
-     * @return EE_Base_Class|Deferred|string|null
239
-     * @throws EE_Error
240
-     * @throws InvalidDataTypeException
241
-     * @throws InvalidInterfaceException
242
-     * @throws UnexpectedEntityException
243
-     * @throws UserError
244
-     * @throws InvalidArgumentException
245
-     * @throws ReflectionException
246
-     * @since $VID:$
247
-     */
248
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
249
-    {
250
-        $source = $source instanceof RootQuery ? $source : $this->getModel($source);
251
-
252
-        return $this->field_resolver->resolve($source, $args, $context, $info);
253
-    }
254
-
255
-
256
-    /**
257
-     * @param mixed      $payload The payload returned after mutation
258
-     * @param array      $args    The inputArgs on the field
259
-     * @param AppContext $context The AppContext passed down the GraphQL tree
260
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
261
-     * @throws EE_Error
262
-     */
263
-    public function resolveFromPayload($payload, array $args, AppContext $context)
264
-    {
265
-        if (empty($payload['id'])) {
266
-            return null;
267
-        }
268
-        return $this->model->get_one_by_ID($payload['id']);
269
-    }
270
-
271
-
272
-    /**
273
-     * Prepares a datetime value in ISO8601/RFC3339 format.
274
-     * It is assumed that the value of $datetime is in the format
275
-     * returned by EE_Base_Class::get_format().
276
-     *
277
-     * @param string        $datetime The datetime value.
278
-     * @param EE_Base_Class $source   The source object.
279
-     * @return string ISO8601/RFC3339 formatted datetime.
280
-     */
281
-    public function formatDatetime(string $datetime, EE_Base_Class $source): string
282
-    {
283
-        $format   = $source->get_format();
284
-        // create date object based on local timezone
285
-        $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
286
-        // change the timezone to UTC
287
-        $datetime->setTimezone(new DateTimeZone('UTC'));
288
-
289
-        return $datetime->format(DateTime::RFC3339);
290
-    }
291
-
292
-
293
-    /**
294
-     * Converts an object to JSON. The object must have a "toJson" method.
295
-     *
296
-     * @param string        $object   The object/value.
297
-     * @param EE_Base_Class $source   The source object.
298
-     * @return string JSON representation of the object.
299
-     */
300
-    public function toJson(JsonableInterface $object, EE_Base_Class $source): string
301
-    {
302
-        return $object->toJson();
303
-    }
38
+	/**
39
+	 * @var string $namespace The graphql namespace/prefix.
40
+	 */
41
+	protected $namespace = 'Espresso';
42
+
43
+	/**
44
+	 * @var EEM_Base $model
45
+	 */
46
+	protected $model;
47
+
48
+	/**
49
+	 * @var string $name
50
+	 */
51
+	protected $name = '';
52
+
53
+	/**
54
+	 * @var string $description
55
+	 */
56
+	protected $description = '';
57
+
58
+	/**
59
+	 * @var GraphQLFieldInterface[] $fields
60
+	 */
61
+	protected $fields = [];
62
+
63
+	/**
64
+	 * @var array $graphql_to_model_map
65
+	 */
66
+	protected $graphql_to_model_map = [];
67
+
68
+	/**
69
+	 * @var FieldResolver $field_resolver
70
+	 */
71
+	protected $field_resolver;
72
+
73
+	/**
74
+	 * @var bool $is_custom_post_type
75
+	 */
76
+	protected $is_custom_post_type = false;
77
+
78
+
79
+	/**
80
+	 * TypeBase constructor.
81
+	 *
82
+	 * @param EEM_Base|null $model
83
+	 */
84
+	public function __construct(EEM_Base $model = null)
85
+	{
86
+		$this->model = $model;
87
+		$this->setFields($this->getFields());
88
+		$this->field_resolver = new FieldResolver(
89
+			$this->model,
90
+			$this->getFieldsForResolver()
91
+		);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return GraphQLFieldInterface[]
97
+	 * @since $VID:$
98
+	 */
99
+	abstract protected function getFields(): array;
100
+
101
+
102
+	/**
103
+	 * @return string
104
+	 */
105
+	public function name(): string
106
+	{
107
+		return $this->name;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param string $name
113
+	 */
114
+	protected function setName(string $name)
115
+	{
116
+		$this->name = $name;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function description(): string
124
+	{
125
+		return $this->description;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @param string $description
131
+	 */
132
+	protected function setDescription(string $description)
133
+	{
134
+		$this->description = $description;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return GraphQLFieldInterface[]
140
+	 * @since $VID:$
141
+	 */
142
+	public function fields(): array
143
+	{
144
+		return (array) $this->fields;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param GraphQLFieldInterface[] $fields
150
+	 */
151
+	protected function setFields(array $fields)
152
+	{
153
+		foreach ($fields as $field) {
154
+			if ($field instanceof GraphQLField) {
155
+				$this->fields[] = $field;
156
+			}
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Creates a key map for internal resolver.
163
+	 *
164
+	 * @return array
165
+	 * @since $VID:$
166
+	 */
167
+	public function getFieldsForResolver(): array
168
+	{
169
+		$fields = [];
170
+		foreach ($this->fields() as $field) {
171
+			if ($field->useForOutput()) {
172
+				$fields[ $field->name() ] = $field;
173
+			}
174
+		}
175
+		return $fields;
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return bool
181
+	 */
182
+	public function isCustomPostType(): bool
183
+	{
184
+		return $this->is_custom_post_type;
185
+	}
186
+
187
+
188
+	/**
189
+	 * @param bool $is_custom_post_type
190
+	 */
191
+	protected function setIsCustomPostType(bool $is_custom_post_type)
192
+	{
193
+		$this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param int|float $value
199
+	 * @return int
200
+	 * @since $VID:$
201
+	 */
202
+	public function parseInfiniteValue($value): int
203
+	{
204
+		$value = trim($value);
205
+		return $value === null
206
+			   || $value === ''
207
+			   || $value === '&infin;'
208
+			   || $value === 'INF'
209
+			   || $value === INF
210
+			   || $value === EE_INF
211
+			   || is_infinite((float) $value)
212
+			? -1
213
+			: $value;
214
+	}
215
+
216
+
217
+	/**
218
+	 * @param mixed $source
219
+	 * @return EE_Base_Class|null
220
+	 * @throws EE_Error
221
+	 */
222
+	private function getModel($source): ?EE_Base_Class
223
+	{
224
+		// If it comes from a custom connection
225
+		// where the $source is already instantiated.
226
+		if ($source instanceof EE_Base_Class) {
227
+			return $source;
228
+		}
229
+		return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
235
+	 * @param array       $args    The inputArgs on the field
236
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
237
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
238
+	 * @return EE_Base_Class|Deferred|string|null
239
+	 * @throws EE_Error
240
+	 * @throws InvalidDataTypeException
241
+	 * @throws InvalidInterfaceException
242
+	 * @throws UnexpectedEntityException
243
+	 * @throws UserError
244
+	 * @throws InvalidArgumentException
245
+	 * @throws ReflectionException
246
+	 * @since $VID:$
247
+	 */
248
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
249
+	{
250
+		$source = $source instanceof RootQuery ? $source : $this->getModel($source);
251
+
252
+		return $this->field_resolver->resolve($source, $args, $context, $info);
253
+	}
254
+
255
+
256
+	/**
257
+	 * @param mixed      $payload The payload returned after mutation
258
+	 * @param array      $args    The inputArgs on the field
259
+	 * @param AppContext $context The AppContext passed down the GraphQL tree
260
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
261
+	 * @throws EE_Error
262
+	 */
263
+	public function resolveFromPayload($payload, array $args, AppContext $context)
264
+	{
265
+		if (empty($payload['id'])) {
266
+			return null;
267
+		}
268
+		return $this->model->get_one_by_ID($payload['id']);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Prepares a datetime value in ISO8601/RFC3339 format.
274
+	 * It is assumed that the value of $datetime is in the format
275
+	 * returned by EE_Base_Class::get_format().
276
+	 *
277
+	 * @param string        $datetime The datetime value.
278
+	 * @param EE_Base_Class $source   The source object.
279
+	 * @return string ISO8601/RFC3339 formatted datetime.
280
+	 */
281
+	public function formatDatetime(string $datetime, EE_Base_Class $source): string
282
+	{
283
+		$format   = $source->get_format();
284
+		// create date object based on local timezone
285
+		$datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
286
+		// change the timezone to UTC
287
+		$datetime->setTimezone(new DateTimeZone('UTC'));
288
+
289
+		return $datetime->format(DateTime::RFC3339);
290
+	}
291
+
292
+
293
+	/**
294
+	 * Converts an object to JSON. The object must have a "toJson" method.
295
+	 *
296
+	 * @param string        $object   The object/value.
297
+	 * @param EE_Base_Class $source   The source object.
298
+	 * @return string JSON representation of the object.
299
+	 */
300
+	public function toJson(JsonableInterface $object, EE_Base_Class $source): string
301
+	{
302
+		return $object->toJson();
303
+	}
304 304
 }
Please login to merge, or discard this patch.