@@ -36,144 +36,144 @@ |
||
36 | 36 | class BlockRegistrationManager extends BlockManager |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
41 | - */ |
|
42 | - protected $block_asset_manager_collection; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * BlockRegistrationManager constructor. |
|
47 | - * |
|
48 | - * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
49 | - * @param BlockCollection $blocks |
|
50 | - * @param RequestInterface $request |
|
51 | - */ |
|
52 | - public function __construct( |
|
53 | - BlockAssetManagerCollection $block_asset_manager_collection, |
|
54 | - BlockCollection $blocks, |
|
55 | - RequestInterface $request |
|
56 | - ) { |
|
57 | - $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
58 | - parent::__construct($blocks, $request); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Returns the name of a hookpoint to be used to call initialize() |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function initHook() |
|
68 | - { |
|
69 | - return 'AHEE__EE_System__core_loaded_and_ready'; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Perform any early setup required for block editors to functions |
|
75 | - * |
|
76 | - * @return void |
|
77 | - * @throws Exception |
|
78 | - */ |
|
79 | - public function initialize() |
|
80 | - { |
|
81 | - $this->initializeBlocks(); |
|
82 | - add_action('AHEE__EE_System__initialize', array($this, 'registerBlocks')); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return CollectionInterface|BlockInterface[] |
|
88 | - * @throws ReflectionException |
|
89 | - * @throws InvalidArgumentException |
|
90 | - * @throws EE_Error |
|
91 | - * @throws InvalidClassException |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidEntityException |
|
94 | - * @throws InvalidFilePathException |
|
95 | - * @throws InvalidIdentifierException |
|
96 | - * @throws InvalidInterfaceException |
|
97 | - */ |
|
98 | - protected function populateBlockCollection() |
|
99 | - { |
|
100 | - $loader = new CollectionLoader( |
|
101 | - new CollectionDetails( |
|
102 | - // collection name |
|
103 | - 'shortcodes', |
|
104 | - // collection interface |
|
105 | - 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
106 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
107 | - apply_filters( |
|
108 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
109 | - array( |
|
110 | - // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
111 | - // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
112 | - 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
113 | - ) |
|
114 | - ), |
|
115 | - // filepaths to classes to add |
|
116 | - array(), |
|
117 | - // file mask to use if parsing folder for files to add |
|
118 | - '', |
|
119 | - // what to use as identifier for collection entities |
|
120 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
121 | - CollectionDetails::ID_CLASS_NAME |
|
122 | - ), |
|
123 | - $this->blocks |
|
124 | - ); |
|
125 | - return $loader->getCollection(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * populates the BlockCollection and calls initialize() on all installed blocks |
|
131 | - * |
|
132 | - * @return void |
|
133 | - * @throws Exception |
|
134 | - */ |
|
135 | - public function initializeBlocks() |
|
136 | - { |
|
137 | - try { |
|
138 | - $this->populateBlockCollection(); |
|
139 | - // cycle thru block loaders and initialize each loader |
|
140 | - foreach ($this->blocks as $block) { |
|
141 | - $block->initialize(); |
|
142 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
143 | - $this->block_asset_manager_collection->add($block->assetManager()); |
|
144 | - $block->assetManager()->setAssetHandles(); |
|
145 | - } |
|
146 | - } |
|
147 | - } catch (Exception $exception) { |
|
148 | - new ExceptionStackTraceDisplay($exception); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * calls registerBlock() and load assets for all installed blocks |
|
155 | - * |
|
156 | - * @return void |
|
157 | - * @throws Exception |
|
158 | - */ |
|
159 | - public function registerBlocks() |
|
160 | - { |
|
161 | - try { |
|
162 | - // cycle thru block loader folders |
|
163 | - foreach ($this->blocks as $block) { |
|
164 | - // perform any setup required for the block |
|
165 | - $block_type = $block->registerBlock(); |
|
166 | - if (! $block_type instanceof WP_Block_Type) { |
|
167 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
168 | - } |
|
169 | - do_action( |
|
170 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
171 | - $block, |
|
172 | - $block_type |
|
173 | - ); |
|
174 | - } |
|
175 | - } catch (Exception $exception) { |
|
176 | - new ExceptionStackTraceDisplay($exception); |
|
177 | - } |
|
178 | - } |
|
39 | + /** |
|
40 | + * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
41 | + */ |
|
42 | + protected $block_asset_manager_collection; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * BlockRegistrationManager constructor. |
|
47 | + * |
|
48 | + * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
49 | + * @param BlockCollection $blocks |
|
50 | + * @param RequestInterface $request |
|
51 | + */ |
|
52 | + public function __construct( |
|
53 | + BlockAssetManagerCollection $block_asset_manager_collection, |
|
54 | + BlockCollection $blocks, |
|
55 | + RequestInterface $request |
|
56 | + ) { |
|
57 | + $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
58 | + parent::__construct($blocks, $request); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Returns the name of a hookpoint to be used to call initialize() |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function initHook() |
|
68 | + { |
|
69 | + return 'AHEE__EE_System__core_loaded_and_ready'; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Perform any early setup required for block editors to functions |
|
75 | + * |
|
76 | + * @return void |
|
77 | + * @throws Exception |
|
78 | + */ |
|
79 | + public function initialize() |
|
80 | + { |
|
81 | + $this->initializeBlocks(); |
|
82 | + add_action('AHEE__EE_System__initialize', array($this, 'registerBlocks')); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return CollectionInterface|BlockInterface[] |
|
88 | + * @throws ReflectionException |
|
89 | + * @throws InvalidArgumentException |
|
90 | + * @throws EE_Error |
|
91 | + * @throws InvalidClassException |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidEntityException |
|
94 | + * @throws InvalidFilePathException |
|
95 | + * @throws InvalidIdentifierException |
|
96 | + * @throws InvalidInterfaceException |
|
97 | + */ |
|
98 | + protected function populateBlockCollection() |
|
99 | + { |
|
100 | + $loader = new CollectionLoader( |
|
101 | + new CollectionDetails( |
|
102 | + // collection name |
|
103 | + 'shortcodes', |
|
104 | + // collection interface |
|
105 | + 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
106 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
107 | + apply_filters( |
|
108 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
109 | + array( |
|
110 | + // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
111 | + // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
112 | + 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
113 | + ) |
|
114 | + ), |
|
115 | + // filepaths to classes to add |
|
116 | + array(), |
|
117 | + // file mask to use if parsing folder for files to add |
|
118 | + '', |
|
119 | + // what to use as identifier for collection entities |
|
120 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
121 | + CollectionDetails::ID_CLASS_NAME |
|
122 | + ), |
|
123 | + $this->blocks |
|
124 | + ); |
|
125 | + return $loader->getCollection(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * populates the BlockCollection and calls initialize() on all installed blocks |
|
131 | + * |
|
132 | + * @return void |
|
133 | + * @throws Exception |
|
134 | + */ |
|
135 | + public function initializeBlocks() |
|
136 | + { |
|
137 | + try { |
|
138 | + $this->populateBlockCollection(); |
|
139 | + // cycle thru block loaders and initialize each loader |
|
140 | + foreach ($this->blocks as $block) { |
|
141 | + $block->initialize(); |
|
142 | + if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
143 | + $this->block_asset_manager_collection->add($block->assetManager()); |
|
144 | + $block->assetManager()->setAssetHandles(); |
|
145 | + } |
|
146 | + } |
|
147 | + } catch (Exception $exception) { |
|
148 | + new ExceptionStackTraceDisplay($exception); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * calls registerBlock() and load assets for all installed blocks |
|
155 | + * |
|
156 | + * @return void |
|
157 | + * @throws Exception |
|
158 | + */ |
|
159 | + public function registerBlocks() |
|
160 | + { |
|
161 | + try { |
|
162 | + // cycle thru block loader folders |
|
163 | + foreach ($this->blocks as $block) { |
|
164 | + // perform any setup required for the block |
|
165 | + $block_type = $block->registerBlock(); |
|
166 | + if (! $block_type instanceof WP_Block_Type) { |
|
167 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
168 | + } |
|
169 | + do_action( |
|
170 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
171 | + $block, |
|
172 | + $block_type |
|
173 | + ); |
|
174 | + } |
|
175 | + } catch (Exception $exception) { |
|
176 | + new ExceptionStackTraceDisplay($exception); |
|
177 | + } |
|
178 | + } |
|
179 | 179 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | /** @var Asset $asset */ |
76 | 76 | $asset = $this->current(); |
77 | 77 | if ($asset->type() === $type) { |
78 | - $files[ $asset->handle() ] = $asset; |
|
78 | + $files[$asset->handle()] = $asset; |
|
79 | 79 | } |
80 | 80 | $this->next(); |
81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** @var JavascriptAsset $asset */ |
97 | 97 | $asset = $this->current(); |
98 | 98 | if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
99 | - $files[ $asset->handle() ] = $asset; |
|
99 | + $files[$asset->handle()] = $asset; |
|
100 | 100 | } |
101 | 101 | $this->next(); |
102 | 102 | } |
@@ -21,201 +21,201 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * AssetCollection constructor |
|
26 | - * |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return StylesheetAsset[] |
|
37 | - * @since 4.9.62.p |
|
38 | - */ |
|
39 | - public function getStylesheetAssets() |
|
40 | - { |
|
41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return JavascriptAsset[] |
|
47 | - * @since 4.9.62.p |
|
48 | - */ |
|
49 | - public function getJavascriptAssets() |
|
50 | - { |
|
51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return ManifestFile[] |
|
57 | - * @since 4.9.62.p |
|
58 | - */ |
|
59 | - public function getManifestFiles() |
|
60 | - { |
|
61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param $type |
|
67 | - * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
|
68 | - * @since 4.9.62.p |
|
69 | - */ |
|
70 | - protected function getAssetsOfType($type) |
|
71 | - { |
|
72 | - $files = array(); |
|
73 | - $this->rewind(); |
|
74 | - while ($this->valid()) { |
|
75 | - /** @var Asset $asset */ |
|
76 | - $asset = $this->current(); |
|
77 | - if ($asset->type() === $type) { |
|
78 | - $files[ $asset->handle() ] = $asset; |
|
79 | - } |
|
80 | - $this->next(); |
|
81 | - } |
|
82 | - $this->rewind(); |
|
83 | - return $files; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return JavascriptAsset[] |
|
89 | - * @since 4.9.62.p |
|
90 | - */ |
|
91 | - public function getJavascriptAssetsWithData() |
|
92 | - { |
|
93 | - $files = array(); |
|
94 | - $this->rewind(); |
|
95 | - while ($this->valid()) { |
|
96 | - /** @var JavascriptAsset $asset */ |
|
97 | - $asset = $this->current(); |
|
98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
99 | - $files[ $asset->handle() ] = $asset; |
|
100 | - } |
|
101 | - $this->next(); |
|
102 | - } |
|
103 | - $this->rewind(); |
|
104 | - return $files; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * has |
|
110 | - * returns TRUE or FALSE |
|
111 | - * depending on whether the object is within the Collection |
|
112 | - * based on the supplied $identifier and type |
|
113 | - * |
|
114 | - * @access public |
|
115 | - * @param mixed $identifier |
|
116 | - * @param string $type |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
120 | - { |
|
121 | - $this->rewind(); |
|
122 | - while ($this->valid()) { |
|
123 | - if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
124 | - $this->rewind(); |
|
125 | - return true; |
|
126 | - } |
|
127 | - $this->next(); |
|
128 | - } |
|
129 | - return false; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * has |
|
135 | - * returns TRUE or FALSE |
|
136 | - * depending on whether the Stylesheet Asset is within the Collection |
|
137 | - * based on the supplied $identifier |
|
138 | - * |
|
139 | - * @access public |
|
140 | - * @param mixed $identifier |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function hasStylesheetAsset($identifier) |
|
144 | - { |
|
145 | - return $this->hasAssetOfType($identifier, Asset::TYPE_CSS); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * has |
|
151 | - * returns TRUE or FALSE |
|
152 | - * depending on whether the Javascript Asset is within the Collection |
|
153 | - * based on the supplied $identifier |
|
154 | - * |
|
155 | - * @access public |
|
156 | - * @param mixed $identifier |
|
157 | - * @return bool |
|
158 | - */ |
|
159 | - public function hasJavascriptAsset($identifier) |
|
160 | - { |
|
161 | - return $this->hasAssetOfType($identifier, Asset::TYPE_JS); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * has |
|
166 | - * returns TRUE or FALSE |
|
167 | - * depending on whether the object is within the Collection |
|
168 | - * based on the supplied $identifier and type |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @param mixed $identifier |
|
172 | - * @param string $type |
|
173 | - * @return JavascriptAsset|StylesheetAsset |
|
174 | - */ |
|
175 | - public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
176 | - { |
|
177 | - $this->rewind(); |
|
178 | - while ($this->valid()) { |
|
179 | - if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
180 | - /** @var JavascriptAsset|StylesheetAsset $object */ |
|
181 | - $object = $this->current(); |
|
182 | - $this->rewind(); |
|
183 | - return $object; |
|
184 | - } |
|
185 | - $this->next(); |
|
186 | - } |
|
187 | - return null; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * has |
|
193 | - * returns TRUE or FALSE |
|
194 | - * depending on whether the Stylesheet Asset is within the Collection |
|
195 | - * based on the supplied $identifier |
|
196 | - * |
|
197 | - * @access public |
|
198 | - * @param mixed $identifier |
|
199 | - * @return StylesheetAsset |
|
200 | - */ |
|
201 | - public function getStylesheetAsset($identifier) |
|
202 | - { |
|
203 | - return $this->getAssetOfType($identifier, Asset::TYPE_CSS); |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * has |
|
209 | - * returns TRUE or FALSE |
|
210 | - * depending on whether the Javascript Asset is within the Collection |
|
211 | - * based on the supplied $identifier |
|
212 | - * |
|
213 | - * @access public |
|
214 | - * @param mixed $identifier |
|
215 | - * @return JavascriptAsset |
|
216 | - */ |
|
217 | - public function getJavascriptAsset($identifier) |
|
218 | - { |
|
219 | - return $this->getAssetOfType($identifier, Asset::TYPE_JS); |
|
220 | - } |
|
24 | + /** |
|
25 | + * AssetCollection constructor |
|
26 | + * |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return StylesheetAsset[] |
|
37 | + * @since 4.9.62.p |
|
38 | + */ |
|
39 | + public function getStylesheetAssets() |
|
40 | + { |
|
41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return JavascriptAsset[] |
|
47 | + * @since 4.9.62.p |
|
48 | + */ |
|
49 | + public function getJavascriptAssets() |
|
50 | + { |
|
51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return ManifestFile[] |
|
57 | + * @since 4.9.62.p |
|
58 | + */ |
|
59 | + public function getManifestFiles() |
|
60 | + { |
|
61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param $type |
|
67 | + * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
|
68 | + * @since 4.9.62.p |
|
69 | + */ |
|
70 | + protected function getAssetsOfType($type) |
|
71 | + { |
|
72 | + $files = array(); |
|
73 | + $this->rewind(); |
|
74 | + while ($this->valid()) { |
|
75 | + /** @var Asset $asset */ |
|
76 | + $asset = $this->current(); |
|
77 | + if ($asset->type() === $type) { |
|
78 | + $files[ $asset->handle() ] = $asset; |
|
79 | + } |
|
80 | + $this->next(); |
|
81 | + } |
|
82 | + $this->rewind(); |
|
83 | + return $files; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return JavascriptAsset[] |
|
89 | + * @since 4.9.62.p |
|
90 | + */ |
|
91 | + public function getJavascriptAssetsWithData() |
|
92 | + { |
|
93 | + $files = array(); |
|
94 | + $this->rewind(); |
|
95 | + while ($this->valid()) { |
|
96 | + /** @var JavascriptAsset $asset */ |
|
97 | + $asset = $this->current(); |
|
98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
99 | + $files[ $asset->handle() ] = $asset; |
|
100 | + } |
|
101 | + $this->next(); |
|
102 | + } |
|
103 | + $this->rewind(); |
|
104 | + return $files; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * has |
|
110 | + * returns TRUE or FALSE |
|
111 | + * depending on whether the object is within the Collection |
|
112 | + * based on the supplied $identifier and type |
|
113 | + * |
|
114 | + * @access public |
|
115 | + * @param mixed $identifier |
|
116 | + * @param string $type |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
120 | + { |
|
121 | + $this->rewind(); |
|
122 | + while ($this->valid()) { |
|
123 | + if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
124 | + $this->rewind(); |
|
125 | + return true; |
|
126 | + } |
|
127 | + $this->next(); |
|
128 | + } |
|
129 | + return false; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * has |
|
135 | + * returns TRUE or FALSE |
|
136 | + * depending on whether the Stylesheet Asset is within the Collection |
|
137 | + * based on the supplied $identifier |
|
138 | + * |
|
139 | + * @access public |
|
140 | + * @param mixed $identifier |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function hasStylesheetAsset($identifier) |
|
144 | + { |
|
145 | + return $this->hasAssetOfType($identifier, Asset::TYPE_CSS); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * has |
|
151 | + * returns TRUE or FALSE |
|
152 | + * depending on whether the Javascript Asset is within the Collection |
|
153 | + * based on the supplied $identifier |
|
154 | + * |
|
155 | + * @access public |
|
156 | + * @param mixed $identifier |
|
157 | + * @return bool |
|
158 | + */ |
|
159 | + public function hasJavascriptAsset($identifier) |
|
160 | + { |
|
161 | + return $this->hasAssetOfType($identifier, Asset::TYPE_JS); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * has |
|
166 | + * returns TRUE or FALSE |
|
167 | + * depending on whether the object is within the Collection |
|
168 | + * based on the supplied $identifier and type |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @param mixed $identifier |
|
172 | + * @param string $type |
|
173 | + * @return JavascriptAsset|StylesheetAsset |
|
174 | + */ |
|
175 | + public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
176 | + { |
|
177 | + $this->rewind(); |
|
178 | + while ($this->valid()) { |
|
179 | + if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
180 | + /** @var JavascriptAsset|StylesheetAsset $object */ |
|
181 | + $object = $this->current(); |
|
182 | + $this->rewind(); |
|
183 | + return $object; |
|
184 | + } |
|
185 | + $this->next(); |
|
186 | + } |
|
187 | + return null; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * has |
|
193 | + * returns TRUE or FALSE |
|
194 | + * depending on whether the Stylesheet Asset is within the Collection |
|
195 | + * based on the supplied $identifier |
|
196 | + * |
|
197 | + * @access public |
|
198 | + * @param mixed $identifier |
|
199 | + * @return StylesheetAsset |
|
200 | + */ |
|
201 | + public function getStylesheetAsset($identifier) |
|
202 | + { |
|
203 | + return $this->getAssetOfType($identifier, Asset::TYPE_CSS); |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * has |
|
209 | + * returns TRUE or FALSE |
|
210 | + * depending on whether the Javascript Asset is within the Collection |
|
211 | + * based on the supplied $identifier |
|
212 | + * |
|
213 | + * @access public |
|
214 | + * @param mixed $identifier |
|
215 | + * @return JavascriptAsset |
|
216 | + */ |
|
217 | + public function getJavascriptAsset($identifier) |
|
218 | + { |
|
219 | + return $this->getAssetOfType($identifier, Asset::TYPE_JS); |
|
220 | + } |
|
221 | 221 | } |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use EventEspresso\core\domain\entities\editor\BlockInterface; |
6 | 6 | use EventEspresso\core\domain\services\assets\CoreAssetManager; |
7 | -use EventEspresso\core\domain\values\assets\Asset; |
|
8 | 7 | use EventEspresso\core\domain\values\assets\BrowserAsset; |
9 | 8 | use EventEspresso\core\domain\values\assets\JavascriptAsset; |
10 | 9 | use EventEspresso\core\domain\values\assets\StylesheetAsset; |
@@ -23,311 +23,311 @@ |
||
23 | 23 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var string $editor_script_handle |
|
28 | - */ |
|
29 | - private $editor_script_handle; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $editor_style_handle |
|
33 | - */ |
|
34 | - private $editor_style_handle; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $script_handle |
|
38 | - */ |
|
39 | - private $script_handle; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string $style_handle |
|
43 | - */ |
|
44 | - private $style_handle; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getEditorScriptHandle() |
|
51 | - { |
|
52 | - return $this->editor_script_handle; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $editor_script_handle |
|
58 | - */ |
|
59 | - public function setEditorScriptHandle($editor_script_handle) |
|
60 | - { |
|
61 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
62 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
63 | - } |
|
64 | - $this->editor_script_handle = $editor_script_handle; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getEditorStyleHandle() |
|
72 | - { |
|
73 | - return $this->editor_style_handle; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @param string $editor_style_handle |
|
79 | - */ |
|
80 | - public function setEditorStyleHandle($editor_style_handle) |
|
81 | - { |
|
82 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
83 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
84 | - } |
|
85 | - $this->editor_style_handle = $editor_style_handle; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function getScriptHandle() |
|
93 | - { |
|
94 | - return $this->script_handle; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $script_handle |
|
100 | - */ |
|
101 | - public function setScriptHandle($script_handle) |
|
102 | - { |
|
103 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
104 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
105 | - } |
|
106 | - $this->script_handle = $script_handle; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function getStyleHandle() |
|
114 | - { |
|
115 | - return $this->style_handle; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $style_handle |
|
121 | - */ |
|
122 | - public function setStyleHandle($style_handle) |
|
123 | - { |
|
124 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
125 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
126 | - } |
|
127 | - $this->style_handle = $style_handle; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @since $VID:$ |
|
132 | - * @throws InvalidDataTypeException |
|
133 | - * @throws InvalidEntityException |
|
134 | - * @throws DuplicateCollectionIdentifierException |
|
135 | - */ |
|
136 | - public function addAssets() |
|
137 | - { |
|
138 | - $this->addEditorScript($this->getEditorScriptHandle()); |
|
139 | - $this->addEditorStyle($this->getEditorStyleHandle()); |
|
140 | - $this->setScriptHandle($this->getScriptHandle()); |
|
141 | - $this->setStyleHandle($this->getStyleHandle()); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param $handle |
|
147 | - * @param array $dependencies |
|
148 | - * @since $VID:$ |
|
149 | - * @return JavascriptAsset |
|
150 | - * @throws InvalidDataTypeException |
|
151 | - * @throws InvalidEntityException |
|
152 | - * @throws DuplicateCollectionIdentifierException |
|
153 | - */ |
|
154 | - public function addEditorScript($handle, array $dependencies = array()) |
|
155 | - { |
|
156 | - if($this->assets->hasJavascriptAsset($handle)){ |
|
157 | - return $this->assets->getJavascriptAsset($handle); |
|
158 | - } |
|
159 | - return parent::addJavascript( |
|
160 | - $handle, |
|
161 | - $this->registry->getJsUrl( |
|
162 | - $this->domain->assetNamespace(), |
|
163 | - $handle |
|
164 | - ), |
|
165 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
166 | - ) |
|
167 | - ->setRequiresTranslation(); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param $handle |
|
173 | - * @param array $dependencies |
|
174 | - * @since $VID:$ |
|
175 | - * @return StylesheetAsset |
|
176 | - * @throws InvalidDataTypeException |
|
177 | - * @throws InvalidEntityException |
|
178 | - * @throws DuplicateCollectionIdentifierException |
|
179 | - */ |
|
180 | - public function addEditorStyle($handle, array $dependencies = array()) |
|
181 | - { |
|
182 | - if ($this->assets->hasStylesheetAsset($handle)) { |
|
183 | - return $this->assets->getStylesheetAsset($handle); |
|
184 | - } |
|
185 | - return parent::addStylesheet( |
|
186 | - $handle, |
|
187 | - $this->registry->getCssUrl( |
|
188 | - $this->domain->assetNamespace(), |
|
189 | - $handle |
|
190 | - ), |
|
191 | - $dependencies |
|
192 | - ); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param $handle |
|
198 | - * @param array $dependencies |
|
199 | - * @since $VID:$ |
|
200 | - * @return JavascriptAsset |
|
201 | - * @throws InvalidDataTypeException |
|
202 | - * @throws InvalidEntityException |
|
203 | - * @throws DuplicateCollectionIdentifierException |
|
204 | - */ |
|
205 | - public function addScript($handle, array $dependencies = array()) |
|
206 | - { |
|
207 | - if ($this->assets->hasJavascriptAsset($handle)) { |
|
208 | - return $this->assets->getJavascriptAsset($handle); |
|
209 | - } |
|
210 | - return parent::addJavascript( |
|
211 | - $handle, |
|
212 | - $this->registry->getJsUrl( |
|
213 | - $this->domain->assetNamespace(), |
|
214 | - $handle |
|
215 | - ), |
|
216 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
217 | - ) |
|
218 | - ->setRequiresTranslation(); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param $handle |
|
224 | - * @param array $dependencies |
|
225 | - * @since $VID:$ |
|
226 | - * @return StylesheetAsset |
|
227 | - * @throws InvalidDataTypeException |
|
228 | - * @throws InvalidEntityException |
|
229 | - * @throws DuplicateCollectionIdentifierException |
|
230 | - */ |
|
231 | - public function addStyle($handle, array $dependencies = array()) |
|
232 | - { |
|
233 | - if ($this->assets->hasStylesheetAsset($handle)) { |
|
234 | - return $this->assets->getStylesheetAsset($handle); |
|
235 | - } |
|
236 | - return parent::addStylesheet( |
|
237 | - $handle, |
|
238 | - $this->registry->getCssUrl( |
|
239 | - $this->domain->assetNamespace(), |
|
240 | - $handle |
|
241 | - ), |
|
242 | - $dependencies |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param array $dependencies |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
252 | - { |
|
253 | - $dependencies += array( |
|
254 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | - 'wp-i18n', // Provides localization functions |
|
256 | - 'wp-element', // Provides React.Component |
|
257 | - 'wp-components', // Provides many prebuilt components and controls |
|
258 | - CoreAssetManager::JS_HANDLE_EE_COMPONENTS |
|
259 | - ); |
|
260 | - return $dependencies; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $handle |
|
266 | - * @param string $type |
|
267 | - * @return mixed|null |
|
268 | - * @since $VID:$ |
|
269 | - */ |
|
270 | - public function getAsset($handle, $type) |
|
271 | - { |
|
272 | - if ($this->assets->hasAssetOfType($handle, $type)) { |
|
273 | - return $this->assets->getAssetOfType($handle, $type); |
|
274 | - } |
|
275 | - return null; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @return JavascriptAsset|null |
|
281 | - */ |
|
282 | - public function getEditorScript() |
|
283 | - { |
|
284 | - return $this->assets->getJavascriptAsset($this->editor_script_handle); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return StylesheetAsset|null |
|
290 | - */ |
|
291 | - public function getEditorStyle() |
|
292 | - { |
|
293 | - return $this->assets->getStylesheetAsset($this->editor_style_handle); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @return JavascriptAsset|null |
|
299 | - */ |
|
300 | - public function getScript() |
|
301 | - { |
|
302 | - return $this->assets->getJavascriptAsset($this->script_handle); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * @return StylesheetAsset|null |
|
308 | - */ |
|
309 | - public function getStyle() |
|
310 | - { |
|
311 | - return $this->assets->getStylesheetAsset($this->style_handle); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * @return void |
|
317 | - */ |
|
318 | - public function enqueueAssets() |
|
319 | - { |
|
320 | - $assets = array( |
|
321 | - $this->getEditorScript(), |
|
322 | - $this->getEditorStyle(), |
|
323 | - $this->getScript(), |
|
324 | - $this->getStyle(), |
|
325 | - ); |
|
326 | - foreach ($assets as $asset) { |
|
327 | - if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
328 | - $asset->enqueueAsset(); |
|
329 | - } |
|
330 | - } |
|
331 | - } |
|
26 | + /** |
|
27 | + * @var string $editor_script_handle |
|
28 | + */ |
|
29 | + private $editor_script_handle; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $editor_style_handle |
|
33 | + */ |
|
34 | + private $editor_style_handle; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $script_handle |
|
38 | + */ |
|
39 | + private $script_handle; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string $style_handle |
|
43 | + */ |
|
44 | + private $style_handle; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getEditorScriptHandle() |
|
51 | + { |
|
52 | + return $this->editor_script_handle; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $editor_script_handle |
|
58 | + */ |
|
59 | + public function setEditorScriptHandle($editor_script_handle) |
|
60 | + { |
|
61 | + if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
62 | + $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
63 | + } |
|
64 | + $this->editor_script_handle = $editor_script_handle; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getEditorStyleHandle() |
|
72 | + { |
|
73 | + return $this->editor_style_handle; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @param string $editor_style_handle |
|
79 | + */ |
|
80 | + public function setEditorStyleHandle($editor_style_handle) |
|
81 | + { |
|
82 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
83 | + $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
84 | + } |
|
85 | + $this->editor_style_handle = $editor_style_handle; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function getScriptHandle() |
|
93 | + { |
|
94 | + return $this->script_handle; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $script_handle |
|
100 | + */ |
|
101 | + public function setScriptHandle($script_handle) |
|
102 | + { |
|
103 | + if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
104 | + $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
105 | + } |
|
106 | + $this->script_handle = $script_handle; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function getStyleHandle() |
|
114 | + { |
|
115 | + return $this->style_handle; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $style_handle |
|
121 | + */ |
|
122 | + public function setStyleHandle($style_handle) |
|
123 | + { |
|
124 | + if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
125 | + $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
126 | + } |
|
127 | + $this->style_handle = $style_handle; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @since $VID:$ |
|
132 | + * @throws InvalidDataTypeException |
|
133 | + * @throws InvalidEntityException |
|
134 | + * @throws DuplicateCollectionIdentifierException |
|
135 | + */ |
|
136 | + public function addAssets() |
|
137 | + { |
|
138 | + $this->addEditorScript($this->getEditorScriptHandle()); |
|
139 | + $this->addEditorStyle($this->getEditorStyleHandle()); |
|
140 | + $this->setScriptHandle($this->getScriptHandle()); |
|
141 | + $this->setStyleHandle($this->getStyleHandle()); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param $handle |
|
147 | + * @param array $dependencies |
|
148 | + * @since $VID:$ |
|
149 | + * @return JavascriptAsset |
|
150 | + * @throws InvalidDataTypeException |
|
151 | + * @throws InvalidEntityException |
|
152 | + * @throws DuplicateCollectionIdentifierException |
|
153 | + */ |
|
154 | + public function addEditorScript($handle, array $dependencies = array()) |
|
155 | + { |
|
156 | + if($this->assets->hasJavascriptAsset($handle)){ |
|
157 | + return $this->assets->getJavascriptAsset($handle); |
|
158 | + } |
|
159 | + return parent::addJavascript( |
|
160 | + $handle, |
|
161 | + $this->registry->getJsUrl( |
|
162 | + $this->domain->assetNamespace(), |
|
163 | + $handle |
|
164 | + ), |
|
165 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
166 | + ) |
|
167 | + ->setRequiresTranslation(); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param $handle |
|
173 | + * @param array $dependencies |
|
174 | + * @since $VID:$ |
|
175 | + * @return StylesheetAsset |
|
176 | + * @throws InvalidDataTypeException |
|
177 | + * @throws InvalidEntityException |
|
178 | + * @throws DuplicateCollectionIdentifierException |
|
179 | + */ |
|
180 | + public function addEditorStyle($handle, array $dependencies = array()) |
|
181 | + { |
|
182 | + if ($this->assets->hasStylesheetAsset($handle)) { |
|
183 | + return $this->assets->getStylesheetAsset($handle); |
|
184 | + } |
|
185 | + return parent::addStylesheet( |
|
186 | + $handle, |
|
187 | + $this->registry->getCssUrl( |
|
188 | + $this->domain->assetNamespace(), |
|
189 | + $handle |
|
190 | + ), |
|
191 | + $dependencies |
|
192 | + ); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param $handle |
|
198 | + * @param array $dependencies |
|
199 | + * @since $VID:$ |
|
200 | + * @return JavascriptAsset |
|
201 | + * @throws InvalidDataTypeException |
|
202 | + * @throws InvalidEntityException |
|
203 | + * @throws DuplicateCollectionIdentifierException |
|
204 | + */ |
|
205 | + public function addScript($handle, array $dependencies = array()) |
|
206 | + { |
|
207 | + if ($this->assets->hasJavascriptAsset($handle)) { |
|
208 | + return $this->assets->getJavascriptAsset($handle); |
|
209 | + } |
|
210 | + return parent::addJavascript( |
|
211 | + $handle, |
|
212 | + $this->registry->getJsUrl( |
|
213 | + $this->domain->assetNamespace(), |
|
214 | + $handle |
|
215 | + ), |
|
216 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
217 | + ) |
|
218 | + ->setRequiresTranslation(); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param $handle |
|
224 | + * @param array $dependencies |
|
225 | + * @since $VID:$ |
|
226 | + * @return StylesheetAsset |
|
227 | + * @throws InvalidDataTypeException |
|
228 | + * @throws InvalidEntityException |
|
229 | + * @throws DuplicateCollectionIdentifierException |
|
230 | + */ |
|
231 | + public function addStyle($handle, array $dependencies = array()) |
|
232 | + { |
|
233 | + if ($this->assets->hasStylesheetAsset($handle)) { |
|
234 | + return $this->assets->getStylesheetAsset($handle); |
|
235 | + } |
|
236 | + return parent::addStylesheet( |
|
237 | + $handle, |
|
238 | + $this->registry->getCssUrl( |
|
239 | + $this->domain->assetNamespace(), |
|
240 | + $handle |
|
241 | + ), |
|
242 | + $dependencies |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param array $dependencies |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
252 | + { |
|
253 | + $dependencies += array( |
|
254 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | + 'wp-i18n', // Provides localization functions |
|
256 | + 'wp-element', // Provides React.Component |
|
257 | + 'wp-components', // Provides many prebuilt components and controls |
|
258 | + CoreAssetManager::JS_HANDLE_EE_COMPONENTS |
|
259 | + ); |
|
260 | + return $dependencies; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $handle |
|
266 | + * @param string $type |
|
267 | + * @return mixed|null |
|
268 | + * @since $VID:$ |
|
269 | + */ |
|
270 | + public function getAsset($handle, $type) |
|
271 | + { |
|
272 | + if ($this->assets->hasAssetOfType($handle, $type)) { |
|
273 | + return $this->assets->getAssetOfType($handle, $type); |
|
274 | + } |
|
275 | + return null; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @return JavascriptAsset|null |
|
281 | + */ |
|
282 | + public function getEditorScript() |
|
283 | + { |
|
284 | + return $this->assets->getJavascriptAsset($this->editor_script_handle); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return StylesheetAsset|null |
|
290 | + */ |
|
291 | + public function getEditorStyle() |
|
292 | + { |
|
293 | + return $this->assets->getStylesheetAsset($this->editor_style_handle); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @return JavascriptAsset|null |
|
299 | + */ |
|
300 | + public function getScript() |
|
301 | + { |
|
302 | + return $this->assets->getJavascriptAsset($this->script_handle); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * @return StylesheetAsset|null |
|
308 | + */ |
|
309 | + public function getStyle() |
|
310 | + { |
|
311 | + return $this->assets->getStylesheetAsset($this->style_handle); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * @return void |
|
317 | + */ |
|
318 | + public function enqueueAssets() |
|
319 | + { |
|
320 | + $assets = array( |
|
321 | + $this->getEditorScript(), |
|
322 | + $this->getEditorStyle(), |
|
323 | + $this->getScript(), |
|
324 | + $this->getStyle(), |
|
325 | + ); |
|
326 | + foreach ($assets as $asset) { |
|
327 | + if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
328 | + $asset->enqueueAsset(); |
|
329 | + } |
|
330 | + } |
|
331 | + } |
|
332 | 332 | |
333 | 333 | } |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function setEditorScriptHandle($editor_script_handle) |
60 | 60 | { |
61 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
62 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
61 | + if (strpos($editor_script_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
62 | + $editor_script_handle = BlockInterface::NAME_SPACE.'-'.$editor_script_handle; |
|
63 | 63 | } |
64 | 64 | $this->editor_script_handle = $editor_script_handle; |
65 | 65 | } |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function setEditorStyleHandle($editor_style_handle) |
81 | 81 | { |
82 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
83 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
82 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
83 | + $editor_style_handle = BlockInterface::NAME_SPACE.'-'.$editor_style_handle; |
|
84 | 84 | } |
85 | 85 | $this->editor_style_handle = $editor_style_handle; |
86 | 86 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function setScriptHandle($script_handle) |
102 | 102 | { |
103 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
104 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
103 | + if (strpos($script_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
104 | + $script_handle = BlockInterface::NAME_SPACE.'-'.$script_handle; |
|
105 | 105 | } |
106 | 106 | $this->script_handle = $script_handle; |
107 | 107 | } |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function setStyleHandle($style_handle) |
123 | 123 | { |
124 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
125 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
124 | + if (strpos($style_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
125 | + $style_handle = BlockInterface::NAME_SPACE.'-'.$style_handle; |
|
126 | 126 | } |
127 | 127 | $this->style_handle = $style_handle; |
128 | 128 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function addEditorScript($handle, array $dependencies = array()) |
155 | 155 | { |
156 | - if($this->assets->hasJavascriptAsset($handle)){ |
|
156 | + if ($this->assets->hasJavascriptAsset($handle)) { |
|
157 | 157 | return $this->assets->getJavascriptAsset($handle); |
158 | 158 | } |
159 | 159 | return parent::addJavascript( |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | protected function addDefaultBlockScriptDependencies(array $dependencies) |
252 | 252 | { |
253 | 253 | $dependencies += array( |
254 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | - 'wp-i18n', // Provides localization functions |
|
256 | - 'wp-element', // Provides React.Component |
|
254 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | + 'wp-i18n', // Provides localization functions |
|
256 | + 'wp-element', // Provides React.Component |
|
257 | 257 | 'wp-components', // Provides many prebuilt components and controls |
258 | 258 | CoreAssetManager::JS_HANDLE_EE_COMPONENTS |
259 | 259 | ); |
@@ -23,43 +23,43 @@ |
||
23 | 23 | class Attendee extends Calculations_Base |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @since $VID:$ |
|
28 | - * @param $wpdb_row |
|
29 | - * @return EE_Attendee|\EE_Base_Class |
|
30 | - * @throws EE_Error |
|
31 | - * @throws InvalidArgumentException |
|
32 | - * @throws InvalidDataTypeException |
|
33 | - * @throws InvalidInterfaceException |
|
34 | - */ |
|
35 | - private static function getAttendeeObject($wpdb_row) |
|
36 | - { |
|
37 | - $attendee = null; |
|
38 | - if (is_array($wpdb_row) && isset($wpdb_row['Attendee_CPT.ID']) && absint($wpdb_row['Attendee_CPT.ID'])) { |
|
39 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($wpdb_row['Attendee_CPT.ID']); |
|
40 | - } |
|
41 | - return $attendee; |
|
42 | - } |
|
26 | + /** |
|
27 | + * @since $VID:$ |
|
28 | + * @param $wpdb_row |
|
29 | + * @return EE_Attendee|\EE_Base_Class |
|
30 | + * @throws EE_Error |
|
31 | + * @throws InvalidArgumentException |
|
32 | + * @throws InvalidDataTypeException |
|
33 | + * @throws InvalidInterfaceException |
|
34 | + */ |
|
35 | + private static function getAttendeeObject($wpdb_row) |
|
36 | + { |
|
37 | + $attendee = null; |
|
38 | + if (is_array($wpdb_row) && isset($wpdb_row['Attendee_CPT.ID']) && absint($wpdb_row['Attendee_CPT.ID'])) { |
|
39 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($wpdb_row['Attendee_CPT.ID']); |
|
40 | + } |
|
41 | + return $attendee; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param array $wpdb_row |
|
47 | - * @param WP_REST_Request $request |
|
48 | - * @param Base $controller |
|
49 | - * @since $VID:$ |
|
50 | - * @return string |
|
51 | - * @throws EE_Error |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws InvalidDataTypeException |
|
54 | - * @throws InvalidInterfaceException |
|
55 | - */ |
|
56 | - public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
|
57 | - { |
|
58 | - $attendee = Attendee::getAttendeeObject($wpdb_row); |
|
59 | - if (! $attendee instanceof EE_Attendee) { |
|
60 | - return ''; |
|
61 | - } |
|
62 | - $avatar = get_avatar_url($attendee->email()); |
|
63 | - return $avatar ? $avatar : ''; |
|
64 | - } |
|
45 | + /** |
|
46 | + * @param array $wpdb_row |
|
47 | + * @param WP_REST_Request $request |
|
48 | + * @param Base $controller |
|
49 | + * @since $VID:$ |
|
50 | + * @return string |
|
51 | + * @throws EE_Error |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws InvalidDataTypeException |
|
54 | + * @throws InvalidInterfaceException |
|
55 | + */ |
|
56 | + public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
|
57 | + { |
|
58 | + $attendee = Attendee::getAttendeeObject($wpdb_row); |
|
59 | + if (! $attendee instanceof EE_Attendee) { |
|
60 | + return ''; |
|
61 | + } |
|
62 | + $avatar = get_avatar_url($attendee->email()); |
|
63 | + return $avatar ? $avatar : ''; |
|
64 | + } |
|
65 | 65 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
57 | 57 | { |
58 | 58 | $attendee = Attendee::getAttendeeObject($wpdb_row); |
59 | - if (! $attendee instanceof EE_Attendee) { |
|
59 | + if ( ! $attendee instanceof EE_Attendee) { |
|
60 | 60 | return ''; |
61 | 61 | } |
62 | 62 | $avatar = get_avatar_url($attendee->email()); |
@@ -19,128 +19,128 @@ |
||
19 | 19 | class CalculatedModelFields |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $mapping; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $mapping; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @param bool $refresh |
|
30 | - * @return array top-level-keys are model names (eg "Event") |
|
31 | - * next-level are the calculated field names AND method names on classes |
|
32 | - * which perform calculations, values are the fully qualified classnames which do the calculations |
|
33 | - * These callbacks should accept as arguments: |
|
34 | - * the wpdb row results, |
|
35 | - * the WP_Request object, |
|
36 | - * the controller object |
|
37 | - */ |
|
38 | - public function mapping($refresh = false) |
|
39 | - { |
|
40 | - if (! $this->mapping || $refresh) { |
|
41 | - $this->mapping = $this->generateNewMapping(); |
|
42 | - } |
|
43 | - return $this->mapping; |
|
44 | - } |
|
28 | + /** |
|
29 | + * @param bool $refresh |
|
30 | + * @return array top-level-keys are model names (eg "Event") |
|
31 | + * next-level are the calculated field names AND method names on classes |
|
32 | + * which perform calculations, values are the fully qualified classnames which do the calculations |
|
33 | + * These callbacks should accept as arguments: |
|
34 | + * the wpdb row results, |
|
35 | + * the WP_Request object, |
|
36 | + * the controller object |
|
37 | + */ |
|
38 | + public function mapping($refresh = false) |
|
39 | + { |
|
40 | + if (! $this->mapping || $refresh) { |
|
41 | + $this->mapping = $this->generateNewMapping(); |
|
42 | + } |
|
43 | + return $this->mapping; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Generates anew mapping between model calculated fields and their callbacks |
|
49 | - * |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function generateNewMapping() |
|
53 | - { |
|
54 | - $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | - $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
59 | - return apply_filters( |
|
60 | - 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
61 | - array( |
|
62 | - 'Event' => array( |
|
63 | - 'optimum_sales_at_start' => $event_calculations_class, |
|
64 | - 'optimum_sales_now' => $event_calculations_class, |
|
65 | - 'spots_taken' => $event_calculations_class, |
|
66 | - 'spots_taken_pending_payment' => $event_calculations_class, |
|
67 | - 'spaces_remaining' => $event_calculations_class, |
|
68 | - 'registrations_checked_in_count' => $event_calculations_class, |
|
69 | - 'registrations_checked_out_count' => $event_calculations_class, |
|
70 | - 'image_thumbnail' => $event_calculations_class, |
|
71 | - 'image_medium' => $event_calculations_class, |
|
72 | - 'image_medium_large' => $event_calculations_class, |
|
73 | - 'image_large' => $event_calculations_class, |
|
74 | - 'image_post_thumbnail' => $event_calculations_class, |
|
75 | - 'image_full' => $event_calculations_class, |
|
76 | - ), |
|
77 | - 'Datetime' => array( |
|
78 | - 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
79 | - 'registrations_checked_in_count' => $datetime_calculations_class, |
|
80 | - 'registrations_checked_out_count' => $datetime_calculations_class, |
|
81 | - 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
82 | - ), |
|
83 | - 'Registration' => array( |
|
84 | - 'datetime_checkin_stati' => $registration_class, |
|
85 | - ), |
|
86 | - 'Attendee' => array( |
|
87 | - 'userAvatar' => $attendee_class, |
|
88 | - ), |
|
89 | - ) |
|
90 | - ); |
|
91 | - } |
|
47 | + /** |
|
48 | + * Generates anew mapping between model calculated fields and their callbacks |
|
49 | + * |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function generateNewMapping() |
|
53 | + { |
|
54 | + $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | + $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | + $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
59 | + return apply_filters( |
|
60 | + 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
|
61 | + array( |
|
62 | + 'Event' => array( |
|
63 | + 'optimum_sales_at_start' => $event_calculations_class, |
|
64 | + 'optimum_sales_now' => $event_calculations_class, |
|
65 | + 'spots_taken' => $event_calculations_class, |
|
66 | + 'spots_taken_pending_payment' => $event_calculations_class, |
|
67 | + 'spaces_remaining' => $event_calculations_class, |
|
68 | + 'registrations_checked_in_count' => $event_calculations_class, |
|
69 | + 'registrations_checked_out_count' => $event_calculations_class, |
|
70 | + 'image_thumbnail' => $event_calculations_class, |
|
71 | + 'image_medium' => $event_calculations_class, |
|
72 | + 'image_medium_large' => $event_calculations_class, |
|
73 | + 'image_large' => $event_calculations_class, |
|
74 | + 'image_post_thumbnail' => $event_calculations_class, |
|
75 | + 'image_full' => $event_calculations_class, |
|
76 | + ), |
|
77 | + 'Datetime' => array( |
|
78 | + 'spaces_remaining_considering_tickets' => $datetime_calculations_class, |
|
79 | + 'registrations_checked_in_count' => $datetime_calculations_class, |
|
80 | + 'registrations_checked_out_count' => $datetime_calculations_class, |
|
81 | + 'spots_taken_pending_payment' => $datetime_calculations_class, |
|
82 | + ), |
|
83 | + 'Registration' => array( |
|
84 | + 'datetime_checkin_stati' => $registration_class, |
|
85 | + ), |
|
86 | + 'Attendee' => array( |
|
87 | + 'userAvatar' => $attendee_class, |
|
88 | + ), |
|
89 | + ) |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Gets the known calculated fields for model |
|
96 | - * |
|
97 | - * @param EEM_Base $model |
|
98 | - * @return array allowable values for this field |
|
99 | - */ |
|
100 | - public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
|
101 | - { |
|
102 | - $mapping = $this->mapping(); |
|
103 | - if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | - return array_keys($mapping[ $model->get_this_model_name() ]); |
|
105 | - } else { |
|
106 | - return array(); |
|
107 | - } |
|
108 | - } |
|
94 | + /** |
|
95 | + * Gets the known calculated fields for model |
|
96 | + * |
|
97 | + * @param EEM_Base $model |
|
98 | + * @return array allowable values for this field |
|
99 | + */ |
|
100 | + public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
|
101 | + { |
|
102 | + $mapping = $this->mapping(); |
|
103 | + if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | + return array_keys($mapping[ $model->get_this_model_name() ]); |
|
105 | + } else { |
|
106 | + return array(); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * Retrieves the value for this calculation |
|
113 | - * |
|
114 | - * @param EEM_Base $model |
|
115 | - * @param string $field_name |
|
116 | - * @param array $wpdb_row |
|
117 | - * @param \WP_REST_Request |
|
118 | - * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
119 | - * @return mixed|null |
|
120 | - * @throws \EE_Error |
|
121 | - */ |
|
122 | - public function retrieveCalculatedFieldValue( |
|
123 | - EEM_Base $model, |
|
124 | - $field_name, |
|
125 | - $wpdb_row, |
|
126 | - $rest_request, |
|
127 | - Base $controller |
|
128 | - ) { |
|
129 | - $mapping = $this->mapping(); |
|
130 | - if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | - && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
132 | - ) { |
|
133 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
134 | - $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
|
135 | - return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
|
136 | - } |
|
137 | - throw new RestException( |
|
138 | - 'calculated_field_does_not_exist', |
|
139 | - sprintf( |
|
140 | - __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
141 | - $field_name, |
|
142 | - $model->get_this_model_name() |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
111 | + /** |
|
112 | + * Retrieves the value for this calculation |
|
113 | + * |
|
114 | + * @param EEM_Base $model |
|
115 | + * @param string $field_name |
|
116 | + * @param array $wpdb_row |
|
117 | + * @param \WP_REST_Request |
|
118 | + * @param \EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
119 | + * @return mixed|null |
|
120 | + * @throws \EE_Error |
|
121 | + */ |
|
122 | + public function retrieveCalculatedFieldValue( |
|
123 | + EEM_Base $model, |
|
124 | + $field_name, |
|
125 | + $wpdb_row, |
|
126 | + $rest_request, |
|
127 | + Base $controller |
|
128 | + ) { |
|
129 | + $mapping = $this->mapping(); |
|
130 | + if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | + && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
132 | + ) { |
|
133 | + $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
134 | + $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
|
135 | + return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
|
136 | + } |
|
137 | + throw new RestException( |
|
138 | + 'calculated_field_does_not_exist', |
|
139 | + sprintf( |
|
140 | + __('There is no calculated field %1$s on resource %2$s', 'event_espresso'), |
|
141 | + $field_name, |
|
142 | + $model->get_this_model_name() |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function mapping($refresh = false) |
39 | 39 | { |
40 | - if (! $this->mapping || $refresh) { |
|
40 | + if ( ! $this->mapping || $refresh) { |
|
41 | 41 | $this->mapping = $this->generateNewMapping(); |
42 | 42 | } |
43 | 43 | return $this->mapping; |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | protected function generateNewMapping() |
53 | 53 | { |
54 | 54 | $rest_api_calculations_namespace = 'EventEspresso\core\libraries\rest_api\calculations\\'; |
55 | - $event_calculations_class = $rest_api_calculations_namespace . 'Event'; |
|
56 | - $datetime_calculations_class = $rest_api_calculations_namespace . 'Datetime'; |
|
57 | - $registration_class = $rest_api_calculations_namespace . 'Registration'; |
|
58 | - $attendee_class = $rest_api_calculations_namespace . 'Attendee'; |
|
55 | + $event_calculations_class = $rest_api_calculations_namespace.'Event'; |
|
56 | + $datetime_calculations_class = $rest_api_calculations_namespace.'Datetime'; |
|
57 | + $registration_class = $rest_api_calculations_namespace.'Registration'; |
|
58 | + $attendee_class = $rest_api_calculations_namespace.'Attendee'; |
|
59 | 59 | return apply_filters( |
60 | 60 | 'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping', |
61 | 61 | array( |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
101 | 101 | { |
102 | 102 | $mapping = $this->mapping(); |
103 | - if (isset($mapping[ $model->get_this_model_name() ])) { |
|
104 | - return array_keys($mapping[ $model->get_this_model_name() ]); |
|
103 | + if (isset($mapping[$model->get_this_model_name()])) { |
|
104 | + return array_keys($mapping[$model->get_this_model_name()]); |
|
105 | 105 | } else { |
106 | 106 | return array(); |
107 | 107 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | Base $controller |
128 | 128 | ) { |
129 | 129 | $mapping = $this->mapping(); |
130 | - if (isset($mapping[ $model->get_this_model_name() ]) |
|
131 | - && isset($mapping[ $model->get_this_model_name() ][ $field_name ]) |
|
130 | + if (isset($mapping[$model->get_this_model_name()]) |
|
131 | + && isset($mapping[$model->get_this_model_name()][$field_name]) |
|
132 | 132 | ) { |
133 | - $classname = $mapping[ $model->get_this_model_name() ][ $field_name ]; |
|
133 | + $classname = $mapping[$model->get_this_model_name()][$field_name]; |
|
134 | 134 | $class_method_name = EEH_Inflector::camelize_all_but_first($field_name); |
135 | 135 | return call_user_func(array($classname, $class_method_name), $wpdb_row, $rest_request, $controller); |
136 | 136 | } |
@@ -20,993 +20,993 @@ |
||
20 | 20 | class EE_Dependency_Map |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * This means that the requested class dependency is not present in the dependency map |
|
25 | - */ |
|
26 | - const not_registered = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | - */ |
|
31 | - const load_new_object = 1; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | - */ |
|
37 | - const load_from_cache = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * When registering a dependency, |
|
41 | - * this indicates to keep any existing dependencies that already exist, |
|
42 | - * and simply discard any new dependencies declared in the incoming data |
|
43 | - */ |
|
44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * When registering a dependency, |
|
48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | - */ |
|
50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = array(); |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function initialize() |
|
110 | - { |
|
111 | - $this->_register_core_dependencies(); |
|
112 | - $this->_register_core_class_loaders(); |
|
113 | - $this->_register_core_aliases(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param ClassInterfaceCache|null $class_cache |
|
120 | - * @return EE_Dependency_Map |
|
121 | - */ |
|
122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | - { |
|
124 | - // check if class object is instantiated, and instantiated properly |
|
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | - && $class_cache instanceof ClassInterfaceCache |
|
127 | - ) { |
|
128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | - } |
|
130 | - return self::$_instance; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RequestInterface $request |
|
136 | - */ |
|
137 | - public function setRequest(RequestInterface $request) |
|
138 | - { |
|
139 | - $this->request = $request; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param LegacyRequestInterface $legacy_request |
|
145 | - */ |
|
146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | - { |
|
148 | - $this->legacy_request = $legacy_request; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param ResponseInterface $response |
|
154 | - */ |
|
155 | - public function setResponse(ResponseInterface $response) |
|
156 | - { |
|
157 | - $this->response = $response; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param LoaderInterface $loader |
|
163 | - */ |
|
164 | - public function setLoader(LoaderInterface $loader) |
|
165 | - { |
|
166 | - $this->loader = $loader; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $class |
|
172 | - * @param array $dependencies |
|
173 | - * @param int $overwrite |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function register_dependencies( |
|
177 | - $class, |
|
178 | - array $dependencies, |
|
179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | - ) { |
|
181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | - * to the class specified by the first parameter. |
|
188 | - * IMPORTANT !!! |
|
189 | - * The order of elements in the incoming $dependencies array MUST match |
|
190 | - * the order of the constructor parameters for the class in question. |
|
191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | - * |
|
194 | - * @param string $class |
|
195 | - * @param array $dependencies |
|
196 | - * @param int $overwrite |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function registerDependencies( |
|
200 | - $class, |
|
201 | - array $dependencies, |
|
202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | - ) { |
|
204 | - $class = trim($class, '\\'); |
|
205 | - $registered = false; |
|
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | - } |
|
209 | - // we need to make sure that any aliases used when registering a dependency |
|
210 | - // get resolved to the correct class name |
|
211 | - foreach ($dependencies as $dependency => $load_source) { |
|
212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | - ) { |
|
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
218 | - $registered = true; |
|
219 | - } |
|
220 | - } |
|
221 | - // now add our two lists of dependencies together. |
|
222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | - // so $dependencies is NOT overwritten because it is listed first |
|
224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | - // Union is way faster than array_merge() but should be used with caution... |
|
226 | - // especially with numerically indexed arrays |
|
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | - // now we need to ensure that the resulting dependencies |
|
229 | - // array only has the entries that are required for the class |
|
230 | - // so first count how many dependencies were originally registered for the class |
|
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | - // then truncate the final array to match that count |
|
235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
236 | - // otherwise just take the incoming array because nothing previously existed |
|
237 | - : $dependencies; |
|
238 | - return $registered; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $class_name |
|
244 | - * @param string $loader |
|
245 | - * @return bool |
|
246 | - * @throws DomainException |
|
247 | - */ |
|
248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | - { |
|
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | - throw new DomainException( |
|
252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | - if (! is_callable($loader) |
|
257 | - && ( |
|
258 | - strpos($loader, 'load_') !== 0 |
|
259 | - || ! method_exists('EE_Registry', $loader) |
|
260 | - ) |
|
261 | - ) { |
|
262 | - throw new DomainException( |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $loader |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | - return true; |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function dependency_map() |
|
285 | - { |
|
286 | - return $this->_dependency_map; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | - * |
|
293 | - * @param string $class_name |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function has($class_name = '') |
|
297 | - { |
|
298 | - // all legacy models have the same dependencies |
|
299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
300 | - $class_name = 'LEGACY_MODELS'; |
|
301 | - } |
|
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | - ? true |
|
322 | - : false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | - * |
|
329 | - * @param string $class_name |
|
330 | - * @param string $dependency |
|
331 | - * @return int |
|
332 | - */ |
|
333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | - { |
|
335 | - // all legacy models have the same dependencies |
|
336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
337 | - $class_name = 'LEGACY_MODELS'; |
|
338 | - } |
|
339 | - $dependency = $this->getFqnForAlias($dependency); |
|
340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | - : EE_Dependency_Map::not_registered; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $class_name |
|
348 | - * @return string | Closure |
|
349 | - */ |
|
350 | - public function class_loader($class_name) |
|
351 | - { |
|
352 | - // all legacy models use load_model() |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - return 'load_model'; |
|
355 | - } |
|
356 | - $class_name = $this->getFqnForAlias($class_name); |
|
357 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * @return array |
|
363 | - */ |
|
364 | - public function class_loaders() |
|
365 | - { |
|
366 | - return $this->_class_loaders; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * adds an alias for a classname |
|
372 | - * |
|
373 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
374 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
375 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
376 | - */ |
|
377 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
378 | - { |
|
379 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
385 | - * WHY? |
|
386 | - * Because if a class is type hinting for a concretion, |
|
387 | - * then why would we need to find another class to supply it? |
|
388 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
389 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
390 | - * Don't go looking for some substitute. |
|
391 | - * Whereas if a class is type hinting for an interface... |
|
392 | - * then we need to find an actual class to use. |
|
393 | - * So the interface IS the alias for some other FQN, |
|
394 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
395 | - * represents some other class. |
|
396 | - * |
|
397 | - * @param string $fqn |
|
398 | - * @param string $for_class |
|
399 | - * @return bool |
|
400 | - */ |
|
401 | - public function isAlias($fqn = '', $for_class = '') |
|
402 | - { |
|
403 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
409 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
410 | - * for example: |
|
411 | - * if the following two entries were added to the _aliases array: |
|
412 | - * array( |
|
413 | - * 'interface_alias' => 'some\namespace\interface' |
|
414 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
415 | - * ) |
|
416 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
417 | - * to load an instance of 'some\namespace\classname' |
|
418 | - * |
|
419 | - * @param string $alias |
|
420 | - * @param string $for_class |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
424 | - { |
|
425 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | - * This is done by using the following class constants: |
|
433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | - */ |
|
436 | - protected function _register_core_dependencies() |
|
437 | - { |
|
438 | - $this->_dependency_map = array( |
|
439 | - 'EE_Request_Handler' => array( |
|
440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_System' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
446 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
447 | - ), |
|
448 | - 'EE_Session' => array( |
|
449 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
450 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
453 | - ), |
|
454 | - 'EE_Cart' => array( |
|
455 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
456 | - ), |
|
457 | - 'EE_Front_Controller' => array( |
|
458 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
461 | - ), |
|
462 | - 'EE_Messenger_Collection_Loader' => array( |
|
463 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | - ), |
|
465 | - 'EE_Message_Type_Collection_Loader' => array( |
|
466 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | - ), |
|
468 | - 'EE_Message_Resource_Manager' => array( |
|
469 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
471 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_Message_Factory' => array( |
|
474 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
475 | - ), |
|
476 | - 'EE_messages' => array( |
|
477 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
478 | - ), |
|
479 | - 'EE_Messages_Generator' => array( |
|
480 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
481 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
483 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_Messages_Processor' => array( |
|
486 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
487 | - ), |
|
488 | - 'EE_Messages_Queue' => array( |
|
489 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
490 | - ), |
|
491 | - 'EE_Messages_Template_Defaults' => array( |
|
492 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
493 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
494 | - ), |
|
495 | - 'EE_Message_To_Generate_From_Request' => array( |
|
496 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
497 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
500 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
503 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
504 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
505 | - ), |
|
506 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
507 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
508 | - ), |
|
509 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
510 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
511 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
514 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
517 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
520 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
523 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
526 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
529 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
530 | - ), |
|
531 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
532 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
535 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
538 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
539 | - ), |
|
540 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
541 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
542 | - ), |
|
543 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
544 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
545 | - ), |
|
546 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
547 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
550 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
551 | - ), |
|
552 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
553 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
554 | - ), |
|
555 | - 'EE_Data_Migration_Class_Base' => array( |
|
556 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
557 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
558 | - ), |
|
559 | - 'EE_DMS_Core_4_1_0' => array( |
|
560 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
561 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EE_DMS_Core_4_2_0' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | - ), |
|
567 | - 'EE_DMS_Core_4_3_0' => array( |
|
568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | - ), |
|
571 | - 'EE_DMS_Core_4_4_0' => array( |
|
572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EE_DMS_Core_4_5_0' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | - ), |
|
579 | - 'EE_DMS_Core_4_6_0' => array( |
|
580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EE_DMS_Core_4_7_0' => array( |
|
584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EE_DMS_Core_4_8_0' => array( |
|
588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | - ), |
|
591 | - 'EE_DMS_Core_4_9_0' => array( |
|
592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
596 | - array(), |
|
597 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
600 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
601 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
602 | - ), |
|
603 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
604 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
605 | - ), |
|
606 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
607 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
608 | - ), |
|
609 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
610 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
611 | - ), |
|
612 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
613 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
614 | - ), |
|
615 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
616 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
617 | - ), |
|
618 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
619 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
620 | - ), |
|
621 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
623 | - ), |
|
624 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
625 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
626 | - ), |
|
627 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
628 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
629 | - ), |
|
630 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
631 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
632 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
635 | - null, |
|
636 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
637 | - ), |
|
638 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
639 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
640 | - ), |
|
641 | - 'LEGACY_MODELS' => array( |
|
642 | - null, |
|
643 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
644 | - ), |
|
645 | - 'EE_Module_Request_Router' => array( |
|
646 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
647 | - ), |
|
648 | - 'EE_Registration_Processor' => array( |
|
649 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
650 | - ), |
|
651 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
652 | - null, |
|
653 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
654 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
655 | - ), |
|
656 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
657 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
658 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
659 | - ), |
|
660 | - 'EE_Admin_Transactions_List_Table' => array( |
|
661 | - null, |
|
662 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
663 | - ), |
|
664 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
665 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
666 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
667 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
668 | - ), |
|
669 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
670 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
671 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
674 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
675 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
676 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
677 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
678 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
680 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
681 | - ), |
|
682 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
683 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
684 | - ), |
|
685 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
686 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
687 | - ), |
|
688 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
689 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
690 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
691 | - ), |
|
692 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
693 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | - ), |
|
695 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
696 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
697 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
698 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
699 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
700 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
701 | - ), |
|
702 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
703 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
704 | - ), |
|
705 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
706 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
708 | - ), |
|
709 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
710 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
711 | - ), |
|
712 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
713 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
714 | - ), |
|
715 | - 'EE_CPT_Strategy' => array( |
|
716 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
717 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
718 | - ), |
|
719 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
720 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
721 | - ), |
|
722 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
723 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
724 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
725 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
726 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
727 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
728 | - ), |
|
729 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
730 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
731 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
732 | - ), |
|
733 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
734 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
735 | - ), |
|
736 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
737 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
739 | - ), |
|
740 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
741 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
742 | - ), |
|
743 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
744 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
745 | - ), |
|
746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
747 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
748 | - ), |
|
749 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | - ), |
|
752 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
753 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
754 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
755 | - ), |
|
756 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
757 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
758 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
759 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
760 | - ), |
|
761 | - 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array( |
|
762 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
763 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
764 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
765 | - ), |
|
766 | - 'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array( |
|
767 | - 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache, |
|
768 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => self::load_from_cache, |
|
769 | - ), |
|
770 | - ); |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * Registers how core classes are loaded. |
|
776 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
777 | - * 'EE_Request_Handler' => 'load_core' |
|
778 | - * 'EE_Messages_Queue' => 'load_lib' |
|
779 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
780 | - * or, if greater control is required, by providing a custom closure. For example: |
|
781 | - * 'Some_Class' => function () { |
|
782 | - * return new Some_Class(); |
|
783 | - * }, |
|
784 | - * This is required for instantiating dependencies |
|
785 | - * where an interface has been type hinted in a class constructor. For example: |
|
786 | - * 'Required_Interface' => function () { |
|
787 | - * return new A_Class_That_Implements_Required_Interface(); |
|
788 | - * }, |
|
789 | - */ |
|
790 | - protected function _register_core_class_loaders() |
|
791 | - { |
|
792 | - // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
793 | - // be used in a closure. |
|
794 | - $request = &$this->request; |
|
795 | - $response = &$this->response; |
|
796 | - $legacy_request = &$this->legacy_request; |
|
797 | - // $loader = &$this->loader; |
|
798 | - $this->_class_loaders = array( |
|
799 | - // load_core |
|
800 | - 'EE_Capabilities' => 'load_core', |
|
801 | - 'EE_Encryption' => 'load_core', |
|
802 | - 'EE_Front_Controller' => 'load_core', |
|
803 | - 'EE_Module_Request_Router' => 'load_core', |
|
804 | - 'EE_Registry' => 'load_core', |
|
805 | - 'EE_Request' => function () use (&$legacy_request) { |
|
806 | - return $legacy_request; |
|
807 | - }, |
|
808 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
809 | - return $request; |
|
810 | - }, |
|
811 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
812 | - return $response; |
|
813 | - }, |
|
814 | - 'EE_Base' => 'load_core', |
|
815 | - 'EE_Request_Handler' => 'load_core', |
|
816 | - 'EE_Session' => 'load_core', |
|
817 | - 'EE_Cron_Tasks' => 'load_core', |
|
818 | - 'EE_System' => 'load_core', |
|
819 | - 'EE_Maintenance_Mode' => 'load_core', |
|
820 | - 'EE_Register_CPTs' => 'load_core', |
|
821 | - 'EE_Admin' => 'load_core', |
|
822 | - 'EE_CPT_Strategy' => 'load_core', |
|
823 | - // load_lib |
|
824 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
825 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
826 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
827 | - 'EE_Messenger_Collection' => 'load_lib', |
|
828 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
829 | - 'EE_Messages_Processor' => 'load_lib', |
|
830 | - 'EE_Message_Repository' => 'load_lib', |
|
831 | - 'EE_Messages_Queue' => 'load_lib', |
|
832 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
833 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
834 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
835 | - 'EE_Messages_Generator' => function () { |
|
836 | - return EE_Registry::instance()->load_lib( |
|
837 | - 'Messages_Generator', |
|
838 | - array(), |
|
839 | - false, |
|
840 | - false |
|
841 | - ); |
|
842 | - }, |
|
843 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
844 | - return EE_Registry::instance()->load_lib( |
|
845 | - 'Messages_Template_Defaults', |
|
846 | - $arguments, |
|
847 | - false, |
|
848 | - false |
|
849 | - ); |
|
850 | - }, |
|
851 | - // load_helper |
|
852 | - 'EEH_Parse_Shortcodes' => function () { |
|
853 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
854 | - return new EEH_Parse_Shortcodes(); |
|
855 | - } |
|
856 | - return null; |
|
857 | - }, |
|
858 | - 'EE_Template_Config' => function () { |
|
859 | - return EE_Config::instance()->template_settings; |
|
860 | - }, |
|
861 | - 'EE_Currency_Config' => function () { |
|
862 | - return EE_Config::instance()->currency; |
|
863 | - }, |
|
864 | - 'EE_Registration_Config' => function () { |
|
865 | - return EE_Config::instance()->registration; |
|
866 | - }, |
|
867 | - 'EE_Core_Config' => function () { |
|
868 | - return EE_Config::instance()->core; |
|
869 | - }, |
|
870 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
871 | - return LoaderFactory::getLoader(); |
|
872 | - }, |
|
873 | - 'EE_Network_Config' => function () { |
|
874 | - return EE_Network_Config::instance(); |
|
875 | - }, |
|
876 | - 'EE_Config' => function () { |
|
877 | - return EE_Config::instance(); |
|
878 | - }, |
|
879 | - 'EventEspresso\core\domain\Domain' => function () { |
|
880 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
881 | - }, |
|
882 | - 'EE_Admin_Config' => function () { |
|
883 | - return EE_Config::instance()->admin; |
|
884 | - } |
|
885 | - ); |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * can be used for supplying alternate names for classes, |
|
891 | - * or for connecting interface names to instantiable classes |
|
892 | - */ |
|
893 | - protected function _register_core_aliases() |
|
894 | - { |
|
895 | - $aliases = array( |
|
896 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
897 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
898 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
899 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
900 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
901 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
902 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
903 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
904 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
905 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
906 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
907 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
908 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
909 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
910 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
911 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
912 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
913 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
914 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
915 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
916 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
917 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
918 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
919 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
920 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
921 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
922 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
923 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
924 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
925 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
926 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
927 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
928 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
929 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
930 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
931 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
932 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
933 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
934 | - ); |
|
935 | - foreach ($aliases as $alias => $fqn) { |
|
936 | - if (is_array($fqn)) { |
|
937 | - foreach ($fqn as $class => $for_class) { |
|
938 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
939 | - } |
|
940 | - continue; |
|
941 | - } |
|
942 | - $this->class_cache->addAlias($fqn, $alias); |
|
943 | - } |
|
944 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
945 | - $this->class_cache->addAlias( |
|
946 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
947 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
948 | - ); |
|
949 | - } |
|
950 | - } |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
955 | - * request Primarily used by unit tests. |
|
956 | - */ |
|
957 | - public function reset() |
|
958 | - { |
|
959 | - $this->_register_core_class_loaders(); |
|
960 | - $this->_register_core_dependencies(); |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - /** |
|
965 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
966 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
967 | - * WHY? |
|
968 | - * Because if a class is type hinting for a concretion, |
|
969 | - * then why would we need to find another class to supply it? |
|
970 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
971 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
972 | - * Don't go looking for some substitute. |
|
973 | - * Whereas if a class is type hinting for an interface... |
|
974 | - * then we need to find an actual class to use. |
|
975 | - * So the interface IS the alias for some other FQN, |
|
976 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
977 | - * represents some other class. |
|
978 | - * |
|
979 | - * @deprecated 4.9.62.p |
|
980 | - * @param string $fqn |
|
981 | - * @param string $for_class |
|
982 | - * @return bool |
|
983 | - */ |
|
984 | - public function has_alias($fqn = '', $for_class = '') |
|
985 | - { |
|
986 | - return $this->isAlias($fqn, $for_class); |
|
987 | - } |
|
988 | - |
|
989 | - |
|
990 | - /** |
|
991 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
992 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
993 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
994 | - * for example: |
|
995 | - * if the following two entries were added to the _aliases array: |
|
996 | - * array( |
|
997 | - * 'interface_alias' => 'some\namespace\interface' |
|
998 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
999 | - * ) |
|
1000 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1001 | - * to load an instance of 'some\namespace\classname' |
|
1002 | - * |
|
1003 | - * @deprecated 4.9.62.p |
|
1004 | - * @param string $alias |
|
1005 | - * @param string $for_class |
|
1006 | - * @return string |
|
1007 | - */ |
|
1008 | - public function get_alias($alias = '', $for_class = '') |
|
1009 | - { |
|
1010 | - return $this->getFqnForAlias($alias, $for_class); |
|
1011 | - } |
|
23 | + /** |
|
24 | + * This means that the requested class dependency is not present in the dependency map |
|
25 | + */ |
|
26 | + const not_registered = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | + */ |
|
31 | + const load_new_object = 1; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | + */ |
|
37 | + const load_from_cache = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * When registering a dependency, |
|
41 | + * this indicates to keep any existing dependencies that already exist, |
|
42 | + * and simply discard any new dependencies declared in the incoming data |
|
43 | + */ |
|
44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * When registering a dependency, |
|
48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | + */ |
|
50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = array(); |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function initialize() |
|
110 | + { |
|
111 | + $this->_register_core_dependencies(); |
|
112 | + $this->_register_core_class_loaders(); |
|
113 | + $this->_register_core_aliases(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param ClassInterfaceCache|null $class_cache |
|
120 | + * @return EE_Dependency_Map |
|
121 | + */ |
|
122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | + { |
|
124 | + // check if class object is instantiated, and instantiated properly |
|
125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | + && $class_cache instanceof ClassInterfaceCache |
|
127 | + ) { |
|
128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | + } |
|
130 | + return self::$_instance; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RequestInterface $request |
|
136 | + */ |
|
137 | + public function setRequest(RequestInterface $request) |
|
138 | + { |
|
139 | + $this->request = $request; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param LegacyRequestInterface $legacy_request |
|
145 | + */ |
|
146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | + { |
|
148 | + $this->legacy_request = $legacy_request; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param ResponseInterface $response |
|
154 | + */ |
|
155 | + public function setResponse(ResponseInterface $response) |
|
156 | + { |
|
157 | + $this->response = $response; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param LoaderInterface $loader |
|
163 | + */ |
|
164 | + public function setLoader(LoaderInterface $loader) |
|
165 | + { |
|
166 | + $this->loader = $loader; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $class |
|
172 | + * @param array $dependencies |
|
173 | + * @param int $overwrite |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function register_dependencies( |
|
177 | + $class, |
|
178 | + array $dependencies, |
|
179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | + ) { |
|
181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | + * to the class specified by the first parameter. |
|
188 | + * IMPORTANT !!! |
|
189 | + * The order of elements in the incoming $dependencies array MUST match |
|
190 | + * the order of the constructor parameters for the class in question. |
|
191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | + * |
|
194 | + * @param string $class |
|
195 | + * @param array $dependencies |
|
196 | + * @param int $overwrite |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function registerDependencies( |
|
200 | + $class, |
|
201 | + array $dependencies, |
|
202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | + ) { |
|
204 | + $class = trim($class, '\\'); |
|
205 | + $registered = false; |
|
206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | + } |
|
209 | + // we need to make sure that any aliases used when registering a dependency |
|
210 | + // get resolved to the correct class name |
|
211 | + foreach ($dependencies as $dependency => $load_source) { |
|
212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | + ) { |
|
216 | + unset($dependencies[ $dependency ]); |
|
217 | + $dependencies[ $alias ] = $load_source; |
|
218 | + $registered = true; |
|
219 | + } |
|
220 | + } |
|
221 | + // now add our two lists of dependencies together. |
|
222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | + // so $dependencies is NOT overwritten because it is listed first |
|
224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | + // Union is way faster than array_merge() but should be used with caution... |
|
226 | + // especially with numerically indexed arrays |
|
227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | + // now we need to ensure that the resulting dependencies |
|
229 | + // array only has the entries that are required for the class |
|
230 | + // so first count how many dependencies were originally registered for the class |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | + // then truncate the final array to match that count |
|
235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
236 | + // otherwise just take the incoming array because nothing previously existed |
|
237 | + : $dependencies; |
|
238 | + return $registered; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $class_name |
|
244 | + * @param string $loader |
|
245 | + * @return bool |
|
246 | + * @throws DomainException |
|
247 | + */ |
|
248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | + { |
|
250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | + throw new DomainException( |
|
252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | + if (! is_callable($loader) |
|
257 | + && ( |
|
258 | + strpos($loader, 'load_') !== 0 |
|
259 | + || ! method_exists('EE_Registry', $loader) |
|
260 | + ) |
|
261 | + ) { |
|
262 | + throw new DomainException( |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $loader |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | + return true; |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function dependency_map() |
|
285 | + { |
|
286 | + return $this->_dependency_map; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | + * |
|
293 | + * @param string $class_name |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function has($class_name = '') |
|
297 | + { |
|
298 | + // all legacy models have the same dependencies |
|
299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
300 | + $class_name = 'LEGACY_MODELS'; |
|
301 | + } |
|
302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | + ? true |
|
322 | + : false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | + * |
|
329 | + * @param string $class_name |
|
330 | + * @param string $dependency |
|
331 | + * @return int |
|
332 | + */ |
|
333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | + { |
|
335 | + // all legacy models have the same dependencies |
|
336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
337 | + $class_name = 'LEGACY_MODELS'; |
|
338 | + } |
|
339 | + $dependency = $this->getFqnForAlias($dependency); |
|
340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | + : EE_Dependency_Map::not_registered; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $class_name |
|
348 | + * @return string | Closure |
|
349 | + */ |
|
350 | + public function class_loader($class_name) |
|
351 | + { |
|
352 | + // all legacy models use load_model() |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + return 'load_model'; |
|
355 | + } |
|
356 | + $class_name = $this->getFqnForAlias($class_name); |
|
357 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * @return array |
|
363 | + */ |
|
364 | + public function class_loaders() |
|
365 | + { |
|
366 | + return $this->_class_loaders; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * adds an alias for a classname |
|
372 | + * |
|
373 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
374 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
375 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
376 | + */ |
|
377 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
378 | + { |
|
379 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
385 | + * WHY? |
|
386 | + * Because if a class is type hinting for a concretion, |
|
387 | + * then why would we need to find another class to supply it? |
|
388 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
389 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
390 | + * Don't go looking for some substitute. |
|
391 | + * Whereas if a class is type hinting for an interface... |
|
392 | + * then we need to find an actual class to use. |
|
393 | + * So the interface IS the alias for some other FQN, |
|
394 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
395 | + * represents some other class. |
|
396 | + * |
|
397 | + * @param string $fqn |
|
398 | + * @param string $for_class |
|
399 | + * @return bool |
|
400 | + */ |
|
401 | + public function isAlias($fqn = '', $for_class = '') |
|
402 | + { |
|
403 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
409 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
410 | + * for example: |
|
411 | + * if the following two entries were added to the _aliases array: |
|
412 | + * array( |
|
413 | + * 'interface_alias' => 'some\namespace\interface' |
|
414 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
415 | + * ) |
|
416 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
417 | + * to load an instance of 'some\namespace\classname' |
|
418 | + * |
|
419 | + * @param string $alias |
|
420 | + * @param string $for_class |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
424 | + { |
|
425 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | + * This is done by using the following class constants: |
|
433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | + */ |
|
436 | + protected function _register_core_dependencies() |
|
437 | + { |
|
438 | + $this->_dependency_map = array( |
|
439 | + 'EE_Request_Handler' => array( |
|
440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_System' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
446 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
447 | + ), |
|
448 | + 'EE_Session' => array( |
|
449 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
450 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
453 | + ), |
|
454 | + 'EE_Cart' => array( |
|
455 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
456 | + ), |
|
457 | + 'EE_Front_Controller' => array( |
|
458 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
461 | + ), |
|
462 | + 'EE_Messenger_Collection_Loader' => array( |
|
463 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | + ), |
|
465 | + 'EE_Message_Type_Collection_Loader' => array( |
|
466 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | + ), |
|
468 | + 'EE_Message_Resource_Manager' => array( |
|
469 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
471 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_Message_Factory' => array( |
|
474 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
475 | + ), |
|
476 | + 'EE_messages' => array( |
|
477 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
478 | + ), |
|
479 | + 'EE_Messages_Generator' => array( |
|
480 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
481 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
483 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_Messages_Processor' => array( |
|
486 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
487 | + ), |
|
488 | + 'EE_Messages_Queue' => array( |
|
489 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
490 | + ), |
|
491 | + 'EE_Messages_Template_Defaults' => array( |
|
492 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
493 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
494 | + ), |
|
495 | + 'EE_Message_To_Generate_From_Request' => array( |
|
496 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
497 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
500 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
503 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
504 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
505 | + ), |
|
506 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
507 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
508 | + ), |
|
509 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
510 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
511 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
514 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
517 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
520 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
523 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
526 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
529 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
530 | + ), |
|
531 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
532 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
535 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
538 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
539 | + ), |
|
540 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
541 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
542 | + ), |
|
543 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
544 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
545 | + ), |
|
546 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
547 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
550 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
551 | + ), |
|
552 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
553 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
554 | + ), |
|
555 | + 'EE_Data_Migration_Class_Base' => array( |
|
556 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
557 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
558 | + ), |
|
559 | + 'EE_DMS_Core_4_1_0' => array( |
|
560 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
561 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EE_DMS_Core_4_2_0' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | + ), |
|
567 | + 'EE_DMS_Core_4_3_0' => array( |
|
568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | + ), |
|
571 | + 'EE_DMS_Core_4_4_0' => array( |
|
572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EE_DMS_Core_4_5_0' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | + ), |
|
579 | + 'EE_DMS_Core_4_6_0' => array( |
|
580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EE_DMS_Core_4_7_0' => array( |
|
584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EE_DMS_Core_4_8_0' => array( |
|
588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | + ), |
|
591 | + 'EE_DMS_Core_4_9_0' => array( |
|
592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
596 | + array(), |
|
597 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
600 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
601 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
602 | + ), |
|
603 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
604 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
605 | + ), |
|
606 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
607 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
608 | + ), |
|
609 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
610 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
611 | + ), |
|
612 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
613 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
614 | + ), |
|
615 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
616 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
617 | + ), |
|
618 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
619 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
620 | + ), |
|
621 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
623 | + ), |
|
624 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
625 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
626 | + ), |
|
627 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
628 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
629 | + ), |
|
630 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
631 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
632 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
635 | + null, |
|
636 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
637 | + ), |
|
638 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
639 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
640 | + ), |
|
641 | + 'LEGACY_MODELS' => array( |
|
642 | + null, |
|
643 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
644 | + ), |
|
645 | + 'EE_Module_Request_Router' => array( |
|
646 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
647 | + ), |
|
648 | + 'EE_Registration_Processor' => array( |
|
649 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
650 | + ), |
|
651 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
652 | + null, |
|
653 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
654 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
655 | + ), |
|
656 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
657 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
658 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
659 | + ), |
|
660 | + 'EE_Admin_Transactions_List_Table' => array( |
|
661 | + null, |
|
662 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
663 | + ), |
|
664 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
665 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
666 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
667 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
668 | + ), |
|
669 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
670 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
671 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
674 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
675 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
676 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
677 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
678 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
680 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
681 | + ), |
|
682 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
683 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
684 | + ), |
|
685 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
686 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
687 | + ), |
|
688 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
689 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
690 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
691 | + ), |
|
692 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
693 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | + ), |
|
695 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
696 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
697 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
698 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
699 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
700 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
701 | + ), |
|
702 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
703 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
704 | + ), |
|
705 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
706 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
708 | + ), |
|
709 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
710 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
711 | + ), |
|
712 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
713 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
714 | + ), |
|
715 | + 'EE_CPT_Strategy' => array( |
|
716 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
717 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
718 | + ), |
|
719 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
720 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
721 | + ), |
|
722 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
723 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
724 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
725 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
726 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
727 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
728 | + ), |
|
729 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
730 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
731 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
732 | + ), |
|
733 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
734 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
735 | + ), |
|
736 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
737 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
739 | + ), |
|
740 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
741 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
742 | + ), |
|
743 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
744 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
745 | + ), |
|
746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
747 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
748 | + ), |
|
749 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | + ), |
|
752 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
753 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
754 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
755 | + ), |
|
756 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
757 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
758 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
759 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
760 | + ), |
|
761 | + 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array( |
|
762 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
763 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
764 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
765 | + ), |
|
766 | + 'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array( |
|
767 | + 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache, |
|
768 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => self::load_from_cache, |
|
769 | + ), |
|
770 | + ); |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * Registers how core classes are loaded. |
|
776 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
777 | + * 'EE_Request_Handler' => 'load_core' |
|
778 | + * 'EE_Messages_Queue' => 'load_lib' |
|
779 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
780 | + * or, if greater control is required, by providing a custom closure. For example: |
|
781 | + * 'Some_Class' => function () { |
|
782 | + * return new Some_Class(); |
|
783 | + * }, |
|
784 | + * This is required for instantiating dependencies |
|
785 | + * where an interface has been type hinted in a class constructor. For example: |
|
786 | + * 'Required_Interface' => function () { |
|
787 | + * return new A_Class_That_Implements_Required_Interface(); |
|
788 | + * }, |
|
789 | + */ |
|
790 | + protected function _register_core_class_loaders() |
|
791 | + { |
|
792 | + // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
793 | + // be used in a closure. |
|
794 | + $request = &$this->request; |
|
795 | + $response = &$this->response; |
|
796 | + $legacy_request = &$this->legacy_request; |
|
797 | + // $loader = &$this->loader; |
|
798 | + $this->_class_loaders = array( |
|
799 | + // load_core |
|
800 | + 'EE_Capabilities' => 'load_core', |
|
801 | + 'EE_Encryption' => 'load_core', |
|
802 | + 'EE_Front_Controller' => 'load_core', |
|
803 | + 'EE_Module_Request_Router' => 'load_core', |
|
804 | + 'EE_Registry' => 'load_core', |
|
805 | + 'EE_Request' => function () use (&$legacy_request) { |
|
806 | + return $legacy_request; |
|
807 | + }, |
|
808 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
809 | + return $request; |
|
810 | + }, |
|
811 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
812 | + return $response; |
|
813 | + }, |
|
814 | + 'EE_Base' => 'load_core', |
|
815 | + 'EE_Request_Handler' => 'load_core', |
|
816 | + 'EE_Session' => 'load_core', |
|
817 | + 'EE_Cron_Tasks' => 'load_core', |
|
818 | + 'EE_System' => 'load_core', |
|
819 | + 'EE_Maintenance_Mode' => 'load_core', |
|
820 | + 'EE_Register_CPTs' => 'load_core', |
|
821 | + 'EE_Admin' => 'load_core', |
|
822 | + 'EE_CPT_Strategy' => 'load_core', |
|
823 | + // load_lib |
|
824 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
825 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
826 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
827 | + 'EE_Messenger_Collection' => 'load_lib', |
|
828 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
829 | + 'EE_Messages_Processor' => 'load_lib', |
|
830 | + 'EE_Message_Repository' => 'load_lib', |
|
831 | + 'EE_Messages_Queue' => 'load_lib', |
|
832 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
833 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
834 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
835 | + 'EE_Messages_Generator' => function () { |
|
836 | + return EE_Registry::instance()->load_lib( |
|
837 | + 'Messages_Generator', |
|
838 | + array(), |
|
839 | + false, |
|
840 | + false |
|
841 | + ); |
|
842 | + }, |
|
843 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
844 | + return EE_Registry::instance()->load_lib( |
|
845 | + 'Messages_Template_Defaults', |
|
846 | + $arguments, |
|
847 | + false, |
|
848 | + false |
|
849 | + ); |
|
850 | + }, |
|
851 | + // load_helper |
|
852 | + 'EEH_Parse_Shortcodes' => function () { |
|
853 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
854 | + return new EEH_Parse_Shortcodes(); |
|
855 | + } |
|
856 | + return null; |
|
857 | + }, |
|
858 | + 'EE_Template_Config' => function () { |
|
859 | + return EE_Config::instance()->template_settings; |
|
860 | + }, |
|
861 | + 'EE_Currency_Config' => function () { |
|
862 | + return EE_Config::instance()->currency; |
|
863 | + }, |
|
864 | + 'EE_Registration_Config' => function () { |
|
865 | + return EE_Config::instance()->registration; |
|
866 | + }, |
|
867 | + 'EE_Core_Config' => function () { |
|
868 | + return EE_Config::instance()->core; |
|
869 | + }, |
|
870 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
871 | + return LoaderFactory::getLoader(); |
|
872 | + }, |
|
873 | + 'EE_Network_Config' => function () { |
|
874 | + return EE_Network_Config::instance(); |
|
875 | + }, |
|
876 | + 'EE_Config' => function () { |
|
877 | + return EE_Config::instance(); |
|
878 | + }, |
|
879 | + 'EventEspresso\core\domain\Domain' => function () { |
|
880 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
881 | + }, |
|
882 | + 'EE_Admin_Config' => function () { |
|
883 | + return EE_Config::instance()->admin; |
|
884 | + } |
|
885 | + ); |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * can be used for supplying alternate names for classes, |
|
891 | + * or for connecting interface names to instantiable classes |
|
892 | + */ |
|
893 | + protected function _register_core_aliases() |
|
894 | + { |
|
895 | + $aliases = array( |
|
896 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
897 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
898 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
899 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
900 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
901 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
902 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
903 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
904 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
905 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
906 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
907 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
908 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
909 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
910 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
911 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
912 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
913 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
914 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
915 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
916 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
917 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
918 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
919 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
920 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
921 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
922 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
923 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
924 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
925 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
926 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
927 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
928 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
929 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
930 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
931 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
932 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
933 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
934 | + ); |
|
935 | + foreach ($aliases as $alias => $fqn) { |
|
936 | + if (is_array($fqn)) { |
|
937 | + foreach ($fqn as $class => $for_class) { |
|
938 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
939 | + } |
|
940 | + continue; |
|
941 | + } |
|
942 | + $this->class_cache->addAlias($fqn, $alias); |
|
943 | + } |
|
944 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
945 | + $this->class_cache->addAlias( |
|
946 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
947 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
948 | + ); |
|
949 | + } |
|
950 | + } |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
955 | + * request Primarily used by unit tests. |
|
956 | + */ |
|
957 | + public function reset() |
|
958 | + { |
|
959 | + $this->_register_core_class_loaders(); |
|
960 | + $this->_register_core_dependencies(); |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + /** |
|
965 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
966 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
967 | + * WHY? |
|
968 | + * Because if a class is type hinting for a concretion, |
|
969 | + * then why would we need to find another class to supply it? |
|
970 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
971 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
972 | + * Don't go looking for some substitute. |
|
973 | + * Whereas if a class is type hinting for an interface... |
|
974 | + * then we need to find an actual class to use. |
|
975 | + * So the interface IS the alias for some other FQN, |
|
976 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
977 | + * represents some other class. |
|
978 | + * |
|
979 | + * @deprecated 4.9.62.p |
|
980 | + * @param string $fqn |
|
981 | + * @param string $for_class |
|
982 | + * @return bool |
|
983 | + */ |
|
984 | + public function has_alias($fqn = '', $for_class = '') |
|
985 | + { |
|
986 | + return $this->isAlias($fqn, $for_class); |
|
987 | + } |
|
988 | + |
|
989 | + |
|
990 | + /** |
|
991 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
992 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
993 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
994 | + * for example: |
|
995 | + * if the following two entries were added to the _aliases array: |
|
996 | + * array( |
|
997 | + * 'interface_alias' => 'some\namespace\interface' |
|
998 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
999 | + * ) |
|
1000 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1001 | + * to load an instance of 'some\namespace\classname' |
|
1002 | + * |
|
1003 | + * @deprecated 4.9.62.p |
|
1004 | + * @param string $alias |
|
1005 | + * @param string $for_class |
|
1006 | + * @return string |
|
1007 | + */ |
|
1008 | + public function get_alias($alias = '', $for_class = '') |
|
1009 | + { |
|
1010 | + return $this->getFqnForAlias($alias, $for_class); |
|
1011 | + } |
|
1012 | 1012 | } |
@@ -23,561 +23,561 @@ |
||
23 | 23 | class Registry |
24 | 24 | { |
25 | 25 | |
26 | - const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var AssetCollection $assets |
|
30 | - */ |
|
31 | - protected $assets; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var I18nRegistry |
|
35 | - */ |
|
36 | - private $i18n_registry; |
|
37 | - |
|
38 | - /** |
|
39 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $jsdata = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | - * page source. |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - private $script_handles_with_data = array(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Holds the manifest data obtained from registered manifest files. |
|
56 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
57 | - * Shape of this array is: |
|
58 | - * array( |
|
59 | - * 'some_namespace_slug' => array( |
|
60 | - * 'some_chunk_name' => array( |
|
61 | - * 'js' => 'filename.js' |
|
62 | - * 'css' => 'filename.js' |
|
63 | - * ), |
|
64 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
65 | - * ) |
|
66 | - * ) |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - private $manifest_data = array(); |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Registry constructor. |
|
75 | - * Hooking into WP actions for script registry. |
|
76 | - * |
|
77 | - * @param AssetCollection $assets |
|
78 | - * @param I18nRegistry $i18n_registry |
|
79 | - */ |
|
80 | - public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
81 | - { |
|
82 | - $this->assets = $assets; |
|
83 | - $this->i18n_registry = $i18n_registry; |
|
84 | - add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | - add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
86 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
88 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
90 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
97 | - * translation handling. |
|
98 | - * |
|
99 | - * @return I18nRegistry |
|
100 | - */ |
|
101 | - public function getI18nRegistry() |
|
102 | - { |
|
103 | - return $this->i18n_registry; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
109 | - * |
|
110 | - * @since 4.9.62.p |
|
111 | - * @throws Exception |
|
112 | - */ |
|
113 | - public function registerScriptsAndStyles() |
|
114 | - { |
|
115 | - try { |
|
116 | - $this->registerScripts($this->assets->getJavascriptAssets()); |
|
117 | - $this->registerStyles($this->assets->getStylesheetAssets()); |
|
118 | - } catch (Exception $exception) { |
|
119 | - new ExceptionStackTraceDisplay($exception); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Registers JS assets with WP core |
|
126 | - * |
|
127 | - * @since 4.9.62.p |
|
128 | - * @param JavascriptAsset[] $scripts |
|
129 | - * @throws AssetRegistrationException |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - */ |
|
132 | - public function registerScripts(array $scripts) |
|
133 | - { |
|
134 | - foreach ($scripts as $script) { |
|
135 | - // skip to next script if this has already been done |
|
136 | - if ($script->isRegistered()) { |
|
137 | - continue; |
|
138 | - } |
|
139 | - do_action( |
|
140 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
141 | - $script |
|
142 | - ); |
|
143 | - $registered = wp_register_script( |
|
144 | - $script->handle(), |
|
145 | - $script->source(), |
|
146 | - $script->dependencies(), |
|
147 | - $script->version(), |
|
148 | - $script->loadInFooter() |
|
149 | - ); |
|
150 | - if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
151 | - throw new AssetRegistrationException($script->handle()); |
|
152 | - } |
|
153 | - $script->setRegistered($registered); |
|
154 | - if ($script->requiresTranslation()) { |
|
155 | - $this->registerTranslation($script->handle()); |
|
156 | - } |
|
157 | - do_action( |
|
158 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
159 | - $script |
|
160 | - ); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Registers CSS assets with WP core |
|
167 | - * |
|
168 | - * @since 4.9.62.p |
|
169 | - * @param StylesheetAsset[] $styles |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - */ |
|
172 | - public function registerStyles(array $styles) |
|
173 | - { |
|
174 | - foreach ($styles as $style) { |
|
175 | - // skip to next style if this has already been done |
|
176 | - if ($style->isRegistered()) { |
|
177 | - continue; |
|
178 | - } |
|
179 | - do_action( |
|
180 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
181 | - $style |
|
182 | - ); |
|
183 | - wp_register_style( |
|
184 | - $style->handle(), |
|
185 | - $style->source(), |
|
186 | - $style->dependencies(), |
|
187 | - $style->version(), |
|
188 | - $style->media() |
|
189 | - ); |
|
190 | - $style->setRegistered(); |
|
191 | - do_action( |
|
192 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
193 | - $style |
|
194 | - ); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Call back for the script print in frontend and backend. |
|
201 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
202 | - * |
|
203 | - * @since 4.9.31.rc.015 |
|
204 | - */ |
|
205 | - public function enqueueData() |
|
206 | - { |
|
207 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
208 | - wp_add_inline_script( |
|
209 | - 'eejs-core', |
|
210 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
211 | - 'before' |
|
212 | - ); |
|
213 | - $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
214 | - foreach ($scripts as $script) { |
|
215 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
216 | - if ($script->hasInlineDataCallback()) { |
|
217 | - $localize = $script->inlineDataCallback(); |
|
218 | - $localize(); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * Used to add data to eejs.data object. |
|
226 | - * Note: Overriding existing data is not allowed. |
|
227 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
228 | - * If the data you add is something like this: |
|
229 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
230 | - * It will be exposed in the page source as: |
|
231 | - * eejs.data.my_plugin_data.foo == gar |
|
232 | - * |
|
233 | - * @param string $key Key used to access your data |
|
234 | - * @param string|array $value Value to attach to key |
|
235 | - * @throws InvalidArgumentException |
|
236 | - */ |
|
237 | - public function addData($key, $value) |
|
238 | - { |
|
239 | - if ($this->verifyDataNotExisting($key)) { |
|
240 | - $this->jsdata[ $key ] = $value; |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
247 | - * elements in an array. |
|
248 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
249 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
250 | - * object like this, eejs.data.test = [ my_data, |
|
251 | - * ] |
|
252 | - * If there has already been a scalar value attached to the data object given key, then |
|
253 | - * this will throw an exception. |
|
254 | - * |
|
255 | - * @param string $key Key to attach data to. |
|
256 | - * @param string|array $value Value being registered. |
|
257 | - * @throws InvalidArgumentException |
|
258 | - */ |
|
259 | - public function pushData($key, $value) |
|
260 | - { |
|
261 | - if (isset($this->jsdata[ $key ]) |
|
262 | - && ! is_array($this->jsdata[ $key ]) |
|
263 | - ) { |
|
264 | - throw new InvalidArgumentException( |
|
265 | - sprintf( |
|
266 | - __( |
|
267 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
26 | + const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var AssetCollection $assets |
|
30 | + */ |
|
31 | + protected $assets; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var I18nRegistry |
|
35 | + */ |
|
36 | + private $i18n_registry; |
|
37 | + |
|
38 | + /** |
|
39 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $jsdata = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | + * page source. |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + private $script_handles_with_data = array(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Holds the manifest data obtained from registered manifest files. |
|
56 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
57 | + * Shape of this array is: |
|
58 | + * array( |
|
59 | + * 'some_namespace_slug' => array( |
|
60 | + * 'some_chunk_name' => array( |
|
61 | + * 'js' => 'filename.js' |
|
62 | + * 'css' => 'filename.js' |
|
63 | + * ), |
|
64 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
65 | + * ) |
|
66 | + * ) |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + private $manifest_data = array(); |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Registry constructor. |
|
75 | + * Hooking into WP actions for script registry. |
|
76 | + * |
|
77 | + * @param AssetCollection $assets |
|
78 | + * @param I18nRegistry $i18n_registry |
|
79 | + */ |
|
80 | + public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
81 | + { |
|
82 | + $this->assets = $assets; |
|
83 | + $this->i18n_registry = $i18n_registry; |
|
84 | + add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | + add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
88 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
90 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
97 | + * translation handling. |
|
98 | + * |
|
99 | + * @return I18nRegistry |
|
100 | + */ |
|
101 | + public function getI18nRegistry() |
|
102 | + { |
|
103 | + return $this->i18n_registry; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
109 | + * |
|
110 | + * @since 4.9.62.p |
|
111 | + * @throws Exception |
|
112 | + */ |
|
113 | + public function registerScriptsAndStyles() |
|
114 | + { |
|
115 | + try { |
|
116 | + $this->registerScripts($this->assets->getJavascriptAssets()); |
|
117 | + $this->registerStyles($this->assets->getStylesheetAssets()); |
|
118 | + } catch (Exception $exception) { |
|
119 | + new ExceptionStackTraceDisplay($exception); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Registers JS assets with WP core |
|
126 | + * |
|
127 | + * @since 4.9.62.p |
|
128 | + * @param JavascriptAsset[] $scripts |
|
129 | + * @throws AssetRegistrationException |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + */ |
|
132 | + public function registerScripts(array $scripts) |
|
133 | + { |
|
134 | + foreach ($scripts as $script) { |
|
135 | + // skip to next script if this has already been done |
|
136 | + if ($script->isRegistered()) { |
|
137 | + continue; |
|
138 | + } |
|
139 | + do_action( |
|
140 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
141 | + $script |
|
142 | + ); |
|
143 | + $registered = wp_register_script( |
|
144 | + $script->handle(), |
|
145 | + $script->source(), |
|
146 | + $script->dependencies(), |
|
147 | + $script->version(), |
|
148 | + $script->loadInFooter() |
|
149 | + ); |
|
150 | + if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
151 | + throw new AssetRegistrationException($script->handle()); |
|
152 | + } |
|
153 | + $script->setRegistered($registered); |
|
154 | + if ($script->requiresTranslation()) { |
|
155 | + $this->registerTranslation($script->handle()); |
|
156 | + } |
|
157 | + do_action( |
|
158 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
159 | + $script |
|
160 | + ); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Registers CSS assets with WP core |
|
167 | + * |
|
168 | + * @since 4.9.62.p |
|
169 | + * @param StylesheetAsset[] $styles |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + */ |
|
172 | + public function registerStyles(array $styles) |
|
173 | + { |
|
174 | + foreach ($styles as $style) { |
|
175 | + // skip to next style if this has already been done |
|
176 | + if ($style->isRegistered()) { |
|
177 | + continue; |
|
178 | + } |
|
179 | + do_action( |
|
180 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
181 | + $style |
|
182 | + ); |
|
183 | + wp_register_style( |
|
184 | + $style->handle(), |
|
185 | + $style->source(), |
|
186 | + $style->dependencies(), |
|
187 | + $style->version(), |
|
188 | + $style->media() |
|
189 | + ); |
|
190 | + $style->setRegistered(); |
|
191 | + do_action( |
|
192 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
193 | + $style |
|
194 | + ); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Call back for the script print in frontend and backend. |
|
201 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
202 | + * |
|
203 | + * @since 4.9.31.rc.015 |
|
204 | + */ |
|
205 | + public function enqueueData() |
|
206 | + { |
|
207 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
208 | + wp_add_inline_script( |
|
209 | + 'eejs-core', |
|
210 | + 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
211 | + 'before' |
|
212 | + ); |
|
213 | + $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
214 | + foreach ($scripts as $script) { |
|
215 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
216 | + if ($script->hasInlineDataCallback()) { |
|
217 | + $localize = $script->inlineDataCallback(); |
|
218 | + $localize(); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * Used to add data to eejs.data object. |
|
226 | + * Note: Overriding existing data is not allowed. |
|
227 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
228 | + * If the data you add is something like this: |
|
229 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
230 | + * It will be exposed in the page source as: |
|
231 | + * eejs.data.my_plugin_data.foo == gar |
|
232 | + * |
|
233 | + * @param string $key Key used to access your data |
|
234 | + * @param string|array $value Value to attach to key |
|
235 | + * @throws InvalidArgumentException |
|
236 | + */ |
|
237 | + public function addData($key, $value) |
|
238 | + { |
|
239 | + if ($this->verifyDataNotExisting($key)) { |
|
240 | + $this->jsdata[ $key ] = $value; |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
247 | + * elements in an array. |
|
248 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
249 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
250 | + * object like this, eejs.data.test = [ my_data, |
|
251 | + * ] |
|
252 | + * If there has already been a scalar value attached to the data object given key, then |
|
253 | + * this will throw an exception. |
|
254 | + * |
|
255 | + * @param string $key Key to attach data to. |
|
256 | + * @param string|array $value Value being registered. |
|
257 | + * @throws InvalidArgumentException |
|
258 | + */ |
|
259 | + public function pushData($key, $value) |
|
260 | + { |
|
261 | + if (isset($this->jsdata[ $key ]) |
|
262 | + && ! is_array($this->jsdata[ $key ]) |
|
263 | + ) { |
|
264 | + throw new InvalidArgumentException( |
|
265 | + sprintf( |
|
266 | + __( |
|
267 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
268 | 268 | push values to this data element when it is an array.', |
269 | - 'event_espresso' |
|
270 | - ), |
|
271 | - $key, |
|
272 | - __METHOD__ |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - $this->jsdata[ $key ][] = $value; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Used to set content used by javascript for a template. |
|
282 | - * Note: Overrides of existing registered templates are not allowed. |
|
283 | - * |
|
284 | - * @param string $template_reference |
|
285 | - * @param string $template_content |
|
286 | - * @throws InvalidArgumentException |
|
287 | - */ |
|
288 | - public function addTemplate($template_reference, $template_content) |
|
289 | - { |
|
290 | - if (! isset($this->jsdata['templates'])) { |
|
291 | - $this->jsdata['templates'] = array(); |
|
292 | - } |
|
293 | - //no overrides allowed. |
|
294 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
295 | - throw new InvalidArgumentException( |
|
296 | - sprintf( |
|
297 | - __( |
|
298 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - $template_reference |
|
302 | - ) |
|
303 | - ); |
|
304 | - } |
|
305 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Retrieve the template content already registered for the given reference. |
|
311 | - * |
|
312 | - * @param string $template_reference |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function getTemplate($template_reference) |
|
316 | - { |
|
317 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
318 | - ? $this->jsdata['templates'][ $template_reference ] |
|
319 | - : ''; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * Retrieve registered data. |
|
325 | - * |
|
326 | - * @param string $key Name of key to attach data to. |
|
327 | - * @return mixed If there is no for the given key, then false is returned. |
|
328 | - */ |
|
329 | - public function getData($key) |
|
330 | - { |
|
331 | - return isset($this->jsdata[ $key ]) |
|
332 | - ? $this->jsdata[ $key ] |
|
333 | - : false; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Verifies whether the given data exists already on the jsdata array. |
|
339 | - * Overriding data is not allowed. |
|
340 | - * |
|
341 | - * @param string $key Index for data. |
|
342 | - * @return bool If valid then return true. |
|
343 | - * @throws InvalidArgumentException if data already exists. |
|
344 | - */ |
|
345 | - protected function verifyDataNotExisting($key) |
|
346 | - { |
|
347 | - if (isset($this->jsdata[ $key ])) { |
|
348 | - if (is_array($this->jsdata[ $key ])) { |
|
349 | - throw new InvalidArgumentException( |
|
350 | - sprintf( |
|
351 | - __( |
|
352 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
269 | + 'event_espresso' |
|
270 | + ), |
|
271 | + $key, |
|
272 | + __METHOD__ |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + $this->jsdata[ $key ][] = $value; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Used to set content used by javascript for a template. |
|
282 | + * Note: Overrides of existing registered templates are not allowed. |
|
283 | + * |
|
284 | + * @param string $template_reference |
|
285 | + * @param string $template_content |
|
286 | + * @throws InvalidArgumentException |
|
287 | + */ |
|
288 | + public function addTemplate($template_reference, $template_content) |
|
289 | + { |
|
290 | + if (! isset($this->jsdata['templates'])) { |
|
291 | + $this->jsdata['templates'] = array(); |
|
292 | + } |
|
293 | + //no overrides allowed. |
|
294 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
295 | + throw new InvalidArgumentException( |
|
296 | + sprintf( |
|
297 | + __( |
|
298 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + $template_reference |
|
302 | + ) |
|
303 | + ); |
|
304 | + } |
|
305 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Retrieve the template content already registered for the given reference. |
|
311 | + * |
|
312 | + * @param string $template_reference |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function getTemplate($template_reference) |
|
316 | + { |
|
317 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
318 | + ? $this->jsdata['templates'][ $template_reference ] |
|
319 | + : ''; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * Retrieve registered data. |
|
325 | + * |
|
326 | + * @param string $key Name of key to attach data to. |
|
327 | + * @return mixed If there is no for the given key, then false is returned. |
|
328 | + */ |
|
329 | + public function getData($key) |
|
330 | + { |
|
331 | + return isset($this->jsdata[ $key ]) |
|
332 | + ? $this->jsdata[ $key ] |
|
333 | + : false; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Verifies whether the given data exists already on the jsdata array. |
|
339 | + * Overriding data is not allowed. |
|
340 | + * |
|
341 | + * @param string $key Index for data. |
|
342 | + * @return bool If valid then return true. |
|
343 | + * @throws InvalidArgumentException if data already exists. |
|
344 | + */ |
|
345 | + protected function verifyDataNotExisting($key) |
|
346 | + { |
|
347 | + if (isset($this->jsdata[ $key ])) { |
|
348 | + if (is_array($this->jsdata[ $key ])) { |
|
349 | + throw new InvalidArgumentException( |
|
350 | + sprintf( |
|
351 | + __( |
|
352 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
353 | 353 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
354 | 354 | %2$s method to push your value to the array.', |
355 | - 'event_espresso' |
|
356 | - ), |
|
357 | - $key, |
|
358 | - 'pushData()' |
|
359 | - ) |
|
360 | - ); |
|
361 | - } |
|
362 | - throw new InvalidArgumentException( |
|
363 | - sprintf( |
|
364 | - __( |
|
365 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
355 | + 'event_espresso' |
|
356 | + ), |
|
357 | + $key, |
|
358 | + 'pushData()' |
|
359 | + ) |
|
360 | + ); |
|
361 | + } |
|
362 | + throw new InvalidArgumentException( |
|
363 | + sprintf( |
|
364 | + __( |
|
365 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
366 | 366 | allowed. Consider attaching your value to a different key', |
367 | - 'event_espresso' |
|
368 | - ), |
|
369 | - $key |
|
370 | - ) |
|
371 | - ); |
|
372 | - } |
|
373 | - return true; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Get the actual asset path for asset manifests. |
|
379 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
380 | - * |
|
381 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
382 | - * asset file location. |
|
383 | - * @param string $chunk_name |
|
384 | - * @param string $asset_type |
|
385 | - * @return string |
|
386 | - * @since 4.9.59.p |
|
387 | - */ |
|
388 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
389 | - { |
|
390 | - $url = isset( |
|
391 | - $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
392 | - $this->manifest_data[ $namespace ]['url_base'] |
|
393 | - ) |
|
394 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
395 | - . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
396 | - : $chunk_name; |
|
397 | - return apply_filters( |
|
398 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
399 | - $url, |
|
400 | - $namespace, |
|
401 | - $chunk_name, |
|
402 | - $asset_type |
|
403 | - ); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Return the url to a js file for the given namespace and chunk name. |
|
410 | - * |
|
411 | - * @param string $namespace |
|
412 | - * @param string $chunk_name |
|
413 | - * @return string |
|
414 | - */ |
|
415 | - public function getJsUrl($namespace, $chunk_name) |
|
416 | - { |
|
417 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * Return the url to a css file for the given namespace and chunk name. |
|
423 | - * |
|
424 | - * @param string $namespace |
|
425 | - * @param string $chunk_name |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - public function getCssUrl($namespace, $chunk_name) |
|
429 | - { |
|
430 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @since 4.9.62.p |
|
436 | - * @throws InvalidArgumentException |
|
437 | - * @throws InvalidFilePathException |
|
438 | - */ |
|
439 | - public function registerManifestFiles() |
|
440 | - { |
|
441 | - $manifest_files = $this->assets->getManifestFiles(); |
|
442 | - foreach ($manifest_files as $manifest_file) { |
|
443 | - $this->registerManifestFile( |
|
444 | - $manifest_file->assetNamespace(), |
|
445 | - $manifest_file->urlBase(), |
|
446 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
447 | - ); |
|
448 | - } |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
454 | - * |
|
455 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
456 | - * @param string $url_base The url base for the manifest file location. |
|
457 | - * @param string $manifest_file The absolute path to the manifest file. |
|
458 | - * @throws InvalidArgumentException |
|
459 | - * @throws InvalidFilePathException |
|
460 | - * @since 4.9.59.p |
|
461 | - */ |
|
462 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
463 | - { |
|
464 | - if (isset($this->manifest_data[ $namespace ])) { |
|
465 | - throw new InvalidArgumentException( |
|
466 | - sprintf( |
|
467 | - esc_html__( |
|
468 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
469 | - 'event_espresso' |
|
470 | - ), |
|
471 | - $namespace |
|
472 | - ) |
|
473 | - ); |
|
474 | - } |
|
475 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
476 | - if (is_admin()) { |
|
477 | - EE_Error::add_error( |
|
478 | - sprintf( |
|
479 | - esc_html__( |
|
480 | - 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
481 | - 'event_espresso' |
|
482 | - ), |
|
483 | - 'Event Espresso', |
|
484 | - $url_base, |
|
485 | - 'plugins_url', |
|
486 | - 'WP_PLUGIN_URL' |
|
487 | - ), |
|
488 | - __FILE__, |
|
489 | - __FUNCTION__, |
|
490 | - __LINE__ |
|
491 | - ); |
|
492 | - } |
|
493 | - return; |
|
494 | - } |
|
495 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
496 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
497 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Decodes json from the provided manifest file. |
|
504 | - * |
|
505 | - * @since 4.9.59.p |
|
506 | - * @param string $manifest_file Path to manifest file. |
|
507 | - * @return array |
|
508 | - * @throws InvalidFilePathException |
|
509 | - */ |
|
510 | - private function decodeManifestFile($manifest_file) |
|
511 | - { |
|
512 | - if (! file_exists($manifest_file)) { |
|
513 | - throw new InvalidFilePathException($manifest_file); |
|
514 | - } |
|
515 | - return json_decode(file_get_contents($manifest_file), true); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * This is used to set registered script handles that have data. |
|
521 | - * |
|
522 | - * @param string $script_handle |
|
523 | - */ |
|
524 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
525 | - { |
|
526 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /**i |
|
367 | + 'event_espresso' |
|
368 | + ), |
|
369 | + $key |
|
370 | + ) |
|
371 | + ); |
|
372 | + } |
|
373 | + return true; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Get the actual asset path for asset manifests. |
|
379 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
380 | + * |
|
381 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
382 | + * asset file location. |
|
383 | + * @param string $chunk_name |
|
384 | + * @param string $asset_type |
|
385 | + * @return string |
|
386 | + * @since 4.9.59.p |
|
387 | + */ |
|
388 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
389 | + { |
|
390 | + $url = isset( |
|
391 | + $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
392 | + $this->manifest_data[ $namespace ]['url_base'] |
|
393 | + ) |
|
394 | + ? $this->manifest_data[ $namespace ]['url_base'] |
|
395 | + . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
396 | + : $chunk_name; |
|
397 | + return apply_filters( |
|
398 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
399 | + $url, |
|
400 | + $namespace, |
|
401 | + $chunk_name, |
|
402 | + $asset_type |
|
403 | + ); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Return the url to a js file for the given namespace and chunk name. |
|
410 | + * |
|
411 | + * @param string $namespace |
|
412 | + * @param string $chunk_name |
|
413 | + * @return string |
|
414 | + */ |
|
415 | + public function getJsUrl($namespace, $chunk_name) |
|
416 | + { |
|
417 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * Return the url to a css file for the given namespace and chunk name. |
|
423 | + * |
|
424 | + * @param string $namespace |
|
425 | + * @param string $chunk_name |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + public function getCssUrl($namespace, $chunk_name) |
|
429 | + { |
|
430 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @since 4.9.62.p |
|
436 | + * @throws InvalidArgumentException |
|
437 | + * @throws InvalidFilePathException |
|
438 | + */ |
|
439 | + public function registerManifestFiles() |
|
440 | + { |
|
441 | + $manifest_files = $this->assets->getManifestFiles(); |
|
442 | + foreach ($manifest_files as $manifest_file) { |
|
443 | + $this->registerManifestFile( |
|
444 | + $manifest_file->assetNamespace(), |
|
445 | + $manifest_file->urlBase(), |
|
446 | + $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
447 | + ); |
|
448 | + } |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
454 | + * |
|
455 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
456 | + * @param string $url_base The url base for the manifest file location. |
|
457 | + * @param string $manifest_file The absolute path to the manifest file. |
|
458 | + * @throws InvalidArgumentException |
|
459 | + * @throws InvalidFilePathException |
|
460 | + * @since 4.9.59.p |
|
461 | + */ |
|
462 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
463 | + { |
|
464 | + if (isset($this->manifest_data[ $namespace ])) { |
|
465 | + throw new InvalidArgumentException( |
|
466 | + sprintf( |
|
467 | + esc_html__( |
|
468 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
469 | + 'event_espresso' |
|
470 | + ), |
|
471 | + $namespace |
|
472 | + ) |
|
473 | + ); |
|
474 | + } |
|
475 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
476 | + if (is_admin()) { |
|
477 | + EE_Error::add_error( |
|
478 | + sprintf( |
|
479 | + esc_html__( |
|
480 | + 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
481 | + 'event_espresso' |
|
482 | + ), |
|
483 | + 'Event Espresso', |
|
484 | + $url_base, |
|
485 | + 'plugins_url', |
|
486 | + 'WP_PLUGIN_URL' |
|
487 | + ), |
|
488 | + __FILE__, |
|
489 | + __FUNCTION__, |
|
490 | + __LINE__ |
|
491 | + ); |
|
492 | + } |
|
493 | + return; |
|
494 | + } |
|
495 | + $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
496 | + if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
497 | + $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Decodes json from the provided manifest file. |
|
504 | + * |
|
505 | + * @since 4.9.59.p |
|
506 | + * @param string $manifest_file Path to manifest file. |
|
507 | + * @return array |
|
508 | + * @throws InvalidFilePathException |
|
509 | + */ |
|
510 | + private function decodeManifestFile($manifest_file) |
|
511 | + { |
|
512 | + if (! file_exists($manifest_file)) { |
|
513 | + throw new InvalidFilePathException($manifest_file); |
|
514 | + } |
|
515 | + return json_decode(file_get_contents($manifest_file), true); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * This is used to set registered script handles that have data. |
|
521 | + * |
|
522 | + * @param string $script_handle |
|
523 | + */ |
|
524 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
525 | + { |
|
526 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /**i |
|
531 | 531 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
532 | 532 | * Dependency stored in WP_Scripts if its set. |
533 | 533 | */ |
534 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
535 | - { |
|
536 | - if (empty($this->script_handles_with_data)) { |
|
537 | - return; |
|
538 | - } |
|
539 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
540 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
547 | - * |
|
548 | - * @param string $script_handle |
|
549 | - */ |
|
550 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
551 | - { |
|
552 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
553 | - global $wp_scripts; |
|
554 | - $unset_handle = false; |
|
555 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
556 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
557 | - $unset_handle = true; |
|
558 | - } |
|
559 | - //deal with inline_scripts |
|
560 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
561 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
562 | - $unset_handle = true; |
|
563 | - } |
|
564 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
565 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
566 | - } |
|
567 | - if ($unset_handle) { |
|
568 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
569 | - } |
|
570 | - } |
|
571 | - } |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * register translations for a registered script |
|
576 | - * |
|
577 | - * @param string $handle |
|
578 | - */ |
|
579 | - public function registerTranslation($handle) |
|
580 | - { |
|
581 | - $this->i18n_registry->registerScriptI18n($handle); |
|
582 | - } |
|
534 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
535 | + { |
|
536 | + if (empty($this->script_handles_with_data)) { |
|
537 | + return; |
|
538 | + } |
|
539 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
540 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
547 | + * |
|
548 | + * @param string $script_handle |
|
549 | + */ |
|
550 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
551 | + { |
|
552 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
553 | + global $wp_scripts; |
|
554 | + $unset_handle = false; |
|
555 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
556 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
557 | + $unset_handle = true; |
|
558 | + } |
|
559 | + //deal with inline_scripts |
|
560 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
561 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
562 | + $unset_handle = true; |
|
563 | + } |
|
564 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
565 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
566 | + } |
|
567 | + if ($unset_handle) { |
|
568 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
569 | + } |
|
570 | + } |
|
571 | + } |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * register translations for a registered script |
|
576 | + * |
|
577 | + * @param string $handle |
|
578 | + */ |
|
579 | + public function registerTranslation($handle) |
|
580 | + { |
|
581 | + $this->i18n_registry->registerScriptI18n($handle); |
|
582 | + } |
|
583 | 583 | } |
@@ -20,204 +20,204 @@ |
||
20 | 20 | abstract class Block implements BlockInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * BlockAssetManager that this editor block uses for asset registration |
|
25 | - * |
|
26 | - * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | - */ |
|
28 | - protected $block_asset_manager; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array $attributes |
|
32 | - */ |
|
33 | - private $attributes; |
|
34 | - |
|
35 | - /** |
|
36 | - * If set to true, then the block will render its content client side |
|
37 | - * If false, then the block will render its content server side using the renderBlock() method |
|
38 | - * |
|
39 | - * @var bool $dynamic |
|
40 | - */ |
|
41 | - private $dynamic = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $block_type |
|
45 | - */ |
|
46 | - private $block_type; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $supported_post_types |
|
50 | - */ |
|
51 | - private $supported_post_types; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var WP_Block_Type $wp_block_type |
|
55 | - */ |
|
56 | - private $wp_block_type; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * BlockLoader constructor. |
|
61 | - * |
|
62 | - * @param BlockAssetManagerInterface $block_asset_manager |
|
63 | - */ |
|
64 | - public function __construct(BlockAssetManagerInterface $block_asset_manager) |
|
65 | - { |
|
66 | - $this->block_asset_manager = $block_asset_manager; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function blockType() |
|
74 | - { |
|
75 | - return $this->block_type; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function namespacedBlockType() |
|
83 | - { |
|
84 | - return self::NAME_SPACE . '/' . $this->block_type; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $block_type |
|
90 | - */ |
|
91 | - protected function setBlockType($block_type) |
|
92 | - { |
|
93 | - $this->block_type = $block_type; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * BlockAssetManager that this editor block uses for asset registration |
|
99 | - * |
|
100 | - * @return BlockAssetManagerInterface |
|
101 | - */ |
|
102 | - public function assetManager() |
|
103 | - { |
|
104 | - return $this->block_asset_manager; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param WP_Block_Type $wp_block_type |
|
110 | - */ |
|
111 | - protected function setWpBlockType($wp_block_type) |
|
112 | - { |
|
113 | - $this->wp_block_type = $wp_block_type; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param array $supported_post_types |
|
119 | - */ |
|
120 | - protected function setSupportedPostTypes(array $supported_post_types) |
|
121 | - { |
|
122 | - $this->supported_post_types = $supported_post_types; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function attributes() |
|
130 | - { |
|
131 | - return $this->attributes; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param array $attributes |
|
137 | - */ |
|
138 | - public function setAttributes(array $attributes) |
|
139 | - { |
|
140 | - $this->attributes = $attributes; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function isDynamic() |
|
148 | - { |
|
149 | - return $this->dynamic; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param bool $dynamic |
|
155 | - */ |
|
156 | - public function setDynamic($dynamic = true) |
|
157 | - { |
|
158 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Registers the Editor Block with WP core; |
|
164 | - * Returns the registered block type on success, or false on failure. |
|
165 | - * |
|
166 | - * @return WP_Block_Type|false |
|
167 | - */ |
|
168 | - public function registerBlock() |
|
169 | - { |
|
170 | - $args = array( |
|
171 | - 'attributes' => $this->attributes(), |
|
172 | - 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
173 | - 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
174 | - 'script' => $this->block_asset_manager->getScriptHandle(), |
|
175 | - 'style' => $this->block_asset_manager->getStyleHandle(), |
|
176 | - ); |
|
177 | - if ($this->isDynamic()) { |
|
178 | - $args['render_callback'] = array($this, 'renderBlock'); |
|
179 | - } |
|
180 | - $wp_block_type = register_block_type( |
|
181 | - new WP_Block_Type( |
|
182 | - $this->namespacedBlockType(), |
|
183 | - $args |
|
184 | - ) |
|
185 | - ); |
|
186 | - $this->setWpBlockType($wp_block_type); |
|
187 | - return $wp_block_type; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
193 | - */ |
|
194 | - public function unRegisterBlock() |
|
195 | - { |
|
196 | - return unregister_block_type($this->namespacedBlockType()); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * returns true if the block type applies for the supplied post type |
|
202 | - * and should be added to that post type's editor |
|
203 | - * |
|
204 | - * @param string $post_type |
|
205 | - * @return boolean |
|
206 | - */ |
|
207 | - public function appliesToPostType($post_type) |
|
208 | - { |
|
209 | - return in_array($post_type, $this->supported_post_types, true); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @return array |
|
215 | - */ |
|
216 | - public function getEditorContainer() |
|
217 | - { |
|
218 | - return array( |
|
219 | - $this->namespacedBlockType(), |
|
220 | - array(), |
|
221 | - ); |
|
222 | - } |
|
23 | + /** |
|
24 | + * BlockAssetManager that this editor block uses for asset registration |
|
25 | + * |
|
26 | + * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | + */ |
|
28 | + protected $block_asset_manager; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array $attributes |
|
32 | + */ |
|
33 | + private $attributes; |
|
34 | + |
|
35 | + /** |
|
36 | + * If set to true, then the block will render its content client side |
|
37 | + * If false, then the block will render its content server side using the renderBlock() method |
|
38 | + * |
|
39 | + * @var bool $dynamic |
|
40 | + */ |
|
41 | + private $dynamic = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $block_type |
|
45 | + */ |
|
46 | + private $block_type; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $supported_post_types |
|
50 | + */ |
|
51 | + private $supported_post_types; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var WP_Block_Type $wp_block_type |
|
55 | + */ |
|
56 | + private $wp_block_type; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * BlockLoader constructor. |
|
61 | + * |
|
62 | + * @param BlockAssetManagerInterface $block_asset_manager |
|
63 | + */ |
|
64 | + public function __construct(BlockAssetManagerInterface $block_asset_manager) |
|
65 | + { |
|
66 | + $this->block_asset_manager = $block_asset_manager; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function blockType() |
|
74 | + { |
|
75 | + return $this->block_type; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function namespacedBlockType() |
|
83 | + { |
|
84 | + return self::NAME_SPACE . '/' . $this->block_type; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $block_type |
|
90 | + */ |
|
91 | + protected function setBlockType($block_type) |
|
92 | + { |
|
93 | + $this->block_type = $block_type; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * BlockAssetManager that this editor block uses for asset registration |
|
99 | + * |
|
100 | + * @return BlockAssetManagerInterface |
|
101 | + */ |
|
102 | + public function assetManager() |
|
103 | + { |
|
104 | + return $this->block_asset_manager; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param WP_Block_Type $wp_block_type |
|
110 | + */ |
|
111 | + protected function setWpBlockType($wp_block_type) |
|
112 | + { |
|
113 | + $this->wp_block_type = $wp_block_type; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param array $supported_post_types |
|
119 | + */ |
|
120 | + protected function setSupportedPostTypes(array $supported_post_types) |
|
121 | + { |
|
122 | + $this->supported_post_types = $supported_post_types; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function attributes() |
|
130 | + { |
|
131 | + return $this->attributes; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param array $attributes |
|
137 | + */ |
|
138 | + public function setAttributes(array $attributes) |
|
139 | + { |
|
140 | + $this->attributes = $attributes; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function isDynamic() |
|
148 | + { |
|
149 | + return $this->dynamic; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param bool $dynamic |
|
155 | + */ |
|
156 | + public function setDynamic($dynamic = true) |
|
157 | + { |
|
158 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Registers the Editor Block with WP core; |
|
164 | + * Returns the registered block type on success, or false on failure. |
|
165 | + * |
|
166 | + * @return WP_Block_Type|false |
|
167 | + */ |
|
168 | + public function registerBlock() |
|
169 | + { |
|
170 | + $args = array( |
|
171 | + 'attributes' => $this->attributes(), |
|
172 | + 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
173 | + 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
174 | + 'script' => $this->block_asset_manager->getScriptHandle(), |
|
175 | + 'style' => $this->block_asset_manager->getStyleHandle(), |
|
176 | + ); |
|
177 | + if ($this->isDynamic()) { |
|
178 | + $args['render_callback'] = array($this, 'renderBlock'); |
|
179 | + } |
|
180 | + $wp_block_type = register_block_type( |
|
181 | + new WP_Block_Type( |
|
182 | + $this->namespacedBlockType(), |
|
183 | + $args |
|
184 | + ) |
|
185 | + ); |
|
186 | + $this->setWpBlockType($wp_block_type); |
|
187 | + return $wp_block_type; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
193 | + */ |
|
194 | + public function unRegisterBlock() |
|
195 | + { |
|
196 | + return unregister_block_type($this->namespacedBlockType()); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * returns true if the block type applies for the supplied post type |
|
202 | + * and should be added to that post type's editor |
|
203 | + * |
|
204 | + * @param string $post_type |
|
205 | + * @return boolean |
|
206 | + */ |
|
207 | + public function appliesToPostType($post_type) |
|
208 | + { |
|
209 | + return in_array($post_type, $this->supported_post_types, true); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @return array |
|
215 | + */ |
|
216 | + public function getEditorContainer() |
|
217 | + { |
|
218 | + return array( |
|
219 | + $this->namespacedBlockType(), |
|
220 | + array(), |
|
221 | + ); |
|
222 | + } |
|
223 | 223 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | */ |
82 | 82 | public function namespacedBlockType() |
83 | 83 | { |
84 | - return self::NAME_SPACE . '/' . $this->block_type; |
|
84 | + return self::NAME_SPACE.'/'.$this->block_type; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 |
@@ -17,58 +17,58 @@ |
||
17 | 17 | class EventAttendees extends Block |
18 | 18 | { |
19 | 19 | |
20 | - const BLOCK_TYPE = 'widgets-event-attendees'; |
|
20 | + const BLOCK_TYPE = 'widgets-event-attendees'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var EspressoEventAttendees $shortcode |
|
24 | - */ |
|
25 | - protected $shortcode; |
|
22 | + /** |
|
23 | + * @var EspressoEventAttendees $shortcode |
|
24 | + */ |
|
25 | + protected $shortcode; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * EventAttendees constructor. |
|
30 | - * |
|
31 | - * @param CoreBlocksAssetManager $block_asset_manager |
|
32 | - * @param EspressoEventAttendees $shortcode |
|
33 | - */ |
|
34 | - public function __construct(CoreBlocksAssetManager $block_asset_manager, EspressoEventAttendees $shortcode) |
|
35 | - { |
|
36 | - parent::__construct($block_asset_manager); |
|
37 | - $this->shortcode = $shortcode; |
|
38 | - } |
|
28 | + /** |
|
29 | + * EventAttendees constructor. |
|
30 | + * |
|
31 | + * @param CoreBlocksAssetManager $block_asset_manager |
|
32 | + * @param EspressoEventAttendees $shortcode |
|
33 | + */ |
|
34 | + public function __construct(CoreBlocksAssetManager $block_asset_manager, EspressoEventAttendees $shortcode) |
|
35 | + { |
|
36 | + parent::__construct($block_asset_manager); |
|
37 | + $this->shortcode = $shortcode; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Perform any early setup required by the block |
|
43 | - * including setting the block type and supported post types |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function initialize() |
|
48 | - { |
|
49 | - $this->setBlockType(self::BLOCK_TYPE); |
|
50 | - $this->setSupportedPostTypes(array('espresso_events', 'post', 'page')); |
|
51 | - $this->setAttributes(array()); |
|
52 | - $this->setDynamic(); |
|
53 | - } |
|
41 | + /** |
|
42 | + * Perform any early setup required by the block |
|
43 | + * including setting the block type and supported post types |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function initialize() |
|
48 | + { |
|
49 | + $this->setBlockType(self::BLOCK_TYPE); |
|
50 | + $this->setSupportedPostTypes(array('espresso_events', 'post', 'page')); |
|
51 | + $this->setAttributes(array()); |
|
52 | + $this->setDynamic(); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * returns the rendered HTML for the block |
|
58 | - * |
|
59 | - * @param array $attributes |
|
60 | - * @return string |
|
61 | - * @throws \EE_Error |
|
62 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
63 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
64 | - * @throws \InvalidArgumentException |
|
65 | - */ |
|
66 | - public function renderBlock(array $attributes = array()) |
|
67 | - { |
|
68 | - if(! isset($attributes['selectedEventId'])) { |
|
69 | - return '<h2>' . __METHOD__ . '()</h2>' . var_export($attributes, true); |
|
70 | - } |
|
71 | - $attributes['event_id'] = absint($attributes['selectedEventId']); |
|
72 | - return $this->shortcode->processShortcode($attributes); |
|
73 | - } |
|
56 | + /** |
|
57 | + * returns the rendered HTML for the block |
|
58 | + * |
|
59 | + * @param array $attributes |
|
60 | + * @return string |
|
61 | + * @throws \EE_Error |
|
62 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
63 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
64 | + * @throws \InvalidArgumentException |
|
65 | + */ |
|
66 | + public function renderBlock(array $attributes = array()) |
|
67 | + { |
|
68 | + if(! isset($attributes['selectedEventId'])) { |
|
69 | + return '<h2>' . __METHOD__ . '()</h2>' . var_export($attributes, true); |
|
70 | + } |
|
71 | + $attributes['event_id'] = absint($attributes['selectedEventId']); |
|
72 | + return $this->shortcode->processShortcode($attributes); |
|
73 | + } |
|
74 | 74 | } |
@@ -65,8 +65,8 @@ |
||
65 | 65 | */ |
66 | 66 | public function renderBlock(array $attributes = array()) |
67 | 67 | { |
68 | - if(! isset($attributes['selectedEventId'])) { |
|
69 | - return '<h2>' . __METHOD__ . '()</h2>' . var_export($attributes, true); |
|
68 | + if ( ! isset($attributes['selectedEventId'])) { |
|
69 | + return '<h2>'.__METHOD__.'()</h2>'.var_export($attributes, true); |
|
70 | 70 | } |
71 | 71 | $attributes['event_id'] = absint($attributes['selectedEventId']); |
72 | 72 | return $this->shortcode->processShortcode($attributes); |