@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class EnumCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_enums'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_enums'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionLoader $loader |
|
27 | - */ |
|
28 | - protected $loader; |
|
25 | + /** |
|
26 | + * @var CollectionLoader $loader |
|
27 | + */ |
|
28 | + protected $loader; |
|
29 | 29 | |
30 | - /** |
|
31 | - * EnumCollection constructor |
|
32 | - * |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct( |
|
38 | - 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
39 | - EnumCollection::COLLECTION_NAME |
|
40 | - ); |
|
41 | - } |
|
30 | + /** |
|
31 | + * EnumCollection constructor |
|
32 | + * |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct( |
|
38 | + 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
39 | + EnumCollection::COLLECTION_NAME |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @throws CollectionDetailsException |
|
46 | - * @throws CollectionLoaderException |
|
47 | - * @since $VID:$ |
|
48 | - */ |
|
49 | - private function loadCollection() |
|
50 | - { |
|
51 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | - $this->loader = new CollectionLoader( |
|
53 | - new CollectionDetails( |
|
54 | - // collection name |
|
55 | - EnumCollection::COLLECTION_NAME, |
|
56 | - // collection interface |
|
57 | - 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
58 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | - apply_filters( |
|
60 | - 'FHEE__EventEspresso_core_services_graphql_EnumCollection__loadCollection__collection_FQCNs', |
|
61 | - ['EventEspresso\core\domain\services\graphql\enums'] |
|
62 | - ), |
|
63 | - // filepaths to classes to add |
|
64 | - array(), |
|
65 | - // file mask to use if parsing folder for files to add |
|
66 | - '', |
|
67 | - // what to use as identifier for collection entities |
|
68 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | - CollectionDetails::ID_CLASS_NAME |
|
70 | - ), |
|
71 | - $this |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @throws CollectionDetailsException |
|
46 | + * @throws CollectionLoaderException |
|
47 | + * @since $VID:$ |
|
48 | + */ |
|
49 | + private function loadCollection() |
|
50 | + { |
|
51 | + if (! $this->loader instanceof CollectionLoader) { |
|
52 | + $this->loader = new CollectionLoader( |
|
53 | + new CollectionDetails( |
|
54 | + // collection name |
|
55 | + EnumCollection::COLLECTION_NAME, |
|
56 | + // collection interface |
|
57 | + 'EventEspresso\core\services\graphql\enums\EnumInterface', |
|
58 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | + apply_filters( |
|
60 | + 'FHEE__EventEspresso_core_services_graphql_EnumCollection__loadCollection__collection_FQCNs', |
|
61 | + ['EventEspresso\core\domain\services\graphql\enums'] |
|
62 | + ), |
|
63 | + // filepaths to classes to add |
|
64 | + array(), |
|
65 | + // file mask to use if parsing folder for files to add |
|
66 | + '', |
|
67 | + // what to use as identifier for collection entities |
|
68 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | + CollectionDetails::ID_CLASS_NAME |
|
70 | + ), |
|
71 | + $this |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return CollectionInterface |
|
79 | - * @throws CollectionDetailsException |
|
80 | - * @throws CollectionLoaderException |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function loadEnums() |
|
84 | - { |
|
85 | - $this->loadCollection(); |
|
86 | - return $this->loader->getCollection(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return CollectionInterface |
|
79 | + * @throws CollectionDetailsException |
|
80 | + * @throws CollectionLoaderException |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function loadEnums() |
|
84 | + { |
|
85 | + $this->loadCollection(); |
|
86 | + return $this->loader->getCollection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * getIdentifier |
|
92 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | - * |
|
95 | - * @param $object |
|
96 | - * @param mixed $identifier |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function getIdentifier($object, $identifier = null) |
|
100 | - { |
|
101 | - return ! empty($identifier) |
|
102 | - ? $identifier |
|
103 | - : get_class($object); |
|
104 | - } |
|
90 | + /** |
|
91 | + * getIdentifier |
|
92 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | + * |
|
95 | + * @param $object |
|
96 | + * @param mixed $identifier |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function getIdentifier($object, $identifier = null) |
|
100 | + { |
|
101 | + return ! empty($identifier) |
|
102 | + ? $identifier |
|
103 | + : get_class($object); |
|
104 | + } |
|
105 | 105 | } |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | class InputCollection extends Collection |
22 | 22 | { |
23 | - const COLLECTION_NAME = 'espresso_graphql_inputs'; |
|
23 | + const COLLECTION_NAME = 'espresso_graphql_inputs'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionLoader $loader |
|
27 | - */ |
|
28 | - protected $loader; |
|
25 | + /** |
|
26 | + * @var CollectionLoader $loader |
|
27 | + */ |
|
28 | + protected $loader; |
|
29 | 29 | |
30 | - /** |
|
31 | - * InputCollection constructor |
|
32 | - * |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - parent::__construct( |
|
38 | - 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
39 | - InputCollection::COLLECTION_NAME |
|
40 | - ); |
|
41 | - } |
|
30 | + /** |
|
31 | + * InputCollection constructor |
|
32 | + * |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + parent::__construct( |
|
38 | + 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
39 | + InputCollection::COLLECTION_NAME |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @throws CollectionDetailsException |
|
46 | - * @throws CollectionLoaderException |
|
47 | - * @since $VID:$ |
|
48 | - */ |
|
49 | - private function loadCollection() |
|
50 | - { |
|
51 | - if (! $this->loader instanceof CollectionLoader) { |
|
52 | - $this->loader = new CollectionLoader( |
|
53 | - new CollectionDetails( |
|
54 | - // collection name |
|
55 | - InputCollection::COLLECTION_NAME, |
|
56 | - // collection interface |
|
57 | - 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
58 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | - apply_filters( |
|
60 | - 'FHEE__EventEspresso_core_services_graphql_InputCollection__loadCollection__collection_FQCNs', |
|
61 | - ['EventEspresso\core\domain\services\graphql\inputs'] |
|
62 | - ), |
|
63 | - // filepaths to classes to add |
|
64 | - array(), |
|
65 | - // file mask to use if parsing folder for files to add |
|
66 | - '', |
|
67 | - // what to use as identifier for collection entities |
|
68 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | - CollectionDetails::ID_CLASS_NAME |
|
70 | - ), |
|
71 | - $this |
|
72 | - ); |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @throws CollectionDetailsException |
|
46 | + * @throws CollectionLoaderException |
|
47 | + * @since $VID:$ |
|
48 | + */ |
|
49 | + private function loadCollection() |
|
50 | + { |
|
51 | + if (! $this->loader instanceof CollectionLoader) { |
|
52 | + $this->loader = new CollectionLoader( |
|
53 | + new CollectionDetails( |
|
54 | + // collection name |
|
55 | + InputCollection::COLLECTION_NAME, |
|
56 | + // collection interface |
|
57 | + 'EventEspresso\core\services\graphql\inputs\InputInterface', |
|
58 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
59 | + apply_filters( |
|
60 | + 'FHEE__EventEspresso_core_services_graphql_InputCollection__loadCollection__collection_FQCNs', |
|
61 | + ['EventEspresso\core\domain\services\graphql\inputs'] |
|
62 | + ), |
|
63 | + // filepaths to classes to add |
|
64 | + array(), |
|
65 | + // file mask to use if parsing folder for files to add |
|
66 | + '', |
|
67 | + // what to use as identifier for collection entities |
|
68 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
69 | + CollectionDetails::ID_CLASS_NAME |
|
70 | + ), |
|
71 | + $this |
|
72 | + ); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return CollectionInterface |
|
79 | - * @throws CollectionDetailsException |
|
80 | - * @throws CollectionLoaderException |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function loadInputs() |
|
84 | - { |
|
85 | - $this->loadCollection(); |
|
86 | - return $this->loader->getCollection(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return CollectionInterface |
|
79 | + * @throws CollectionDetailsException |
|
80 | + * @throws CollectionLoaderException |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function loadInputs() |
|
84 | + { |
|
85 | + $this->loadCollection(); |
|
86 | + return $this->loader->getCollection(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * getIdentifier |
|
92 | - * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | - * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | - * |
|
95 | - * @param $object |
|
96 | - * @param mixed $identifier |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function getIdentifier($object, $identifier = null) |
|
100 | - { |
|
101 | - return ! empty($identifier) |
|
102 | - ? $identifier |
|
103 | - : get_class($object); |
|
104 | - } |
|
90 | + /** |
|
91 | + * getIdentifier |
|
92 | + * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
|
93 | + * If no $identifier is supplied, then the fully qualified class name is used |
|
94 | + * |
|
95 | + * @param $object |
|
96 | + * @param mixed $identifier |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function getIdentifier($object, $identifier = null) |
|
100 | + { |
|
101 | + return ! empty($identifier) |
|
102 | + ? $identifier |
|
103 | + : get_class($object); |
|
104 | + } |
|
105 | 105 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | */ |
13 | 13 | interface GraphQLDataInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since $VID:$ |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []); |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since $VID:$ |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []); |
|
21 | 21 | } |
@@ -17,234 +17,234 @@ |
||
17 | 17 | abstract class BrowserAsset extends Asset |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var array $attributes |
|
22 | - */ |
|
23 | - private $attributes = []; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array $allowed_attributes |
|
27 | - */ |
|
28 | - private static $allowed_attributes = [ |
|
29 | - Asset::TYPE_CSS => [ |
|
30 | - 'crossorigin', |
|
31 | - 'media', |
|
32 | - 'referrerpolicy', |
|
33 | - 'sizes', |
|
34 | - 'type', |
|
35 | - ], |
|
36 | - Asset::TYPE_JS => [ |
|
37 | - 'async', |
|
38 | - 'charset', |
|
39 | - 'crossorigin', |
|
40 | - 'defer', |
|
41 | - 'type', |
|
42 | - ] |
|
43 | - ]; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array $dependencies |
|
47 | - */ |
|
48 | - private $dependencies; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string $source |
|
52 | - */ |
|
53 | - private $source; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var string $version |
|
57 | - */ |
|
58 | - private $version; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * Asset constructor. |
|
63 | - * |
|
64 | - * @param string $type |
|
65 | - * @param string $handle |
|
66 | - * @param string $source |
|
67 | - * @param array $dependencies |
|
68 | - * @param DomainInterface $domain |
|
69 | - * @param string $version |
|
70 | - * @throws DomainException |
|
71 | - * @throws InvalidDataTypeException |
|
72 | - */ |
|
73 | - public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '') |
|
74 | - { |
|
75 | - parent::__construct($type, $handle, $domain); |
|
76 | - $this->setSource($source); |
|
77 | - $this->setDependencies($dependencies); |
|
78 | - $this->setVersion($version, false); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @since 4.9.62.p |
|
84 | - */ |
|
85 | - abstract public function enqueueAsset(); |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function getAttributes() |
|
92 | - { |
|
93 | - return $this->attributes; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param array $attributes |
|
99 | - * @throws DomainException |
|
100 | - * @since $VID:$ |
|
101 | - */ |
|
102 | - public function addAttributes(array $attributes) |
|
103 | - { |
|
104 | - if (empty($attributes)) { |
|
105 | - throw new DomainException( |
|
106 | - esc_html__('The attributes array needs at least one value.', 'event_espresso') |
|
107 | - ); |
|
108 | - } |
|
109 | - foreach ($attributes as $key => $value) { |
|
110 | - if (is_int($key) && $this->validateAttribute($value)) { |
|
111 | - $this->attributes[] = $value; |
|
112 | - } else if ($this->validateAttribute($key)) { |
|
113 | - $this->attributes[ $key ] = $value; |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $attribute |
|
121 | - * @return bool |
|
122 | - * @throws DomainException |
|
123 | - * @since $VID:$ |
|
124 | - */ |
|
125 | - private function validateAttribute($attribute) |
|
126 | - { |
|
127 | - $allowed = BrowserAsset::$allowed_attributes[ $this->type() ]; |
|
128 | - if (! in_array($attribute, $allowed, true)) { |
|
129 | - throw new DomainException( |
|
130 | - sprintf( |
|
131 | - esc_html__('Invalid attribute! The only allowed attributes are: "%1$s"', 'event_espresso'), |
|
132 | - implode('", "', $allowed) |
|
133 | - ) |
|
134 | - ); |
|
135 | - } |
|
136 | - return true; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public function dependencies() |
|
144 | - { |
|
145 | - return $this->dependencies; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @param array $dependencies |
|
151 | - */ |
|
152 | - public function addDependencies(array $dependencies) |
|
153 | - { |
|
154 | - $this->dependencies = array_merge($this->dependencies, $dependencies); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @param array $dependencies |
|
160 | - */ |
|
161 | - protected function setDependencies(array $dependencies) |
|
162 | - { |
|
163 | - $this->dependencies = $dependencies; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @since 4.9.62.p |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - public function hasDependencies() |
|
172 | - { |
|
173 | - return count($this->dependencies) > 0; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function source() |
|
181 | - { |
|
182 | - return $this->source; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param string $source |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - */ |
|
190 | - private function setSource($source) |
|
191 | - { |
|
192 | - if (! is_string($source)) { |
|
193 | - throw new InvalidDataTypeException( |
|
194 | - '$source', |
|
195 | - $source, |
|
196 | - 'string' |
|
197 | - ); |
|
198 | - } |
|
199 | - $this->source = $source; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return string |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws DomainException |
|
207 | - */ |
|
208 | - public function version() |
|
209 | - { |
|
210 | - return $this->version; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @param string $version |
|
216 | - * @param bool $fluent |
|
217 | - * @return BrowserAsset|null |
|
218 | - * @throws DomainException |
|
219 | - * @throws InvalidDataTypeException |
|
220 | - */ |
|
221 | - public function setVersion($version, $fluent = true) |
|
222 | - { |
|
223 | - // if version is NOT set and this asset was NOT built for distribution, |
|
224 | - // then set the version equal to the EE core plugin version |
|
225 | - if (empty($version) && ! $this->isBuiltDistributionSource()) { |
|
226 | - $version = $this->domain->version(); |
|
227 | - } |
|
228 | - if (! is_string($version)) { |
|
229 | - throw new InvalidDataTypeException( |
|
230 | - '$version', |
|
231 | - $version, |
|
232 | - 'string' |
|
233 | - ); |
|
234 | - } |
|
235 | - $this->version = $version; |
|
236 | - if ($fluent) { |
|
237 | - return $this; |
|
238 | - } |
|
239 | - return null; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @return bool |
|
245 | - */ |
|
246 | - public function isBuiltDistributionSource() { |
|
247 | - return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
248 | - || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS; |
|
249 | - } |
|
20 | + /** |
|
21 | + * @var array $attributes |
|
22 | + */ |
|
23 | + private $attributes = []; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array $allowed_attributes |
|
27 | + */ |
|
28 | + private static $allowed_attributes = [ |
|
29 | + Asset::TYPE_CSS => [ |
|
30 | + 'crossorigin', |
|
31 | + 'media', |
|
32 | + 'referrerpolicy', |
|
33 | + 'sizes', |
|
34 | + 'type', |
|
35 | + ], |
|
36 | + Asset::TYPE_JS => [ |
|
37 | + 'async', |
|
38 | + 'charset', |
|
39 | + 'crossorigin', |
|
40 | + 'defer', |
|
41 | + 'type', |
|
42 | + ] |
|
43 | + ]; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array $dependencies |
|
47 | + */ |
|
48 | + private $dependencies; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string $source |
|
52 | + */ |
|
53 | + private $source; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var string $version |
|
57 | + */ |
|
58 | + private $version; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * Asset constructor. |
|
63 | + * |
|
64 | + * @param string $type |
|
65 | + * @param string $handle |
|
66 | + * @param string $source |
|
67 | + * @param array $dependencies |
|
68 | + * @param DomainInterface $domain |
|
69 | + * @param string $version |
|
70 | + * @throws DomainException |
|
71 | + * @throws InvalidDataTypeException |
|
72 | + */ |
|
73 | + public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '') |
|
74 | + { |
|
75 | + parent::__construct($type, $handle, $domain); |
|
76 | + $this->setSource($source); |
|
77 | + $this->setDependencies($dependencies); |
|
78 | + $this->setVersion($version, false); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @since 4.9.62.p |
|
84 | + */ |
|
85 | + abstract public function enqueueAsset(); |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function getAttributes() |
|
92 | + { |
|
93 | + return $this->attributes; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param array $attributes |
|
99 | + * @throws DomainException |
|
100 | + * @since $VID:$ |
|
101 | + */ |
|
102 | + public function addAttributes(array $attributes) |
|
103 | + { |
|
104 | + if (empty($attributes)) { |
|
105 | + throw new DomainException( |
|
106 | + esc_html__('The attributes array needs at least one value.', 'event_espresso') |
|
107 | + ); |
|
108 | + } |
|
109 | + foreach ($attributes as $key => $value) { |
|
110 | + if (is_int($key) && $this->validateAttribute($value)) { |
|
111 | + $this->attributes[] = $value; |
|
112 | + } else if ($this->validateAttribute($key)) { |
|
113 | + $this->attributes[ $key ] = $value; |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $attribute |
|
121 | + * @return bool |
|
122 | + * @throws DomainException |
|
123 | + * @since $VID:$ |
|
124 | + */ |
|
125 | + private function validateAttribute($attribute) |
|
126 | + { |
|
127 | + $allowed = BrowserAsset::$allowed_attributes[ $this->type() ]; |
|
128 | + if (! in_array($attribute, $allowed, true)) { |
|
129 | + throw new DomainException( |
|
130 | + sprintf( |
|
131 | + esc_html__('Invalid attribute! The only allowed attributes are: "%1$s"', 'event_espresso'), |
|
132 | + implode('", "', $allowed) |
|
133 | + ) |
|
134 | + ); |
|
135 | + } |
|
136 | + return true; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public function dependencies() |
|
144 | + { |
|
145 | + return $this->dependencies; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @param array $dependencies |
|
151 | + */ |
|
152 | + public function addDependencies(array $dependencies) |
|
153 | + { |
|
154 | + $this->dependencies = array_merge($this->dependencies, $dependencies); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @param array $dependencies |
|
160 | + */ |
|
161 | + protected function setDependencies(array $dependencies) |
|
162 | + { |
|
163 | + $this->dependencies = $dependencies; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @since 4.9.62.p |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + public function hasDependencies() |
|
172 | + { |
|
173 | + return count($this->dependencies) > 0; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function source() |
|
181 | + { |
|
182 | + return $this->source; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param string $source |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + */ |
|
190 | + private function setSource($source) |
|
191 | + { |
|
192 | + if (! is_string($source)) { |
|
193 | + throw new InvalidDataTypeException( |
|
194 | + '$source', |
|
195 | + $source, |
|
196 | + 'string' |
|
197 | + ); |
|
198 | + } |
|
199 | + $this->source = $source; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return string |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws DomainException |
|
207 | + */ |
|
208 | + public function version() |
|
209 | + { |
|
210 | + return $this->version; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @param string $version |
|
216 | + * @param bool $fluent |
|
217 | + * @return BrowserAsset|null |
|
218 | + * @throws DomainException |
|
219 | + * @throws InvalidDataTypeException |
|
220 | + */ |
|
221 | + public function setVersion($version, $fluent = true) |
|
222 | + { |
|
223 | + // if version is NOT set and this asset was NOT built for distribution, |
|
224 | + // then set the version equal to the EE core plugin version |
|
225 | + if (empty($version) && ! $this->isBuiltDistributionSource()) { |
|
226 | + $version = $this->domain->version(); |
|
227 | + } |
|
228 | + if (! is_string($version)) { |
|
229 | + throw new InvalidDataTypeException( |
|
230 | + '$version', |
|
231 | + $version, |
|
232 | + 'string' |
|
233 | + ); |
|
234 | + } |
|
235 | + $this->version = $version; |
|
236 | + if ($fluent) { |
|
237 | + return $this; |
|
238 | + } |
|
239 | + return null; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @return bool |
|
245 | + */ |
|
246 | + public function isBuiltDistributionSource() { |
|
247 | + return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
248 | + || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS; |
|
249 | + } |
|
250 | 250 | } |
@@ -24,125 +24,125 @@ |
||
24 | 24 | class LegacyAccountingAssetManager extends AssetManager |
25 | 25 | { |
26 | 26 | |
27 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
28 | - |
|
29 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
30 | - |
|
31 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @var EE_Currency_Config $currency_config |
|
36 | - */ |
|
37 | - protected $currency_config; |
|
38 | - |
|
39 | - /** |
|
40 | - * CoreAssetRegister constructor. |
|
41 | - * |
|
42 | - * @param AssetCollection $assets |
|
43 | - * @param DomainInterface $domain |
|
44 | - * @param Registry $registry |
|
45 | - * @param EE_Currency_Config $currency_config |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - AssetCollection $assets, |
|
49 | - DomainInterface $domain, |
|
50 | - Registry $registry, |
|
51 | - EE_Currency_Config $currency_config |
|
52 | - ) { |
|
53 | - $this->currency_config = $currency_config; |
|
54 | - parent::__construct($domain, $assets, $registry); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - * @throws InvalidEntityException |
|
62 | - * @throws DuplicateCollectionIdentifierException |
|
63 | - * @throws DomainException |
|
64 | - */ |
|
65 | - public function addAssets() |
|
66 | - { |
|
67 | - $this->loadAccountingJs(); |
|
68 | - add_action('admin_enqueue_scripts', [$this, 'enqueueLegacyAccountingAssets'], 100); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * accounting.js for performing client-side calculations |
|
74 | - * |
|
75 | - * @throws DomainException |
|
76 | - * @throws DuplicateCollectionIdentifierException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidEntityException |
|
79 | - * @since $VID:$ |
|
80 | - */ |
|
81 | - private function loadAccountingJs() |
|
82 | - { |
|
83 | - //accounting.js library |
|
84 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
85 | - $this->addJavascript( |
|
86 | - LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
87 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
88 | - [LegacyAccountingAssetManager::JS_HANDLE_UNDERSCORE], |
|
89 | - true, |
|
90 | - '0.3.2' |
|
91 | - ); |
|
92 | - |
|
93 | - $this->addJavascript( |
|
94 | - LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
95 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
96 | - [LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
|
97 | - ) |
|
98 | - ->setInlineDataCallback( |
|
99 | - function () { |
|
100 | - wp_localize_script( |
|
101 | - LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
102 | - 'EE_ACCOUNTING_CFG', |
|
103 | - $this->getAccountingSettings() |
|
104 | - ); |
|
105 | - } |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Returns configuration data for the accounting-js library. |
|
112 | - * |
|
113 | - * @return array |
|
114 | - * @since $VID:$ |
|
115 | - */ |
|
116 | - private function getAccountingSettings() |
|
117 | - { |
|
118 | - return [ |
|
119 | - 'currency' => [ |
|
120 | - 'symbol' => $this->currency_config->sign, |
|
121 | - 'format' => [ |
|
122 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
123 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
124 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
125 | - ], |
|
126 | - 'decimal' => $this->currency_config->dec_mrk, |
|
127 | - 'thousand' => $this->currency_config->thsnds, |
|
128 | - 'precision' => $this->currency_config->dec_plc, |
|
129 | - ], |
|
130 | - 'number' => [ |
|
131 | - 'precision' => $this->currency_config->dec_plc, |
|
132 | - 'thousand' => $this->currency_config->thsnds, |
|
133 | - 'decimal' => $this->currency_config->dec_mrk, |
|
134 | - ], |
|
135 | - ]; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * enqueue_scripts - Load the scripts and css |
|
141 | - * |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - public function enqueueLegacyAccountingAssets() |
|
145 | - { |
|
146 | - $this->enqueueAsset(LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING); |
|
147 | - } |
|
27 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
28 | + |
|
29 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
30 | + |
|
31 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @var EE_Currency_Config $currency_config |
|
36 | + */ |
|
37 | + protected $currency_config; |
|
38 | + |
|
39 | + /** |
|
40 | + * CoreAssetRegister constructor. |
|
41 | + * |
|
42 | + * @param AssetCollection $assets |
|
43 | + * @param DomainInterface $domain |
|
44 | + * @param Registry $registry |
|
45 | + * @param EE_Currency_Config $currency_config |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + AssetCollection $assets, |
|
49 | + DomainInterface $domain, |
|
50 | + Registry $registry, |
|
51 | + EE_Currency_Config $currency_config |
|
52 | + ) { |
|
53 | + $this->currency_config = $currency_config; |
|
54 | + parent::__construct($domain, $assets, $registry); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + * @throws InvalidEntityException |
|
62 | + * @throws DuplicateCollectionIdentifierException |
|
63 | + * @throws DomainException |
|
64 | + */ |
|
65 | + public function addAssets() |
|
66 | + { |
|
67 | + $this->loadAccountingJs(); |
|
68 | + add_action('admin_enqueue_scripts', [$this, 'enqueueLegacyAccountingAssets'], 100); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * accounting.js for performing client-side calculations |
|
74 | + * |
|
75 | + * @throws DomainException |
|
76 | + * @throws DuplicateCollectionIdentifierException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidEntityException |
|
79 | + * @since $VID:$ |
|
80 | + */ |
|
81 | + private function loadAccountingJs() |
|
82 | + { |
|
83 | + //accounting.js library |
|
84 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
85 | + $this->addJavascript( |
|
86 | + LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
87 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
88 | + [LegacyAccountingAssetManager::JS_HANDLE_UNDERSCORE], |
|
89 | + true, |
|
90 | + '0.3.2' |
|
91 | + ); |
|
92 | + |
|
93 | + $this->addJavascript( |
|
94 | + LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
95 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
96 | + [LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
|
97 | + ) |
|
98 | + ->setInlineDataCallback( |
|
99 | + function () { |
|
100 | + wp_localize_script( |
|
101 | + LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
102 | + 'EE_ACCOUNTING_CFG', |
|
103 | + $this->getAccountingSettings() |
|
104 | + ); |
|
105 | + } |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Returns configuration data for the accounting-js library. |
|
112 | + * |
|
113 | + * @return array |
|
114 | + * @since $VID:$ |
|
115 | + */ |
|
116 | + private function getAccountingSettings() |
|
117 | + { |
|
118 | + return [ |
|
119 | + 'currency' => [ |
|
120 | + 'symbol' => $this->currency_config->sign, |
|
121 | + 'format' => [ |
|
122 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
123 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
124 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
125 | + ], |
|
126 | + 'decimal' => $this->currency_config->dec_mrk, |
|
127 | + 'thousand' => $this->currency_config->thsnds, |
|
128 | + 'precision' => $this->currency_config->dec_plc, |
|
129 | + ], |
|
130 | + 'number' => [ |
|
131 | + 'precision' => $this->currency_config->dec_plc, |
|
132 | + 'thousand' => $this->currency_config->thsnds, |
|
133 | + 'decimal' => $this->currency_config->dec_mrk, |
|
134 | + ], |
|
135 | + ]; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * enqueue_scripts - Load the scripts and css |
|
141 | + * |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + public function enqueueLegacyAccountingAssets() |
|
145 | + { |
|
146 | + $this->enqueueAsset(LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING); |
|
147 | + } |
|
148 | 148 | } |
@@ -18,172 +18,172 @@ |
||
18 | 18 | class JavascriptAsset extends BrowserAsset |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var boolean $load_in_footer |
|
23 | - */ |
|
24 | - private $load_in_footer = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var boolean $requires_translation |
|
28 | - */ |
|
29 | - private $requires_translation = false; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var boolean $has_inline_data |
|
33 | - */ |
|
34 | - private $has_inline_data = false; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Closure $inline_data_callback |
|
38 | - */ |
|
39 | - private $inline_data_callback; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Asset constructor. |
|
44 | - * |
|
45 | - * @param string $handle |
|
46 | - * @param string $source |
|
47 | - * @param array $dependencies |
|
48 | - * @param bool $load_in_footer |
|
49 | - * @param DomainInterface $domain |
|
50 | - * @param string $version |
|
51 | - * @throws InvalidDataTypeException |
|
52 | - * @throws DomainException |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - $handle, |
|
56 | - $source, |
|
57 | - array $dependencies, |
|
58 | - $load_in_footer, |
|
59 | - DomainInterface $domain, |
|
60 | - $version = '' |
|
61 | - ) { |
|
62 | - parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version); |
|
63 | - $this->setLoadInFooter($load_in_footer); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function loadInFooter() |
|
71 | - { |
|
72 | - return $this->load_in_footer; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param bool $load_in_footer |
|
78 | - */ |
|
79 | - private function setLoadInFooter($load_in_footer = true) |
|
80 | - { |
|
81 | - $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function requiresTranslation() |
|
89 | - { |
|
90 | - return $this->requires_translation; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasInlineData() |
|
98 | - { |
|
99 | - return $this->has_inline_data; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param bool $has_inline_data |
|
105 | - * @return JavascriptAsset |
|
106 | - */ |
|
107 | - public function setHasInlineData($has_inline_data = true) |
|
108 | - { |
|
109 | - $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return Closure |
|
116 | - */ |
|
117 | - public function inlineDataCallback() |
|
118 | - { |
|
119 | - return $this->inline_data_callback; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function hasInlineDataCallback() |
|
127 | - { |
|
128 | - return $this->inline_data_callback instanceof Closure; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param Closure $inline_data_callback |
|
134 | - * @return JavascriptAsset |
|
135 | - */ |
|
136 | - public function setInlineDataCallback(Closure $inline_data_callback) |
|
137 | - { |
|
138 | - $this->inline_data_callback = $inline_data_callback; |
|
139 | - $this->setHasInlineData(); |
|
140 | - return $this; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @since 4.9.62.p |
|
146 | - */ |
|
147 | - public function enqueueAsset() |
|
148 | - { |
|
149 | - if ($this->source() === '') { |
|
150 | - return; |
|
151 | - } |
|
152 | - $attributes = $this->getAttributes(); |
|
153 | - if (!empty($attributes)) { |
|
154 | - add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
|
155 | - } |
|
156 | - wp_enqueue_script($this->handle()); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - public function addAttributeTagsToScript($tag, $handle) |
|
161 | - { |
|
162 | - if ($handle === $this->handle()) { |
|
163 | - $attributes = $this->getAttributes(); |
|
164 | - $attributes_string = ''; |
|
165 | - foreach ($attributes as $key => $value) { |
|
166 | - if (is_int($key)) { |
|
167 | - $attributes_string .= " {$value}"; |
|
168 | - } else { |
|
169 | - $attributes_string .= " {$key}='{$value}'"; |
|
170 | - } |
|
171 | - } |
|
172 | - $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
173 | - } |
|
174 | - |
|
175 | - return $tag; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @deprecated $VID:$ |
|
181 | - * @param bool $requires_translation |
|
182 | - * @return JavascriptAsset |
|
183 | - */ |
|
184 | - public function setRequiresTranslation($requires_translation = true) |
|
185 | - { |
|
186 | - $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
187 | - return $this; |
|
188 | - } |
|
21 | + /** |
|
22 | + * @var boolean $load_in_footer |
|
23 | + */ |
|
24 | + private $load_in_footer = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var boolean $requires_translation |
|
28 | + */ |
|
29 | + private $requires_translation = false; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var boolean $has_inline_data |
|
33 | + */ |
|
34 | + private $has_inline_data = false; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Closure $inline_data_callback |
|
38 | + */ |
|
39 | + private $inline_data_callback; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Asset constructor. |
|
44 | + * |
|
45 | + * @param string $handle |
|
46 | + * @param string $source |
|
47 | + * @param array $dependencies |
|
48 | + * @param bool $load_in_footer |
|
49 | + * @param DomainInterface $domain |
|
50 | + * @param string $version |
|
51 | + * @throws InvalidDataTypeException |
|
52 | + * @throws DomainException |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + $handle, |
|
56 | + $source, |
|
57 | + array $dependencies, |
|
58 | + $load_in_footer, |
|
59 | + DomainInterface $domain, |
|
60 | + $version = '' |
|
61 | + ) { |
|
62 | + parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version); |
|
63 | + $this->setLoadInFooter($load_in_footer); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function loadInFooter() |
|
71 | + { |
|
72 | + return $this->load_in_footer; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param bool $load_in_footer |
|
78 | + */ |
|
79 | + private function setLoadInFooter($load_in_footer = true) |
|
80 | + { |
|
81 | + $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function requiresTranslation() |
|
89 | + { |
|
90 | + return $this->requires_translation; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasInlineData() |
|
98 | + { |
|
99 | + return $this->has_inline_data; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param bool $has_inline_data |
|
105 | + * @return JavascriptAsset |
|
106 | + */ |
|
107 | + public function setHasInlineData($has_inline_data = true) |
|
108 | + { |
|
109 | + $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return Closure |
|
116 | + */ |
|
117 | + public function inlineDataCallback() |
|
118 | + { |
|
119 | + return $this->inline_data_callback; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function hasInlineDataCallback() |
|
127 | + { |
|
128 | + return $this->inline_data_callback instanceof Closure; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param Closure $inline_data_callback |
|
134 | + * @return JavascriptAsset |
|
135 | + */ |
|
136 | + public function setInlineDataCallback(Closure $inline_data_callback) |
|
137 | + { |
|
138 | + $this->inline_data_callback = $inline_data_callback; |
|
139 | + $this->setHasInlineData(); |
|
140 | + return $this; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @since 4.9.62.p |
|
146 | + */ |
|
147 | + public function enqueueAsset() |
|
148 | + { |
|
149 | + if ($this->source() === '') { |
|
150 | + return; |
|
151 | + } |
|
152 | + $attributes = $this->getAttributes(); |
|
153 | + if (!empty($attributes)) { |
|
154 | + add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
|
155 | + } |
|
156 | + wp_enqueue_script($this->handle()); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + public function addAttributeTagsToScript($tag, $handle) |
|
161 | + { |
|
162 | + if ($handle === $this->handle()) { |
|
163 | + $attributes = $this->getAttributes(); |
|
164 | + $attributes_string = ''; |
|
165 | + foreach ($attributes as $key => $value) { |
|
166 | + if (is_int($key)) { |
|
167 | + $attributes_string .= " {$value}"; |
|
168 | + } else { |
|
169 | + $attributes_string .= " {$key}='{$value}'"; |
|
170 | + } |
|
171 | + } |
|
172 | + $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
173 | + } |
|
174 | + |
|
175 | + return $tag; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @deprecated $VID:$ |
|
181 | + * @param bool $requires_translation |
|
182 | + * @return JavascriptAsset |
|
183 | + */ |
|
184 | + public function setRequiresTranslation($requires_translation = true) |
|
185 | + { |
|
186 | + $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
187 | + return $this; |
|
188 | + } |
|
189 | 189 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface DependencyHandlerInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * @since $VID:$ |
|
9 | - */ |
|
10 | - public function registerDependencies(); |
|
7 | + /** |
|
8 | + * @since $VID:$ |
|
9 | + */ |
|
10 | + public function registerDependencies(); |
|
11 | 11 | } |
@@ -18,38 +18,38 @@ |
||
18 | 18 | */ |
19 | 19 | class Api extends JsonDataNode |
20 | 20 | { |
21 | - const NODE_NAME = 'api'; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param JsonDataNodeValidator $validator |
|
26 | - */ |
|
27 | - public function __construct(JsonDataNodeValidator $validator) |
|
28 | - { |
|
29 | - parent::__construct($validator); |
|
30 | - $this->setNodeName(Api::NODE_NAME); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @throws DomainException |
|
36 | - * @since $VID:$ |
|
37 | - */ |
|
38 | - public function initialize() |
|
39 | - { |
|
40 | - $this->addData('restApiNonce', wp_create_nonce('wp_rest')); |
|
41 | - $this->addData('restApiBaseUrl', rest_url()); |
|
42 | - $this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/')); |
|
43 | - $this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()); |
|
44 | - $this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName()); |
|
45 | - |
|
46 | - // route can be something like 'graphql' |
|
47 | - $route = trim(Router::$route, '/'); |
|
48 | - // make sure we are dealing with sane folks |
|
49 | - $has_pretty_permalinks = (bool) get_option('permalink_structure'); |
|
50 | - // if pretty permalinks, use '/graphql' otherwise '?graphql=1' |
|
51 | - $graphqlEndpoint = $has_pretty_permalinks ? site_url($route) : add_query_arg($route, 1, site_url()); |
|
52 | - $this->addData('graphqlEndpoint', esc_url($graphqlEndpoint)); |
|
53 | - $this->setInitialized(true); |
|
54 | - } |
|
21 | + const NODE_NAME = 'api'; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param JsonDataNodeValidator $validator |
|
26 | + */ |
|
27 | + public function __construct(JsonDataNodeValidator $validator) |
|
28 | + { |
|
29 | + parent::__construct($validator); |
|
30 | + $this->setNodeName(Api::NODE_NAME); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @throws DomainException |
|
36 | + * @since $VID:$ |
|
37 | + */ |
|
38 | + public function initialize() |
|
39 | + { |
|
40 | + $this->addData('restApiNonce', wp_create_nonce('wp_rest')); |
|
41 | + $this->addData('restApiBaseUrl', rest_url()); |
|
42 | + $this->addData('restApiRouteUrl', rest_url('ee/v4.8.36/')); |
|
43 | + $this->addData('restApiCollectionEndpoints', EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName()); |
|
44 | + $this->addData('restApiPrimaryKeys', EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName()); |
|
45 | + |
|
46 | + // route can be something like 'graphql' |
|
47 | + $route = trim(Router::$route, '/'); |
|
48 | + // make sure we are dealing with sane folks |
|
49 | + $has_pretty_permalinks = (bool) get_option('permalink_structure'); |
|
50 | + // if pretty permalinks, use '/graphql' otherwise '?graphql=1' |
|
51 | + $graphqlEndpoint = $has_pretty_permalinks ? site_url($route) : add_query_arg($route, 1, site_url()); |
|
52 | + $this->addData('graphqlEndpoint', esc_url($graphqlEndpoint)); |
|
53 | + $this->setInitialized(true); |
|
54 | + } |
|
55 | 55 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | 'Payment_Method' => new EE_Belongs_To_Relation(), |
56 | 56 | ]; |
57 | 57 | // this model is generally available for reading |
58 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
58 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
59 | 59 | $this->_caps_slug = 'payment_methods'; |
60 | 60 | parent::__construct($timezone); |
61 | 61 | } |
@@ -9,44 +9,44 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Currency_Payment_Method extends EEM_Base |
11 | 11 | { |
12 | - protected static ?EEM_Currency_Payment_Method $_instance = null; |
|
12 | + protected static ?EEM_Currency_Payment_Method $_instance = null; |
|
13 | 13 | |
14 | - protected function __construct($timezone = null) |
|
15 | - { |
|
16 | - $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso'); |
|
17 | - $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso'); |
|
18 | - $this->_tables = [ |
|
19 | - 'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'), |
|
20 | - ]; |
|
21 | - $this->_fields = [ |
|
22 | - 'Currency_Payment_Method' => [ |
|
23 | - 'CPM_ID' => new EE_Primary_Key_Int_Field( |
|
24 | - 'CPM_ID', |
|
25 | - esc_html__('Currency to Payment Method LInk ID', 'event_espresso') |
|
26 | - ), |
|
27 | - 'CUR_code' => new EE_Foreign_Key_String_Field( |
|
28 | - 'CUR_code', |
|
29 | - esc_html__('Currency Code', 'event_espresso'), |
|
30 | - false, |
|
31 | - '', |
|
32 | - 'Currency' |
|
33 | - ), |
|
34 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
35 | - 'PMD_ID', |
|
36 | - esc_html__('Paymetn Method ID', 'event_espresso'), |
|
37 | - false, |
|
38 | - 0, |
|
39 | - 'Payment_Method' |
|
40 | - ), |
|
41 | - ], |
|
42 | - ]; |
|
43 | - $this->_model_relations = [ |
|
44 | - 'Currency' => new EE_Belongs_To_Relation(), |
|
45 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
46 | - ]; |
|
47 | - // this model is generally available for reading |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
49 | - $this->_caps_slug = 'payment_methods'; |
|
50 | - parent::__construct($timezone); |
|
51 | - } |
|
14 | + protected function __construct($timezone = null) |
|
15 | + { |
|
16 | + $this->singular_item = esc_html__('Currency Usable by Payment Method', 'event_espresso'); |
|
17 | + $this->plural_item = esc_html__('Currencies Usable by Payment Methods', 'event_espresso'); |
|
18 | + $this->_tables = [ |
|
19 | + 'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'), |
|
20 | + ]; |
|
21 | + $this->_fields = [ |
|
22 | + 'Currency_Payment_Method' => [ |
|
23 | + 'CPM_ID' => new EE_Primary_Key_Int_Field( |
|
24 | + 'CPM_ID', |
|
25 | + esc_html__('Currency to Payment Method LInk ID', 'event_espresso') |
|
26 | + ), |
|
27 | + 'CUR_code' => new EE_Foreign_Key_String_Field( |
|
28 | + 'CUR_code', |
|
29 | + esc_html__('Currency Code', 'event_espresso'), |
|
30 | + false, |
|
31 | + '', |
|
32 | + 'Currency' |
|
33 | + ), |
|
34 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
35 | + 'PMD_ID', |
|
36 | + esc_html__('Paymetn Method ID', 'event_espresso'), |
|
37 | + false, |
|
38 | + 0, |
|
39 | + 'Payment_Method' |
|
40 | + ), |
|
41 | + ], |
|
42 | + ]; |
|
43 | + $this->_model_relations = [ |
|
44 | + 'Currency' => new EE_Belongs_To_Relation(), |
|
45 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
46 | + ]; |
|
47 | + // this model is generally available for reading |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
49 | + $this->_caps_slug = 'payment_methods'; |
|
50 | + parent::__construct($timezone); |
|
51 | + } |
|
52 | 52 | } |