Completed
Branch master (d65695)
by
unknown
04:25
created
core/services/graphql/DataLoaderManager.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@
 block discarded – undo
17 17
  */
18 18
 class DataLoaderManager implements GQLManagerInterface
19 19
 {
20
-    /**
21
-     * @var DataLoaderCollection|GQLDataDomainInterface[] $data_loaders
22
-     */
23
-    private $data_loaders;
20
+	/**
21
+	 * @var DataLoaderCollection|GQLDataDomainInterface[] $data_loaders
22
+	 */
23
+	private $data_loaders;
24 24
 
25 25
 
26
-    /**
27
-     * @param DataLoaderCollection|GQLDataDomainInterface[] $data_loaders
28
-     */
29
-    public function __construct(DataLoaderCollection $data_loaders)
30
-    {
31
-        $this->data_loaders = $data_loaders;
32
-    }
26
+	/**
27
+	 * @param DataLoaderCollection|GQLDataDomainInterface[] $data_loaders
28
+	 */
29
+	public function __construct(DataLoaderCollection $data_loaders)
30
+	{
31
+		$this->data_loaders = $data_loaders;
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * @throws CollectionDetailsException
37
-     * @throws CollectionLoaderException
38
-     * @since 5.0.0.p
39
-     */
40
-    public function init()
41
-    {
42
-        $data_loaders = $this->data_loaders->getDataLoaders();
43
-        foreach ($data_loaders as $data_loader) {
44
-            add_filter('graphql_data_loaders', [$data_loader, 'registerLoaders'], 10, 2);
45
-        }
46
-    }
35
+	/**
36
+	 * @throws CollectionDetailsException
37
+	 * @throws CollectionLoaderException
38
+	 * @since 5.0.0.p
39
+	 */
40
+	public function init()
41
+	{
42
+		$data_loaders = $this->data_loaders->getDataLoaders();
43
+		foreach ($data_loaders as $data_loader) {
44
+			add_filter('graphql_data_loaders', [$data_loader, 'registerLoaders'], 10, 2);
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
core/services/graphql/types/TypeBase.php 1 patch
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -34,270 +34,270 @@
 block discarded – undo
34 34
  */
35 35
 abstract class TypeBase implements TypeInterface
36 36
 {
37
-    /**
38
-     * @var string $namespace The graphql namespace/prefix.
39
-     */
40
-    protected $namespace = 'Espresso';
41
-
42
-    /**
43
-     * @var EEM_Base $model
44
-     */
45
-    protected $model;
46
-
47
-    /**
48
-     * @var string $name
49
-     */
50
-    protected $name = '';
51
-
52
-    /**
53
-     * @var string $description
54
-     */
55
-    protected $description = '';
56
-
57
-    /**
58
-     * @var GraphQLFieldInterface[] $fields
59
-     */
60
-    protected $fields = [];
61
-
62
-    /**
63
-     * @var array $graphql_to_model_map
64
-     */
65
-    protected $graphql_to_model_map = [];
66
-
67
-    /**
68
-     * @var FieldResolver $field_resolver
69
-     */
70
-    protected $field_resolver;
71
-
72
-    /**
73
-     * @var bool $is_custom_post_type
74
-     */
75
-    protected $is_custom_post_type = false;
76
-
77
-
78
-    /**
79
-     * TypeBase constructor.
80
-     *
81
-     * @param EEM_Base|null $model
82
-     */
83
-    public function __construct(EEM_Base $model = null)
84
-    {
85
-        $this->model = $model;
86
-        $this->setFields($this->getFields());
87
-        $this->field_resolver = new FieldResolver(
88
-            $this->model,
89
-            $this->getFieldsForResolver()
90
-        );
91
-    }
92
-
93
-
94
-    /**
95
-     * @return GraphQLFieldInterface[]
96
-     * @since 5.0.0.p
97
-     */
98
-    abstract protected function getFields(): array;
99
-
100
-
101
-    /**
102
-     * @return string
103
-     */
104
-    public function name(): string
105
-    {
106
-        return $this->name;
107
-    }
108
-
109
-
110
-    /**
111
-     * @param string $name
112
-     */
113
-    protected function setName(string $name)
114
-    {
115
-        $this->name = $name;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function description(): string
123
-    {
124
-        return $this->description;
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $description
130
-     */
131
-    protected function setDescription(string $description)
132
-    {
133
-        $this->description = $description;
134
-    }
135
-
136
-
137
-    /**
138
-     * @return GraphQLFieldInterface[]
139
-     * @since 5.0.0.p
140
-     */
141
-    public function fields(): array
142
-    {
143
-        return (array) $this->fields;
144
-    }
145
-
146
-
147
-    /**
148
-     * @param GraphQLFieldInterface[] $fields
149
-     */
150
-    protected function setFields(array $fields)
151
-    {
152
-        foreach ($fields as $field) {
153
-            if ($field instanceof GraphQLField) {
154
-                $this->fields[] = $field;
155
-            }
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Creates a key map for internal resolver.
162
-     *
163
-     * @return array
164
-     * @since 5.0.0.p
165
-     */
166
-    public function getFieldsForResolver(): array
167
-    {
168
-        $fields = [];
169
-        foreach ($this->fields() as $field) {
170
-            if ($field->useForOutput()) {
171
-                $fields[ $field->name() ] = $field;
172
-            }
173
-        }
174
-        return $fields;
175
-    }
176
-
177
-
178
-    /**
179
-     * @return bool
180
-     */
181
-    public function isCustomPostType(): bool
182
-    {
183
-        return $this->is_custom_post_type;
184
-    }
185
-
186
-
187
-    /**
188
-     * @param bool $is_custom_post_type
189
-     */
190
-    protected function setIsCustomPostType(bool $is_custom_post_type)
191
-    {
192
-        $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
193
-    }
194
-
195
-
196
-    /**
197
-     * @param int|float $value
198
-     * @return int
199
-     * @since 5.0.0.p
200
-     */
201
-    public function parseInfiniteValue($value): int
202
-    {
203
-        $value = trim($value);
204
-        return $value === null
205
-               || $value === ''
206
-               || $value === '∞'
207
-               || $value === 'INF'
208
-               || $value === INF
209
-               || $value === EE_INF
210
-               || is_infinite((float) $value)
211
-            ? -1
212
-            : $value;
213
-    }
214
-
215
-
216
-    /**
217
-     * @param mixed $source
218
-     * @return EE_Base_Class|null
219
-     * @throws EE_Error
220
-     */
221
-    private function getModel($source): ?EE_Base_Class
222
-    {
223
-        // If it comes from a custom connection
224
-        // where the $source is already instantiated.
225
-        if ($source instanceof EE_Base_Class) {
226
-            return $source;
227
-        }
228
-        return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
229
-    }
230
-
231
-
232
-    /**
233
-     * @param mixed       $source  The source that's passed down the GraphQL queries
234
-     * @param array       $args    The inputArgs on the field
235
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
236
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
237
-     * @return EE_Base_Class|Deferred|string|null
238
-     * @throws EE_Error
239
-     * @throws InvalidDataTypeException
240
-     * @throws InvalidInterfaceException
241
-     * @throws UnexpectedEntityException
242
-     * @throws UserError
243
-     * @throws InvalidArgumentException
244
-     * @throws ReflectionException
245
-     * @since 5.0.0.p
246
-     */
247
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
248
-    {
249
-        $source = $source instanceof RootQuery ? $source : $this->getModel($source);
250
-
251
-        return $this->field_resolver->resolve($source, $args, $context, $info);
252
-    }
253
-
254
-
255
-    /**
256
-     * @param mixed      $payload The payload returned after mutation
257
-     * @param array      $args    The inputArgs on the field
258
-     * @param AppContext $context The AppContext passed down the GraphQL tree
259
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
260
-     * @throws EE_Error
261
-     */
262
-    public function resolveFromPayload($payload, array $args, AppContext $context)
263
-    {
264
-        if (empty($payload['id'])) {
265
-            return null;
266
-        }
267
-        return $this->model->get_one_by_ID($payload['id']);
268
-    }
269
-
270
-
271
-    /**
272
-     * Prepares a datetime value in ISO8601/RFC3339 format.
273
-     * It is assumed that the value of $datetime is in the format
274
-     * returned by EE_Base_Class::get_format().
275
-     *
276
-     * @param string        $datetime The datetime value.
277
-     * @param EE_Base_Class $source   The source object.
278
-     * @return string ISO8601/RFC3339 formatted datetime.
279
-     */
280
-    public function formatDatetime(string $datetime, EE_Base_Class $source): string
281
-    {
282
-        $format   = $source->get_format();
283
-        // create date object based on local timezone
284
-        $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
285
-        // change the timezone to UTC
286
-        $datetime->setTimezone(new DateTimeZone('UTC'));
287
-
288
-        return $datetime->format(DateTime::RFC3339);
289
-    }
290
-
291
-
292
-    /**
293
-     * Converts an object to JSON. The object must have a "toJson" method.
294
-     *
295
-     * @param string        $object   The object/value.
296
-     * @param EE_Base_Class $source   The source object.
297
-     * @return string JSON representation of the object.
298
-     */
299
-    public function toJson(JsonableInterface $object, EE_Base_Class $source): string
300
-    {
301
-        return $object->toJson();
302
-    }
37
+	/**
38
+	 * @var string $namespace The graphql namespace/prefix.
39
+	 */
40
+	protected $namespace = 'Espresso';
41
+
42
+	/**
43
+	 * @var EEM_Base $model
44
+	 */
45
+	protected $model;
46
+
47
+	/**
48
+	 * @var string $name
49
+	 */
50
+	protected $name = '';
51
+
52
+	/**
53
+	 * @var string $description
54
+	 */
55
+	protected $description = '';
56
+
57
+	/**
58
+	 * @var GraphQLFieldInterface[] $fields
59
+	 */
60
+	protected $fields = [];
61
+
62
+	/**
63
+	 * @var array $graphql_to_model_map
64
+	 */
65
+	protected $graphql_to_model_map = [];
66
+
67
+	/**
68
+	 * @var FieldResolver $field_resolver
69
+	 */
70
+	protected $field_resolver;
71
+
72
+	/**
73
+	 * @var bool $is_custom_post_type
74
+	 */
75
+	protected $is_custom_post_type = false;
76
+
77
+
78
+	/**
79
+	 * TypeBase constructor.
80
+	 *
81
+	 * @param EEM_Base|null $model
82
+	 */
83
+	public function __construct(EEM_Base $model = null)
84
+	{
85
+		$this->model = $model;
86
+		$this->setFields($this->getFields());
87
+		$this->field_resolver = new FieldResolver(
88
+			$this->model,
89
+			$this->getFieldsForResolver()
90
+		);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @return GraphQLFieldInterface[]
96
+	 * @since 5.0.0.p
97
+	 */
98
+	abstract protected function getFields(): array;
99
+
100
+
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function name(): string
105
+	{
106
+		return $this->name;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @param string $name
112
+	 */
113
+	protected function setName(string $name)
114
+	{
115
+		$this->name = $name;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function description(): string
123
+	{
124
+		return $this->description;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $description
130
+	 */
131
+	protected function setDescription(string $description)
132
+	{
133
+		$this->description = $description;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return GraphQLFieldInterface[]
139
+	 * @since 5.0.0.p
140
+	 */
141
+	public function fields(): array
142
+	{
143
+		return (array) $this->fields;
144
+	}
145
+
146
+
147
+	/**
148
+	 * @param GraphQLFieldInterface[] $fields
149
+	 */
150
+	protected function setFields(array $fields)
151
+	{
152
+		foreach ($fields as $field) {
153
+			if ($field instanceof GraphQLField) {
154
+				$this->fields[] = $field;
155
+			}
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Creates a key map for internal resolver.
162
+	 *
163
+	 * @return array
164
+	 * @since 5.0.0.p
165
+	 */
166
+	public function getFieldsForResolver(): array
167
+	{
168
+		$fields = [];
169
+		foreach ($this->fields() as $field) {
170
+			if ($field->useForOutput()) {
171
+				$fields[ $field->name() ] = $field;
172
+			}
173
+		}
174
+		return $fields;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @return bool
180
+	 */
181
+	public function isCustomPostType(): bool
182
+	{
183
+		return $this->is_custom_post_type;
184
+	}
185
+
186
+
187
+	/**
188
+	 * @param bool $is_custom_post_type
189
+	 */
190
+	protected function setIsCustomPostType(bool $is_custom_post_type)
191
+	{
192
+		$this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param int|float $value
198
+	 * @return int
199
+	 * @since 5.0.0.p
200
+	 */
201
+	public function parseInfiniteValue($value): int
202
+	{
203
+		$value = trim($value);
204
+		return $value === null
205
+			   || $value === ''
206
+			   || $value === '∞'
207
+			   || $value === 'INF'
208
+			   || $value === INF
209
+			   || $value === EE_INF
210
+			   || is_infinite((float) $value)
211
+			? -1
212
+			: $value;
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param mixed $source
218
+	 * @return EE_Base_Class|null
219
+	 * @throws EE_Error
220
+	 */
221
+	private function getModel($source): ?EE_Base_Class
222
+	{
223
+		// If it comes from a custom connection
224
+		// where the $source is already instantiated.
225
+		if ($source instanceof EE_Base_Class) {
226
+			return $source;
227
+		}
228
+		return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
234
+	 * @param array       $args    The inputArgs on the field
235
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
236
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
237
+	 * @return EE_Base_Class|Deferred|string|null
238
+	 * @throws EE_Error
239
+	 * @throws InvalidDataTypeException
240
+	 * @throws InvalidInterfaceException
241
+	 * @throws UnexpectedEntityException
242
+	 * @throws UserError
243
+	 * @throws InvalidArgumentException
244
+	 * @throws ReflectionException
245
+	 * @since 5.0.0.p
246
+	 */
247
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
248
+	{
249
+		$source = $source instanceof RootQuery ? $source : $this->getModel($source);
250
+
251
+		return $this->field_resolver->resolve($source, $args, $context, $info);
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param mixed      $payload The payload returned after mutation
257
+	 * @param array      $args    The inputArgs on the field
258
+	 * @param AppContext $context The AppContext passed down the GraphQL tree
259
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
260
+	 * @throws EE_Error
261
+	 */
262
+	public function resolveFromPayload($payload, array $args, AppContext $context)
263
+	{
264
+		if (empty($payload['id'])) {
265
+			return null;
266
+		}
267
+		return $this->model->get_one_by_ID($payload['id']);
268
+	}
269
+
270
+
271
+	/**
272
+	 * Prepares a datetime value in ISO8601/RFC3339 format.
273
+	 * It is assumed that the value of $datetime is in the format
274
+	 * returned by EE_Base_Class::get_format().
275
+	 *
276
+	 * @param string        $datetime The datetime value.
277
+	 * @param EE_Base_Class $source   The source object.
278
+	 * @return string ISO8601/RFC3339 formatted datetime.
279
+	 */
280
+	public function formatDatetime(string $datetime, EE_Base_Class $source): string
281
+	{
282
+		$format   = $source->get_format();
283
+		// create date object based on local timezone
284
+		$datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
285
+		// change the timezone to UTC
286
+		$datetime->setTimezone(new DateTimeZone('UTC'));
287
+
288
+		return $datetime->format(DateTime::RFC3339);
289
+	}
290
+
291
+
292
+	/**
293
+	 * Converts an object to JSON. The object must have a "toJson" method.
294
+	 *
295
+	 * @param string        $object   The object/value.
296
+	 * @param EE_Base_Class $source   The source object.
297
+	 * @return string JSON representation of the object.
298
+	 */
299
+	public function toJson(JsonableInterface $object, EE_Base_Class $source): string
300
+	{
301
+		return $object->toJson();
302
+	}
303 303
 }
Please login to merge, or discard this patch.
core/services/graphql/types/TypeCollection.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -20,89 +20,89 @@
 block discarded – undo
20 20
  */
21 21
 class TypeCollection extends Collection
22 22
 {
23
-    const COLLECTION_NAME = 'espresso_graphql_types';
23
+	const COLLECTION_NAME = 'espresso_graphql_types';
24 24
 
25
-    const COLLECTION_INTERFACE = 'EventEspresso\core\services\graphql\types\TypeInterface';
25
+	const COLLECTION_INTERFACE = 'EventEspresso\core\services\graphql\types\TypeInterface';
26 26
 
27
-    /**
28
-     * @var CollectionLoader $loader
29
-     */
30
-    protected $loader;
27
+	/**
28
+	 * @var CollectionLoader $loader
29
+	 */
30
+	protected $loader;
31 31
 
32 32
 
33
-    /**
34
-     * TypeCollection constructor
35
-     *
36
-     * @throws InvalidInterfaceException
37
-     */
38
-    public function __construct()
39
-    {
40
-        parent::__construct(
41
-            TypeCollection::COLLECTION_INTERFACE,
42
-            TypeCollection::COLLECTION_NAME
43
-        );
44
-    }
33
+	/**
34
+	 * TypeCollection constructor
35
+	 *
36
+	 * @throws InvalidInterfaceException
37
+	 */
38
+	public function __construct()
39
+	{
40
+		parent::__construct(
41
+			TypeCollection::COLLECTION_INTERFACE,
42
+			TypeCollection::COLLECTION_NAME
43
+		);
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * @throws CollectionDetailsException
49
-     * @throws CollectionLoaderException
50
-     * @since 5.0.0.p
51
-     */
52
-    private function loadCollection()
53
-    {
54
-        if (! $this->loader instanceof CollectionLoader) {
55
-            $this->loader = new CollectionLoader(
56
-                new CollectionDetails(
57
-                    // collection name
58
-                    TypeCollection::COLLECTION_NAME,
59
-                    // collection interface
60
-                    TypeCollection::COLLECTION_INTERFACE,
61
-                    // FQCNs for classes to add (all classes within each namespace will be loaded)
62
-                    apply_filters(
63
-                        'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs',
64
-                        ['EventEspresso\core\domain\services\graphql\types']
65
-                    ),
66
-                    // filepaths to classes to add
67
-                    array(),
68
-                    // file mask to use if parsing folder for files to add
69
-                    '',
70
-                    // what to use as identifier for collection entities
71
-                    // using CLASS NAME prevents duplicates (works like a singleton)
72
-                    CollectionDetails::ID_CLASS_NAME
73
-                ),
74
-                $this
75
-            );
76
-        }
77
-    }
47
+	/**
48
+	 * @throws CollectionDetailsException
49
+	 * @throws CollectionLoaderException
50
+	 * @since 5.0.0.p
51
+	 */
52
+	private function loadCollection()
53
+	{
54
+		if (! $this->loader instanceof CollectionLoader) {
55
+			$this->loader = new CollectionLoader(
56
+				new CollectionDetails(
57
+					// collection name
58
+					TypeCollection::COLLECTION_NAME,
59
+					// collection interface
60
+					TypeCollection::COLLECTION_INTERFACE,
61
+					// FQCNs for classes to add (all classes within each namespace will be loaded)
62
+					apply_filters(
63
+						'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs',
64
+						['EventEspresso\core\domain\services\graphql\types']
65
+					),
66
+					// filepaths to classes to add
67
+					array(),
68
+					// file mask to use if parsing folder for files to add
69
+					'',
70
+					// what to use as identifier for collection entities
71
+					// using CLASS NAME prevents duplicates (works like a singleton)
72
+					CollectionDetails::ID_CLASS_NAME
73
+				),
74
+				$this
75
+			);
76
+		}
77
+	}
78 78
 
79 79
 
80
-    /**
81
-     * @return CollectionInterface
82
-     * @throws CollectionDetailsException
83
-     * @throws CollectionLoaderException
84
-     * @since 5.0.0.p
85
-     */
86
-    public function loadTypes()
87
-    {
88
-        $this->loadCollection();
89
-        return $this->loader->getCollection();
90
-    }
80
+	/**
81
+	 * @return CollectionInterface
82
+	 * @throws CollectionDetailsException
83
+	 * @throws CollectionLoaderException
84
+	 * @since 5.0.0.p
85
+	 */
86
+	public function loadTypes()
87
+	{
88
+		$this->loadCollection();
89
+		return $this->loader->getCollection();
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * getIdentifier
95
-     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
96
-     * If no $identifier is supplied, then the  fully qualified class name is used
97
-     *
98
-     * @param        $object
99
-     * @param mixed  $identifier
100
-     * @return bool
101
-     */
102
-    public function getIdentifier($object, $identifier = null)
103
-    {
104
-        return ! empty($identifier)
105
-            ? $identifier
106
-            : get_class($object);
107
-    }
93
+	/**
94
+	 * getIdentifier
95
+	 * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
96
+	 * If no $identifier is supplied, then the  fully qualified class name is used
97
+	 *
98
+	 * @param        $object
99
+	 * @param mixed  $identifier
100
+	 * @return bool
101
+	 */
102
+	public function getIdentifier($object, $identifier = null)
103
+	{
104
+		return ! empty($identifier)
105
+			? $identifier
106
+			: get_class($object);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
core/services/graphql/types/TypeInterface.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -23,79 +23,79 @@
 block discarded – undo
23 23
  */
24 24
 interface TypeInterface
25 25
 {
26
-    /**
27
-     * @return string
28
-     */
29
-    public function name(): string;
30
-
31
-
32
-    /**
33
-     * @return string
34
-     */
35
-    public function description(): string;
36
-
37
-
38
-    /**
39
-     * @return GraphQLFieldInterface[]
40
-     * @since 5.0.0.p
41
-     */
42
-    public function fields(): array;
43
-
44
-
45
-    /**
46
-     * Creates a key map for internal resolver.
47
-     *
48
-     * @return array
49
-     * @since 5.0.0.p
50
-     */
51
-    public function getFieldsForResolver(): array;
52
-
53
-
54
-    /**
55
-     * @return bool
56
-     */
57
-    public function isCustomPostType(): bool;
58
-
59
-
60
-    /**
61
-     * @param int|float $value
62
-     * @return int
63
-     * @since 5.0.0.p
64
-     */
65
-    public function parseInfiniteValue($value): int;
66
-
67
-
68
-    /**
69
-     * @param mixed       $source  The source that's passed down the GraphQL queries
70
-     * @param array       $args    The inputArgs on the field
71
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
72
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
73
-     * @return mixed
74
-     * @throws EE_Error
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws UnexpectedEntityException
78
-     * @throws UserError
79
-     * @throws InvalidArgumentException
80
-     * @throws ReflectionException
81
-     * @since 5.0.0.p
82
-     */
83
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info);
84
-
85
-
86
-    /**
87
-     * @param mixed      $payload The payload returned after mutation
88
-     * @param array      $args    The inputArgs on the field
89
-     * @param AppContext $context The AppContext passed down the GraphQL tree
90
-     * @return string|null
91
-     * @throws EE_Error
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidInterfaceException
94
-     * @throws UnexpectedEntityException
95
-     * @throws UserError
96
-     * @throws InvalidArgumentException
97
-     * @throws ReflectionException
98
-     * @since 5.0.0.p
99
-     */
100
-    public function resolveFromPayload($payload, array $args, AppContext $context);
26
+	/**
27
+	 * @return string
28
+	 */
29
+	public function name(): string;
30
+
31
+
32
+	/**
33
+	 * @return string
34
+	 */
35
+	public function description(): string;
36
+
37
+
38
+	/**
39
+	 * @return GraphQLFieldInterface[]
40
+	 * @since 5.0.0.p
41
+	 */
42
+	public function fields(): array;
43
+
44
+
45
+	/**
46
+	 * Creates a key map for internal resolver.
47
+	 *
48
+	 * @return array
49
+	 * @since 5.0.0.p
50
+	 */
51
+	public function getFieldsForResolver(): array;
52
+
53
+
54
+	/**
55
+	 * @return bool
56
+	 */
57
+	public function isCustomPostType(): bool;
58
+
59
+
60
+	/**
61
+	 * @param int|float $value
62
+	 * @return int
63
+	 * @since 5.0.0.p
64
+	 */
65
+	public function parseInfiniteValue($value): int;
66
+
67
+
68
+	/**
69
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
70
+	 * @param array       $args    The inputArgs on the field
71
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
72
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
73
+	 * @return mixed
74
+	 * @throws EE_Error
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws UnexpectedEntityException
78
+	 * @throws UserError
79
+	 * @throws InvalidArgumentException
80
+	 * @throws ReflectionException
81
+	 * @since 5.0.0.p
82
+	 */
83
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info);
84
+
85
+
86
+	/**
87
+	 * @param mixed      $payload The payload returned after mutation
88
+	 * @param array      $args    The inputArgs on the field
89
+	 * @param AppContext $context The AppContext passed down the GraphQL tree
90
+	 * @return string|null
91
+	 * @throws EE_Error
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidInterfaceException
94
+	 * @throws UnexpectedEntityException
95
+	 * @throws UserError
96
+	 * @throws InvalidArgumentException
97
+	 * @throws ReflectionException
98
+	 * @since 5.0.0.p
99
+	 */
100
+	public function resolveFromPayload($payload, array $args, AppContext $context);
101 101
 }
Please login to merge, or discard this patch.
core/services/database/WordPressOption.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -17,181 +17,181 @@
 block discarded – undo
17 17
  */
18 18
 abstract class WordPressOption
19 19
 {
20
-    public const NOT_SET_YET = 'wordpress-option-value-not-yet-set';
21
-
22
-    /**
23
-     * WordPress makes it difficult to determine if an option successfully saved or not,
24
-     * which is sometimes really important to know, especially if the information you are saving is critical.
25
-     * The following options allow us to have a better chance of knowing when an update actually failed
26
-     * or when everything is OK but it just didn't update because the value hasn't changed.
27
-     */
28
-    public const UPDATE_SUCCESS = 1;
29
-
30
-    public const UPDATE_NONE = 0;
31
-
32
-    public const UPDATE_ERROR = -1;
33
-
34
-    /**
35
-     * @var bool
36
-     */
37
-    private $autoload = false;
38
-
39
-    /**
40
-     * @var mixed
41
-     */
42
-    private $default_value = null;
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    private $option_name = '';
48
-
49
-    /**
50
-     * @var mixed
51
-     */
52
-    private $value = WordPressOption::NOT_SET_YET;
53
-
54
-    /**
55
-     * @var OptionEngine
56
-     */
57
-    private $option_engine;
58
-
59
-
60
-    /**
61
-     * WordPressOption constructor.
62
-     *
63
-     * @param string $option_name
64
-     * @param mixed  $default_value
65
-     * @param bool   $autoload              if true, will load the option on EVERY request
66
-     * @param bool   $is_network_option     if true, will save the option to the network as opposed to the current blog
67
-     */
68
-    public function __construct(
69
-        string $option_name,
70
-        $default_value,
71
-        bool $autoload = false,
72
-        bool $is_network_option = false
73
-    ) {
74
-        $this->setAutoload($autoload);
75
-        $this->setDefaultValue($default_value);
76
-        $this->setOptionName($option_name);
77
-        $this->option_engine = new OptionEngine($is_network_option);
78
-    }
79
-
80
-
81
-    /**
82
-     * @param bool|string $autoload
83
-     */
84
-    public function setAutoload($autoload): void
85
-    {
86
-        $this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN);
87
-    }
88
-
89
-
90
-    /**
91
-     * @param mixed $default_value
92
-     */
93
-    public function setDefaultValue($default_value): void
94
-    {
95
-        $this->default_value = $default_value;
96
-    }
97
-
98
-
99
-    /**
100
-     * @param string $option_name
101
-     */
102
-    public function setOptionName(string $option_name): void
103
-    {
104
-        $this->option_name = sanitize_key($option_name);
105
-    }
106
-
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function optionExists(): string
112
-    {
113
-        return $this->option_engine->getOption(
114
-            $this->getOptionName(),
115
-            WordPressOption::NOT_SET_YET
116
-        ) !== WordPressOption::NOT_SET_YET;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function getOptionName(): string
124
-    {
125
-        return $this->option_name;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return false|mixed|void
131
-     */
132
-    public function loadOption()
133
-    {
134
-        if ($this->value === WordPressOption::NOT_SET_YET) {
135
-            $this->value = $this->option_engine->getOption($this->getOptionName(), $this->default_value);
136
-        }
137
-        return $this->value;
138
-    }
139
-
140
-
141
-    /**
142
-     * @param $value
143
-     * @return int
144
-     */
145
-    public function updateOption($value): int
146
-    {
147
-        // don't update if value has not changed since last update
148
-        if ($this->valueIsUnchanged($value)) {
149
-            return WordPressOption::UPDATE_NONE;
150
-        }
151
-        $this->value = $value;
152
-        // because the options for updating differ when adding an option for the first time
153
-        // we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db
154
-        $updated = $this->optionExists()
155
-            ? $this->option_engine->updateOption($this->getOptionName(), $this->value)
156
-            : $this->option_engine->addOption($this->getOptionName(), $this->value, $this->autoload());
157
-
158
-        if ($updated) {
159
-            return WordPressOption::UPDATE_SUCCESS;
160
-        }
161
-        return WordPressOption::UPDATE_ERROR;
162
-    }
163
-
164
-
165
-    private function valueIsUnchanged($value): bool
166
-    {
167
-        if (is_array($value) && is_array($this->value)) {
168
-            $diff = EEH_Array::array_diff_recursive($value, $this->value);
169
-            // $diff = array_diff($value, $this->value);
170
-            return empty($diff);
171
-        }
172
-        // emulate WP's method for checking equality
173
-        return $value === $this->value && maybe_serialize($value) === maybe_serialize($this->value);
174
-    }
175
-
176
-
177
-    /**
178
-     * @return string
179
-     */
180
-    private function autoload(): string
181
-    {
182
-        return $this->autoload ? 'yes' : 'no';
183
-    }
184
-
185
-
186
-    /**
187
-     * Deletes the option from the database
188
-     * for the rest of the request
189
-     *
190
-     * @return bool
191
-     * @since  5.0.0.p
192
-     */
193
-    public function deleteOption(): bool
194
-    {
195
-        return $this->option_engine->deleteOption($this->getOptionName());
196
-    }
20
+	public const NOT_SET_YET = 'wordpress-option-value-not-yet-set';
21
+
22
+	/**
23
+	 * WordPress makes it difficult to determine if an option successfully saved or not,
24
+	 * which is sometimes really important to know, especially if the information you are saving is critical.
25
+	 * The following options allow us to have a better chance of knowing when an update actually failed
26
+	 * or when everything is OK but it just didn't update because the value hasn't changed.
27
+	 */
28
+	public const UPDATE_SUCCESS = 1;
29
+
30
+	public const UPDATE_NONE = 0;
31
+
32
+	public const UPDATE_ERROR = -1;
33
+
34
+	/**
35
+	 * @var bool
36
+	 */
37
+	private $autoload = false;
38
+
39
+	/**
40
+	 * @var mixed
41
+	 */
42
+	private $default_value = null;
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	private $option_name = '';
48
+
49
+	/**
50
+	 * @var mixed
51
+	 */
52
+	private $value = WordPressOption::NOT_SET_YET;
53
+
54
+	/**
55
+	 * @var OptionEngine
56
+	 */
57
+	private $option_engine;
58
+
59
+
60
+	/**
61
+	 * WordPressOption constructor.
62
+	 *
63
+	 * @param string $option_name
64
+	 * @param mixed  $default_value
65
+	 * @param bool   $autoload              if true, will load the option on EVERY request
66
+	 * @param bool   $is_network_option     if true, will save the option to the network as opposed to the current blog
67
+	 */
68
+	public function __construct(
69
+		string $option_name,
70
+		$default_value,
71
+		bool $autoload = false,
72
+		bool $is_network_option = false
73
+	) {
74
+		$this->setAutoload($autoload);
75
+		$this->setDefaultValue($default_value);
76
+		$this->setOptionName($option_name);
77
+		$this->option_engine = new OptionEngine($is_network_option);
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param bool|string $autoload
83
+	 */
84
+	public function setAutoload($autoload): void
85
+	{
86
+		$this->autoload = filter_var($autoload, FILTER_VALIDATE_BOOLEAN);
87
+	}
88
+
89
+
90
+	/**
91
+	 * @param mixed $default_value
92
+	 */
93
+	public function setDefaultValue($default_value): void
94
+	{
95
+		$this->default_value = $default_value;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param string $option_name
101
+	 */
102
+	public function setOptionName(string $option_name): void
103
+	{
104
+		$this->option_name = sanitize_key($option_name);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return string
110
+	 */
111
+	public function optionExists(): string
112
+	{
113
+		return $this->option_engine->getOption(
114
+			$this->getOptionName(),
115
+			WordPressOption::NOT_SET_YET
116
+		) !== WordPressOption::NOT_SET_YET;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function getOptionName(): string
124
+	{
125
+		return $this->option_name;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return false|mixed|void
131
+	 */
132
+	public function loadOption()
133
+	{
134
+		if ($this->value === WordPressOption::NOT_SET_YET) {
135
+			$this->value = $this->option_engine->getOption($this->getOptionName(), $this->default_value);
136
+		}
137
+		return $this->value;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param $value
143
+	 * @return int
144
+	 */
145
+	public function updateOption($value): int
146
+	{
147
+		// don't update if value has not changed since last update
148
+		if ($this->valueIsUnchanged($value)) {
149
+			return WordPressOption::UPDATE_NONE;
150
+		}
151
+		$this->value = $value;
152
+		// because the options for updating differ when adding an option for the first time
153
+		// we use the WordPressOption::NOT_SET_YET to determine if things already exist in the db
154
+		$updated = $this->optionExists()
155
+			? $this->option_engine->updateOption($this->getOptionName(), $this->value)
156
+			: $this->option_engine->addOption($this->getOptionName(), $this->value, $this->autoload());
157
+
158
+		if ($updated) {
159
+			return WordPressOption::UPDATE_SUCCESS;
160
+		}
161
+		return WordPressOption::UPDATE_ERROR;
162
+	}
163
+
164
+
165
+	private function valueIsUnchanged($value): bool
166
+	{
167
+		if (is_array($value) && is_array($this->value)) {
168
+			$diff = EEH_Array::array_diff_recursive($value, $this->value);
169
+			// $diff = array_diff($value, $this->value);
170
+			return empty($diff);
171
+		}
172
+		// emulate WP's method for checking equality
173
+		return $value === $this->value && maybe_serialize($value) === maybe_serialize($this->value);
174
+	}
175
+
176
+
177
+	/**
178
+	 * @return string
179
+	 */
180
+	private function autoload(): string
181
+	{
182
+		return $this->autoload ? 'yes' : 'no';
183
+	}
184
+
185
+
186
+	/**
187
+	 * Deletes the option from the database
188
+	 * for the rest of the request
189
+	 *
190
+	 * @return bool
191
+	 * @since  5.0.0.p
192
+	 */
193
+	public function deleteOption(): bool
194
+	{
195
+		return $this->option_engine->deleteOption($this->getOptionName());
196
+	}
197 197
 }
Please login to merge, or discard this patch.
core/services/i18n/LegacyTextDomainOptions.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -14,53 +14,53 @@
 block discarded – undo
14 14
  */
15 15
 class LegacyTextDomainOptions
16 16
 {
17
-    /**
18
-     * @var LoadedTextDomains
19
-     */
20
-    private $loaded_text_domains;
17
+	/**
18
+	 * @var LoadedTextDomains
19
+	 */
20
+	private $loaded_text_domains;
21 21
 
22 22
 
23
-    /**
24
-     * @param LoadedTextDomains|null $loaded_text_domains
25
-     */
26
-    public function __construct(?LoadedTextDomains $loaded_text_domains = null)
27
-    {
28
-        $this->loaded_text_domains = $loaded_text_domains ?? new LoadedTextDomains();
29
-    }
23
+	/**
24
+	 * @param LoadedTextDomains|null $loaded_text_domains
25
+	 */
26
+	public function __construct(?LoadedTextDomains $loaded_text_domains = null)
27
+	{
28
+		$this->loaded_text_domains = $loaded_text_domains ?? new LoadedTextDomains();
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * attempts to collect all of the ee_lang_check_* options stored in the database
34
-     * and add them to one single option handled by EventEspresso\core\services\i18n\LoadedTextDomains
35
-     *
36
-     * @since   5.0.0.p
37
-     */
38
-    public function convertToConsolidatedFormat()
39
-    {
40
-        $options = wp_load_alloptions();
41
-        foreach ($options as $slug => $values) {
42
-            if (strpos($slug, 'ee_lang_check_') === 0) {
43
-                // convert something like "ee_lang_check_en_CA_4.10.39.rc.018" to 'en_CA_4.10.39.rc.018'
44
-                $locale_version = str_replace('ee_lang_check_', '', $slug);
45
-                // split 'en_CA_4.10.39.rc.018' into [ 'en', 'CA', '4.10.39.rc.018' ]
46
-                $locale_version = explode('_', $locale_version);
47
-                $locale         = null;
48
-                $version        = null;
49
-                switch (count($locale_version)) {
50
-                    case 3:
51
-                        $locale  = "$locale_version[0]_$locale_version[1]";
52
-                        $version = $locale_version[2];
53
-                        break;
54
-                    case 2:
55
-                        $locale  = $locale_version[0];
56
-                        $version = $locale_version[1];
57
-                        break;
58
-                }
59
-                if ($locale && $version) {
60
-                    $this->loaded_text_domains->versionLoaded($locale, $version);
61
-                    delete_option($slug);
62
-                }
63
-            }
64
-        }
65
-    }
32
+	/**
33
+	 * attempts to collect all of the ee_lang_check_* options stored in the database
34
+	 * and add them to one single option handled by EventEspresso\core\services\i18n\LoadedTextDomains
35
+	 *
36
+	 * @since   5.0.0.p
37
+	 */
38
+	public function convertToConsolidatedFormat()
39
+	{
40
+		$options = wp_load_alloptions();
41
+		foreach ($options as $slug => $values) {
42
+			if (strpos($slug, 'ee_lang_check_') === 0) {
43
+				// convert something like "ee_lang_check_en_CA_4.10.39.rc.018" to 'en_CA_4.10.39.rc.018'
44
+				$locale_version = str_replace('ee_lang_check_', '', $slug);
45
+				// split 'en_CA_4.10.39.rc.018' into [ 'en', 'CA', '4.10.39.rc.018' ]
46
+				$locale_version = explode('_', $locale_version);
47
+				$locale         = null;
48
+				$version        = null;
49
+				switch (count($locale_version)) {
50
+					case 3:
51
+						$locale  = "$locale_version[0]_$locale_version[1]";
52
+						$version = $locale_version[2];
53
+						break;
54
+					case 2:
55
+						$locale  = $locale_version[0];
56
+						$version = $locale_version[1];
57
+						break;
58
+				}
59
+				if ($locale && $version) {
60
+					$this->loaded_text_domains->versionLoaded($locale, $version);
61
+					delete_option($slug);
62
+				}
63
+			}
64
+		}
65
+	}
66 66
 }
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 1 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}". Asset::EXT_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   5.0.0.p
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}". Asset::EXT_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   5.0.0.p
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 5.0.0.p
341
-     */
342
-    public function addManifestFile()
343
-    {
344
-    }
345
-
346
-
347
-    /**
348
-     * @return void
349
-     * @deprecated 5.0.0.p
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 5.0.0.p
341
+	 */
342
+	public function addManifestFile()
343
+	{
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return void
349
+	 * @deprecated 5.0.0.p
350
+	 */
351
+	public function getManifestFile()
352
+	{
353
+	}
354 354
 }
Please login to merge, or discard this patch.
core/services/assets/I18nRegistry.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,46 +13,46 @@
 block discarded – undo
13 13
  */
14 14
 class I18nRegistry
15 15
 {
16
-    /**
17
-     * @var DomainInterface
18
-     */
19
-    private $domain;
16
+	/**
17
+	 * @var DomainInterface
18
+	 */
19
+	private $domain;
20 20
 
21
-    /**
22
-     * @var JedLocaleData $jed_locale
23
-     */
24
-    private $jed_locale;
21
+	/**
22
+	 * @var JedLocaleData $jed_locale
23
+	 */
24
+	private $jed_locale;
25 25
 
26
-    /**
27
-     * I18nRegistry constructor.
28
-     *
29
-     * @param DomainInterface $domain
30
-     * @param JedLocaleData $jed_locale
31
-     * @param array() $i18n_map
32
-     * @deprecated 5.0.0.p
33
-     */
34
-    public function __construct(DomainInterface $domain, JedLocaleData $jed_locale, array $i18n_map = [])
35
-    {
36
-        $this->domain = $domain;
37
-        $this->jed_locale = $jed_locale;
38
-    }
26
+	/**
27
+	 * I18nRegistry constructor.
28
+	 *
29
+	 * @param DomainInterface $domain
30
+	 * @param JedLocaleData $jed_locale
31
+	 * @param array() $i18n_map
32
+	 * @deprecated 5.0.0.p
33
+	 */
34
+	public function __construct(DomainInterface $domain, JedLocaleData $jed_locale, array $i18n_map = [])
35
+	{
36
+		$this->domain = $domain;
37
+		$this->jed_locale = $jed_locale;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $handle The script handle reference.
42
-     * @param string $domain The i18n domain for the strings.
43
-     * @deprecated 5.0.0.p
44
-     */
45
-    public function registerScriptI18n(string $handle, string $domain = Domain::TEXT_DOMAIN)
46
-    {
47
-    }
40
+	/**
41
+	 * @param string $handle The script handle reference.
42
+	 * @param string $domain The i18n domain for the strings.
43
+	 * @deprecated 5.0.0.p
44
+	 */
45
+	public function registerScriptI18n(string $handle, string $domain = Domain::TEXT_DOMAIN)
46
+	{
47
+	}
48 48
 
49
-    /**
50
-     * @param array $handles Array of registered script handles.
51
-     * @return array
52
-     * @deprecated 5.0.0.p
53
-     */
54
-    public function queueI18n(array $handles): array
55
-    {
56
-        return $handles;
57
-    }
49
+	/**
50
+	 * @param array $handles Array of registered script handles.
51
+	 * @return array
52
+	 * @deprecated 5.0.0.p
53
+	 */
54
+	public function queueI18n(array $handles): array
55
+	{
56
+		return $handles;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +570 added lines, -570 removed lines patch added patch discarded remove patch
@@ -25,581 +25,581 @@
 block discarded – undo
25 25
 class Registry
26 26
 {
27 27
 
28
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
29
-
30
-    /**
31
-     * @var AssetCollection[] $assets
32
-     */
33
-    protected $assets = [];
34
-
35
-    /**
36
-     * @var AssetManifestInterface
37
-     */
38
-    private $asset_manifest;
39
-
40
-    /**
41
-     * This holds the js_data data object that will be exposed on pages that enqueue the `eejs-core` script.
42
-     *
43
-     * @var array
44
-     */
45
-    protected $js_data = [];
46
-
47
-    /**
48
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
49
-     * page source.
50
-     *
51
-     * @var array
52
-     */
53
-    private $script_handles_with_data = [];
54
-
55
-
56
-    /**
57
-     * Registry constructor.
58
-     * Hooking into WP actions for script registry.
59
-     *
60
-     * @param AssetCollection        $assets
61
-     * @param AssetManifestInterface $asset_manifest
62
-     * @throws InvalidArgumentException
63
-     * @throws InvalidDataTypeException
64
-     * @throws InvalidInterfaceException
65
-     */
66
-    public function __construct(AssetCollection $assets, AssetManifestInterface $asset_manifest)
67
-    {
68
-        $this->addAssetCollection($assets);
69
-        $this->asset_manifest = $asset_manifest;
70
-        $this->asset_manifest->initialize();
71
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
72
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
73
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 5);
74
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 5);
75
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
76
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
77
-    }
78
-
79
-
80
-    /**
81
-     * @param AssetCollection $asset_collection
82
-     */
83
-    public function addAssetCollection(AssetCollection $asset_collection)
84
-    {
85
-        $id = $asset_collection->collectionIdentifier();
86
-        if (! array_key_exists($id, $this->assets)) {
87
-            $this->assets[ $id ] = $asset_collection;
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Callback for the wp_enqueue_scripts actions used to register assets.
95
-     *
96
-     * @throws Exception
97
-     * @since 4.9.62.p
98
-     */
99
-    public function registerScriptsAndStyles()
100
-    {
101
-        try {
102
-            foreach ($this->assets as $asset_collection) {
103
-                $this->registerScripts($asset_collection->getJavascriptAssets());
104
-                $this->registerStyles($asset_collection->getStylesheetAssets());
105
-            }
106
-        } catch (Exception $exception) {
107
-            new ExceptionStackTraceDisplay($exception);
108
-        }
109
-    }
110
-
111
-
112
-    /**
113
-     * Registers JS assets with WP core
114
-     *
115
-     * @param JavascriptAsset[] $scripts
116
-     * @throws AssetRegistrationException
117
-     * @throws InvalidDataTypeException
118
-     * @throws DomainException
119
-     * @since 4.9.62.p
120
-     */
121
-    public function registerScripts(array $scripts)
122
-    {
123
-        foreach ($scripts as $script) {
124
-            // skip to next script if this has already been done
125
-            if ($script->isRegistered()) {
126
-                continue;
127
-            }
128
-            do_action(
129
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
130
-                $script
131
-            );
132
-            $registered = wp_register_script(
133
-                $script->handle(),
134
-                $script->source(),
135
-                $script->dependencies(),
136
-                $script->version(),
137
-                $script->loadInFooter()
138
-            );
139
-            if (! $registered && $this->debug()) {
140
-                throw new AssetRegistrationException($script->handle());
141
-            }
142
-            $script->setRegistered($registered);
143
-            if ($script->enqueueImmediately()) {
144
-                wp_enqueue_script($script->handle());
145
-            }
146
-            do_action(
147
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
148
-                $script
149
-            );
150
-        }
151
-    }
152
-
153
-
154
-    /**
155
-     * Registers CSS assets with WP core
156
-     *
157
-     * @param StylesheetAsset[] $styles
158
-     * @throws InvalidDataTypeException
159
-     * @throws DomainException
160
-     * @since 4.9.62.p
161
-     */
162
-    public function registerStyles(array $styles)
163
-    {
164
-        foreach ($styles as $style) {
165
-            // skip to next style if this has already been done
166
-            if ($style->isRegistered()) {
167
-                continue;
168
-            }
169
-            do_action(
170
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
171
-                $style
172
-            );
173
-            wp_register_style(
174
-                $style->handle(),
175
-                $style->source(),
176
-                $style->dependencies(),
177
-                $style->version(),
178
-                $style->media()
179
-            );
180
-            $style->setRegistered();
181
-            if ($style->enqueueImmediately()) {
182
-                wp_enqueue_style($style->handle());
183
-            }
184
-            do_action(
185
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
186
-                $style
187
-            );
188
-        }
189
-    }
190
-
191
-
192
-    /**
193
-     * Call back for the script print in frontend and backend.
194
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
195
-     *
196
-     * @throws Exception
197
-     * @since 4.9.31.rc.015
198
-     */
199
-    public function enqueueData()
200
-    {
201
-        try {
202
-            $this->removeAlreadyRegisteredDataForScriptHandles();
203
-            wp_add_inline_script(
204
-                CoreAssetManager::JS_HANDLE_JS_CORE,
205
-                'var eejsdata=' . wp_json_encode(['data' => $this->js_data]),
206
-                'before'
207
-            );
208
-            foreach ($this->assets as $asset_collection) {
209
-                $scripts = $asset_collection->getJavascriptAssetsWithData();
210
-                foreach ($scripts as $script) {
211
-                    $this->addRegisteredScriptHandlesWithData($script->handle());
212
-                    if ($script->hasInlineDataCallback()) {
213
-                        $localize = $script->inlineDataCallback();
214
-                        $localize();
215
-                    }
216
-                }
217
-            }
218
-        } catch (Exception $exception) {
219
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
220
-            new ExceptionStackTraceDisplay($exception);
221
-        }
222
-    }
223
-
224
-
225
-    /**
226
-     * Used to add data to eejs.data object.
227
-     * Note:  Overriding existing data is not allowed.
228
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
229
-     * If the data you add is something like this:
230
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
231
-     * It will be exposed in the page source as:
232
-     *  eejs.data.my_plugin_data.foo == gar
233
-     *
234
-     * @param string       $key   Key used to access your data
235
-     * @param string|array $value Value to attach to key
236
-     * @throws InvalidArgumentException
237
-     */
238
-    public function addData(string $key, $value)
239
-    {
240
-        if ($this->verifyDataNotExisting($key)) {
241
-            $this->js_data[ $key ] = $value;
242
-        }
243
-    }
244
-
245
-
246
-    /**
247
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
248
-     * elements in an array.
249
-     *
250
-     * When you use this method, the value you include will be merged with the array on $key.
251
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
252
-     * object like this, eejs.data.test = [ my_data,
253
-     * ]
254
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
255
-     * this will throw an exception.
256
-     *
257
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
258
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
259
-     *
260
-     * @param string       $key   Key to attach data to.
261
-     * @param string|array $value Value being registered.
262
-     * @throws InvalidArgumentException
263
-     */
264
-    public function pushData(string $key, $value)
265
-    {
266
-        if (
267
-            isset($this->js_data[ $key ])
268
-            && ! is_array($this->js_data[ $key ])
269
-        ) {
270
-            if (! $this->debug()) {
271
-                return;
272
-            }
273
-            throw new InvalidArgumentException(
274
-                sprintf(
275
-                    esc_html__(
276
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
28
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
29
+
30
+	/**
31
+	 * @var AssetCollection[] $assets
32
+	 */
33
+	protected $assets = [];
34
+
35
+	/**
36
+	 * @var AssetManifestInterface
37
+	 */
38
+	private $asset_manifest;
39
+
40
+	/**
41
+	 * This holds the js_data data object that will be exposed on pages that enqueue the `eejs-core` script.
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $js_data = [];
46
+
47
+	/**
48
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
49
+	 * page source.
50
+	 *
51
+	 * @var array
52
+	 */
53
+	private $script_handles_with_data = [];
54
+
55
+
56
+	/**
57
+	 * Registry constructor.
58
+	 * Hooking into WP actions for script registry.
59
+	 *
60
+	 * @param AssetCollection        $assets
61
+	 * @param AssetManifestInterface $asset_manifest
62
+	 * @throws InvalidArgumentException
63
+	 * @throws InvalidDataTypeException
64
+	 * @throws InvalidInterfaceException
65
+	 */
66
+	public function __construct(AssetCollection $assets, AssetManifestInterface $asset_manifest)
67
+	{
68
+		$this->addAssetCollection($assets);
69
+		$this->asset_manifest = $asset_manifest;
70
+		$this->asset_manifest->initialize();
71
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
72
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
73
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 5);
74
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 5);
75
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
76
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
77
+	}
78
+
79
+
80
+	/**
81
+	 * @param AssetCollection $asset_collection
82
+	 */
83
+	public function addAssetCollection(AssetCollection $asset_collection)
84
+	{
85
+		$id = $asset_collection->collectionIdentifier();
86
+		if (! array_key_exists($id, $this->assets)) {
87
+			$this->assets[ $id ] = $asset_collection;
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
95
+	 *
96
+	 * @throws Exception
97
+	 * @since 4.9.62.p
98
+	 */
99
+	public function registerScriptsAndStyles()
100
+	{
101
+		try {
102
+			foreach ($this->assets as $asset_collection) {
103
+				$this->registerScripts($asset_collection->getJavascriptAssets());
104
+				$this->registerStyles($asset_collection->getStylesheetAssets());
105
+			}
106
+		} catch (Exception $exception) {
107
+			new ExceptionStackTraceDisplay($exception);
108
+		}
109
+	}
110
+
111
+
112
+	/**
113
+	 * Registers JS assets with WP core
114
+	 *
115
+	 * @param JavascriptAsset[] $scripts
116
+	 * @throws AssetRegistrationException
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws DomainException
119
+	 * @since 4.9.62.p
120
+	 */
121
+	public function registerScripts(array $scripts)
122
+	{
123
+		foreach ($scripts as $script) {
124
+			// skip to next script if this has already been done
125
+			if ($script->isRegistered()) {
126
+				continue;
127
+			}
128
+			do_action(
129
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
130
+				$script
131
+			);
132
+			$registered = wp_register_script(
133
+				$script->handle(),
134
+				$script->source(),
135
+				$script->dependencies(),
136
+				$script->version(),
137
+				$script->loadInFooter()
138
+			);
139
+			if (! $registered && $this->debug()) {
140
+				throw new AssetRegistrationException($script->handle());
141
+			}
142
+			$script->setRegistered($registered);
143
+			if ($script->enqueueImmediately()) {
144
+				wp_enqueue_script($script->handle());
145
+			}
146
+			do_action(
147
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
148
+				$script
149
+			);
150
+		}
151
+	}
152
+
153
+
154
+	/**
155
+	 * Registers CSS assets with WP core
156
+	 *
157
+	 * @param StylesheetAsset[] $styles
158
+	 * @throws InvalidDataTypeException
159
+	 * @throws DomainException
160
+	 * @since 4.9.62.p
161
+	 */
162
+	public function registerStyles(array $styles)
163
+	{
164
+		foreach ($styles as $style) {
165
+			// skip to next style if this has already been done
166
+			if ($style->isRegistered()) {
167
+				continue;
168
+			}
169
+			do_action(
170
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
171
+				$style
172
+			);
173
+			wp_register_style(
174
+				$style->handle(),
175
+				$style->source(),
176
+				$style->dependencies(),
177
+				$style->version(),
178
+				$style->media()
179
+			);
180
+			$style->setRegistered();
181
+			if ($style->enqueueImmediately()) {
182
+				wp_enqueue_style($style->handle());
183
+			}
184
+			do_action(
185
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
186
+				$style
187
+			);
188
+		}
189
+	}
190
+
191
+
192
+	/**
193
+	 * Call back for the script print in frontend and backend.
194
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
195
+	 *
196
+	 * @throws Exception
197
+	 * @since 4.9.31.rc.015
198
+	 */
199
+	public function enqueueData()
200
+	{
201
+		try {
202
+			$this->removeAlreadyRegisteredDataForScriptHandles();
203
+			wp_add_inline_script(
204
+				CoreAssetManager::JS_HANDLE_JS_CORE,
205
+				'var eejsdata=' . wp_json_encode(['data' => $this->js_data]),
206
+				'before'
207
+			);
208
+			foreach ($this->assets as $asset_collection) {
209
+				$scripts = $asset_collection->getJavascriptAssetsWithData();
210
+				foreach ($scripts as $script) {
211
+					$this->addRegisteredScriptHandlesWithData($script->handle());
212
+					if ($script->hasInlineDataCallback()) {
213
+						$localize = $script->inlineDataCallback();
214
+						$localize();
215
+					}
216
+				}
217
+			}
218
+		} catch (Exception $exception) {
219
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
220
+			new ExceptionStackTraceDisplay($exception);
221
+		}
222
+	}
223
+
224
+
225
+	/**
226
+	 * Used to add data to eejs.data object.
227
+	 * Note:  Overriding existing data is not allowed.
228
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
229
+	 * If the data you add is something like this:
230
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
231
+	 * It will be exposed in the page source as:
232
+	 *  eejs.data.my_plugin_data.foo == gar
233
+	 *
234
+	 * @param string       $key   Key used to access your data
235
+	 * @param string|array $value Value to attach to key
236
+	 * @throws InvalidArgumentException
237
+	 */
238
+	public function addData(string $key, $value)
239
+	{
240
+		if ($this->verifyDataNotExisting($key)) {
241
+			$this->js_data[ $key ] = $value;
242
+		}
243
+	}
244
+
245
+
246
+	/**
247
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
248
+	 * elements in an array.
249
+	 *
250
+	 * When you use this method, the value you include will be merged with the array on $key.
251
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
252
+	 * object like this, eejs.data.test = [ my_data,
253
+	 * ]
254
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
255
+	 * this will throw an exception.
256
+	 *
257
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
258
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
259
+	 *
260
+	 * @param string       $key   Key to attach data to.
261
+	 * @param string|array $value Value being registered.
262
+	 * @throws InvalidArgumentException
263
+	 */
264
+	public function pushData(string $key, $value)
265
+	{
266
+		if (
267
+			isset($this->js_data[ $key ])
268
+			&& ! is_array($this->js_data[ $key ])
269
+		) {
270
+			if (! $this->debug()) {
271
+				return;
272
+			}
273
+			throw new InvalidArgumentException(
274
+				sprintf(
275
+					esc_html__(
276
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
277 277
                          push values to this data element when it is an array.',
278
-                        'event_espresso'
279
-                    ),
280
-                    $key,
281
-                    __METHOD__
282
-                )
283
-            );
284
-        }
285
-        if (! isset($this->js_data[ $key ])) {
286
-            $this->js_data[ $key ] = is_array($value) ? $value : [$value];
287
-        } else {
288
-            $this->js_data[ $key ] = array_merge($this->js_data[ $key ], (array) $value);
289
-        }
290
-    }
291
-
292
-
293
-    /**
294
-     * Used to set content used by javascript for a template.
295
-     * Note: Overrides of existing registered templates are not allowed.
296
-     *
297
-     * @param string $template_reference
298
-     * @param string $template_content
299
-     * @throws InvalidArgumentException
300
-     */
301
-    public function addTemplate(string $template_reference, string $template_content)
302
-    {
303
-        if (! isset($this->js_data['templates'])) {
304
-            $this->js_data['templates'] = [];
305
-        }
306
-        //no overrides allowed.
307
-        if (isset($this->js_data['templates'][ $template_reference ])) {
308
-            if (! $this->debug()) {
309
-                return;
310
-            }
311
-            throw new InvalidArgumentException(
312
-                sprintf(
313
-                    esc_html__(
314
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
315
-                        'event_espresso'
316
-                    ),
317
-                    $template_reference
318
-                )
319
-            );
320
-        }
321
-        $this->js_data['templates'][ $template_reference ] = $template_content;
322
-    }
323
-
324
-
325
-    /**
326
-     * Retrieve the template content already registered for the given reference.
327
-     *
328
-     * @param string $template_reference
329
-     * @return string
330
-     */
331
-    public function getTemplate(string $template_reference): string
332
-    {
333
-        return $this->js_data['templates'][ $template_reference ] ?? '';
334
-    }
335
-
336
-
337
-    /**
338
-     * Retrieve registered data.
339
-     *
340
-     * @param string $key Name of key to attach data to.
341
-     * @return mixed                If there is no for the given key, then false is returned.
342
-     */
343
-    public function getData(string $key)
344
-    {
345
-        return array_key_exists($key, $this->js_data) ? $this->js_data[ $key ] : null;
346
-    }
347
-
348
-
349
-    /**
350
-     * Verifies whether the given data exists already on the js_data array.
351
-     * Overriding data is not allowed.
352
-     *
353
-     * @param string $key Index for data.
354
-     * @return bool        If valid then return true.
355
-     * @throws InvalidArgumentException if data already exists.
356
-     */
357
-    protected function verifyDataNotExisting(string $key): bool
358
-    {
359
-        if (isset($this->js_data[ $key ])) {
360
-            if (! $this->debug()) {
361
-                return false;
362
-            }
363
-            if (is_array($this->js_data[ $key ])) {
364
-                throw new InvalidArgumentException(
365
-                    sprintf(
366
-                        esc_html__(
367
-                            'The value for %1$s already exists in the Registry::eejs object.
278
+						'event_espresso'
279
+					),
280
+					$key,
281
+					__METHOD__
282
+				)
283
+			);
284
+		}
285
+		if (! isset($this->js_data[ $key ])) {
286
+			$this->js_data[ $key ] = is_array($value) ? $value : [$value];
287
+		} else {
288
+			$this->js_data[ $key ] = array_merge($this->js_data[ $key ], (array) $value);
289
+		}
290
+	}
291
+
292
+
293
+	/**
294
+	 * Used to set content used by javascript for a template.
295
+	 * Note: Overrides of existing registered templates are not allowed.
296
+	 *
297
+	 * @param string $template_reference
298
+	 * @param string $template_content
299
+	 * @throws InvalidArgumentException
300
+	 */
301
+	public function addTemplate(string $template_reference, string $template_content)
302
+	{
303
+		if (! isset($this->js_data['templates'])) {
304
+			$this->js_data['templates'] = [];
305
+		}
306
+		//no overrides allowed.
307
+		if (isset($this->js_data['templates'][ $template_reference ])) {
308
+			if (! $this->debug()) {
309
+				return;
310
+			}
311
+			throw new InvalidArgumentException(
312
+				sprintf(
313
+					esc_html__(
314
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
315
+						'event_espresso'
316
+					),
317
+					$template_reference
318
+				)
319
+			);
320
+		}
321
+		$this->js_data['templates'][ $template_reference ] = $template_content;
322
+	}
323
+
324
+
325
+	/**
326
+	 * Retrieve the template content already registered for the given reference.
327
+	 *
328
+	 * @param string $template_reference
329
+	 * @return string
330
+	 */
331
+	public function getTemplate(string $template_reference): string
332
+	{
333
+		return $this->js_data['templates'][ $template_reference ] ?? '';
334
+	}
335
+
336
+
337
+	/**
338
+	 * Retrieve registered data.
339
+	 *
340
+	 * @param string $key Name of key to attach data to.
341
+	 * @return mixed                If there is no for the given key, then false is returned.
342
+	 */
343
+	public function getData(string $key)
344
+	{
345
+		return array_key_exists($key, $this->js_data) ? $this->js_data[ $key ] : null;
346
+	}
347
+
348
+
349
+	/**
350
+	 * Verifies whether the given data exists already on the js_data array.
351
+	 * Overriding data is not allowed.
352
+	 *
353
+	 * @param string $key Index for data.
354
+	 * @return bool        If valid then return true.
355
+	 * @throws InvalidArgumentException if data already exists.
356
+	 */
357
+	protected function verifyDataNotExisting(string $key): bool
358
+	{
359
+		if (isset($this->js_data[ $key ])) {
360
+			if (! $this->debug()) {
361
+				return false;
362
+			}
363
+			if (is_array($this->js_data[ $key ])) {
364
+				throw new InvalidArgumentException(
365
+					sprintf(
366
+						esc_html__(
367
+							'The value for %1$s already exists in the Registry::eejs object.
368 368
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
369 369
                             %2$s method to push your value to the array.',
370
-                            'event_espresso'
371
-                        ),
372
-                        $key,
373
-                        'pushData()'
374
-                    )
375
-                );
376
-            }
377
-            throw new InvalidArgumentException(
378
-                sprintf(
379
-                    esc_html__(
380
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
370
+							'event_espresso'
371
+						),
372
+						$key,
373
+						'pushData()'
374
+					)
375
+				);
376
+			}
377
+			throw new InvalidArgumentException(
378
+				sprintf(
379
+					esc_html__(
380
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
381 381
                         allowed.  Consider attaching your value to a different key',
382
-                        'event_espresso'
383
-                    ),
384
-                    $key
385
-                )
386
-            );
387
-        }
388
-        return true;
389
-    }
390
-
391
-
392
-    /**
393
-     * Get the actual asset path for asset manifests.
394
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
395
-     *
396
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
397
-     *                           asset file location.
398
-     * @param string $chunk_name
399
-     * @param string $asset_type
400
-     * @return string
401
-     * @since 4.9.59.p
402
-     */
403
-    public function getAssetUrl(string $namespace, string $chunk_name, string $asset_type): string
404
-    {
405
-        return apply_filters(
406
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
407
-            $this->asset_manifest->getAssetUrl($chunk_name, $asset_type),
408
-            $namespace,
409
-            $chunk_name,
410
-            $asset_type
411
-        );
412
-    }
413
-
414
-
415
-    /**
416
-     * Return the url to a js file for the given namespace and chunk name.
417
-     *
418
-     * @param string $namespace
419
-     * @param string $chunk_name
420
-     * @return string
421
-     */
422
-    public function getJsUrl(string $namespace, string $chunk_name): string
423
-    {
424
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
425
-    }
426
-
427
-
428
-    /**
429
-     * Return the url to a css file for the given namespace and chunk name.
430
-     *
431
-     * @param string $namespace
432
-     * @param string $chunk_name
433
-     * @return string
434
-     */
435
-    public function getCssUrl(string $namespace, string $chunk_name): string
436
-    {
437
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
438
-    }
439
-
440
-
441
-    /**
442
-     * This is used to set registered script handles that have data.
443
-     *
444
-     * @param string $script_handle
445
-     */
446
-    private function addRegisteredScriptHandlesWithData(string $script_handle)
447
-    {
448
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
449
-    }
450
-
451
-
452
-    /**i
382
+						'event_espresso'
383
+					),
384
+					$key
385
+				)
386
+			);
387
+		}
388
+		return true;
389
+	}
390
+
391
+
392
+	/**
393
+	 * Get the actual asset path for asset manifests.
394
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
395
+	 *
396
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
397
+	 *                           asset file location.
398
+	 * @param string $chunk_name
399
+	 * @param string $asset_type
400
+	 * @return string
401
+	 * @since 4.9.59.p
402
+	 */
403
+	public function getAssetUrl(string $namespace, string $chunk_name, string $asset_type): string
404
+	{
405
+		return apply_filters(
406
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
407
+			$this->asset_manifest->getAssetUrl($chunk_name, $asset_type),
408
+			$namespace,
409
+			$chunk_name,
410
+			$asset_type
411
+		);
412
+	}
413
+
414
+
415
+	/**
416
+	 * Return the url to a js file for the given namespace and chunk name.
417
+	 *
418
+	 * @param string $namespace
419
+	 * @param string $chunk_name
420
+	 * @return string
421
+	 */
422
+	public function getJsUrl(string $namespace, string $chunk_name): string
423
+	{
424
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Return the url to a css file for the given namespace and chunk name.
430
+	 *
431
+	 * @param string $namespace
432
+	 * @param string $chunk_name
433
+	 * @return string
434
+	 */
435
+	public function getCssUrl(string $namespace, string $chunk_name): string
436
+	{
437
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
438
+	}
439
+
440
+
441
+	/**
442
+	 * This is used to set registered script handles that have data.
443
+	 *
444
+	 * @param string $script_handle
445
+	 */
446
+	private function addRegisteredScriptHandlesWithData(string $script_handle)
447
+	{
448
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
449
+	}
450
+
451
+
452
+	/**i
453 453
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
454 454
      * Dependency stored in WP_Scripts if its set.
455 455
      */
456
-    private function removeAlreadyRegisteredDataForScriptHandles()
457
-    {
458
-        if (empty($this->script_handles_with_data)) {
459
-            return;
460
-        }
461
-        foreach ($this->script_handles_with_data as $script_handle) {
462
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
463
-        }
464
-    }
465
-
466
-
467
-    /**
468
-     * Removes any data dependency registered in WP_Scripts if its set.
469
-     *
470
-     * @param string $script_handle
471
-     */
472
-    private function removeAlreadyRegisteredDataForScriptHandle(string $script_handle)
473
-    {
474
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
475
-            global $wp_scripts;
476
-            $unset_handle = false;
477
-            if ($wp_scripts->get_data($script_handle, 'data')) {
478
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
479
-                $unset_handle = true;
480
-            }
481
-            //deal with inline_scripts
482
-            if ($wp_scripts->get_data($script_handle, 'before')) {
483
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
484
-                $unset_handle = true;
485
-            }
486
-            if ($wp_scripts->get_data($script_handle, 'after')) {
487
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
488
-            }
489
-            if ($unset_handle) {
490
-                unset($this->script_handles_with_data[ $script_handle ]);
491
-            }
492
-        }
493
-    }
494
-
495
-
496
-    /**
497
-     * @since 4.9.63.p
498
-     * @return bool
499
-     * @since 4.9.63.p
500
-     */
501
-    private function debug(): bool
502
-    {
503
-        return apply_filters(
504
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
505
-            defined('EE_DEBUG') && EE_DEBUG
506
-        );
507
-    }
508
-
509
-
510
-    /**************** deprecated ****************/
511
-
512
-
513
-
514
-    /**
515
-     * @return null
516
-     * @deprecated 5.0.0.p
517
-     */
518
-    public function getI18nRegistry()
519
-    {
520
-        return null;
521
-    }
522
-
523
-
524
-    /**
525
-     * @param string $handle
526
-     * @deprecated 5.0.0.p
527
-     */
528
-    public function registerTranslation($handle)
529
-    {
530
-    }
531
-
532
-
533
-    /**
534
-     * @param string $namespace
535
-     * @param string $chunk_name
536
-     * @return array
537
-     * @deprecated 5.0.0.p
538
-     */
539
-    public function getCssAssetDetails($namespace, $chunk_name)
540
-    {
541
-        return [
542
-            AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_CSS),
543
-            AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_CSS),
544
-        ];
545
-    }
546
-
547
-
548
-    /**
549
-     * @param string $namespace
550
-     * @param string $chunk_name
551
-     * @return array
552
-     * @deprecated 5.0.0.p
553
-     */
554
-    public function getCssDependencies($namespace, $chunk_name)
555
-    {
556
-        return $this->asset_manifest->getAssetDependencies($chunk_name, AssetManifest::ASSET_EXT_CSS);
557
-    }
558
-
559
-
560
-    /**
561
-     * @param string $namespace
562
-     * @param string $chunk_name
563
-     * @return array
564
-     * @deprecated 5.0.0.p
565
-     */
566
-    public function getJsAssetDetails($namespace, $chunk_name)
567
-    {
568
-        return [
569
-            AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_JS),
570
-            AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_JS),
571
-        ];
572
-    }
573
-
574
-
575
-    /**
576
-     * @param string $namespace
577
-     * @param string $chunk_name
578
-     * @return array
579
-     * @deprecated 5.0.0.p
580
-     */
581
-    public function getJsDependencies($namespace, $chunk_name)
582
-    {
583
-        return $this->asset_manifest->getAssetDependencies($chunk_name);
584
-    }
585
-
586
-
587
-    /**
588
-     * @deprecated 5.0.0.p
589
-     */
590
-    public function registerManifestFiles()
591
-    {
592
-    }
593
-
594
-
595
-    /**
596
-     * @param string $namespace
597
-     * @param string $url_base
598
-     * @param string $manifest_file
599
-     * @param string $manifest_file_path
600
-     * @deprecated 5.0.0.p
601
-     */
602
-    public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
603
-    {
604
-    }
456
+	private function removeAlreadyRegisteredDataForScriptHandles()
457
+	{
458
+		if (empty($this->script_handles_with_data)) {
459
+			return;
460
+		}
461
+		foreach ($this->script_handles_with_data as $script_handle) {
462
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
463
+		}
464
+	}
465
+
466
+
467
+	/**
468
+	 * Removes any data dependency registered in WP_Scripts if its set.
469
+	 *
470
+	 * @param string $script_handle
471
+	 */
472
+	private function removeAlreadyRegisteredDataForScriptHandle(string $script_handle)
473
+	{
474
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
475
+			global $wp_scripts;
476
+			$unset_handle = false;
477
+			if ($wp_scripts->get_data($script_handle, 'data')) {
478
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
479
+				$unset_handle = true;
480
+			}
481
+			//deal with inline_scripts
482
+			if ($wp_scripts->get_data($script_handle, 'before')) {
483
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
484
+				$unset_handle = true;
485
+			}
486
+			if ($wp_scripts->get_data($script_handle, 'after')) {
487
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
488
+			}
489
+			if ($unset_handle) {
490
+				unset($this->script_handles_with_data[ $script_handle ]);
491
+			}
492
+		}
493
+	}
494
+
495
+
496
+	/**
497
+	 * @since 4.9.63.p
498
+	 * @return bool
499
+	 * @since 4.9.63.p
500
+	 */
501
+	private function debug(): bool
502
+	{
503
+		return apply_filters(
504
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
505
+			defined('EE_DEBUG') && EE_DEBUG
506
+		);
507
+	}
508
+
509
+
510
+	/**************** deprecated ****************/
511
+
512
+
513
+
514
+	/**
515
+	 * @return null
516
+	 * @deprecated 5.0.0.p
517
+	 */
518
+	public function getI18nRegistry()
519
+	{
520
+		return null;
521
+	}
522
+
523
+
524
+	/**
525
+	 * @param string $handle
526
+	 * @deprecated 5.0.0.p
527
+	 */
528
+	public function registerTranslation($handle)
529
+	{
530
+	}
531
+
532
+
533
+	/**
534
+	 * @param string $namespace
535
+	 * @param string $chunk_name
536
+	 * @return array
537
+	 * @deprecated 5.0.0.p
538
+	 */
539
+	public function getCssAssetDetails($namespace, $chunk_name)
540
+	{
541
+		return [
542
+			AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_CSS),
543
+			AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_CSS),
544
+		];
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param string $namespace
550
+	 * @param string $chunk_name
551
+	 * @return array
552
+	 * @deprecated 5.0.0.p
553
+	 */
554
+	public function getCssDependencies($namespace, $chunk_name)
555
+	{
556
+		return $this->asset_manifest->getAssetDependencies($chunk_name, AssetManifest::ASSET_EXT_CSS);
557
+	}
558
+
559
+
560
+	/**
561
+	 * @param string $namespace
562
+	 * @param string $chunk_name
563
+	 * @return array
564
+	 * @deprecated 5.0.0.p
565
+	 */
566
+	public function getJsAssetDetails($namespace, $chunk_name)
567
+	{
568
+		return [
569
+			AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_JS),
570
+			AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_JS),
571
+		];
572
+	}
573
+
574
+
575
+	/**
576
+	 * @param string $namespace
577
+	 * @param string $chunk_name
578
+	 * @return array
579
+	 * @deprecated 5.0.0.p
580
+	 */
581
+	public function getJsDependencies($namespace, $chunk_name)
582
+	{
583
+		return $this->asset_manifest->getAssetDependencies($chunk_name);
584
+	}
585
+
586
+
587
+	/**
588
+	 * @deprecated 5.0.0.p
589
+	 */
590
+	public function registerManifestFiles()
591
+	{
592
+	}
593
+
594
+
595
+	/**
596
+	 * @param string $namespace
597
+	 * @param string $url_base
598
+	 * @param string $manifest_file
599
+	 * @param string $manifest_file_path
600
+	 * @deprecated 5.0.0.p
601
+	 */
602
+	public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
603
+	{
604
+	}
605 605
 }
Please login to merge, or discard this patch.