@@ -16,595 +16,595 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
21 | - */ |
|
22 | - protected $_message_resource_manager; |
|
23 | - |
|
24 | - /** |
|
25 | - * @type EE_Messages_Queue |
|
26 | - */ |
|
27 | - protected $_queue; |
|
28 | - |
|
29 | - /** |
|
30 | - * @type EE_Messages_Generator |
|
31 | - */ |
|
32 | - protected $_generator; |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * constructor |
|
39 | - * |
|
40 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
41 | - */ |
|
42 | - public function __construct(EE_Message_Resource_Manager $message_resource_manager) |
|
43 | - { |
|
44 | - $this->_message_resource_manager = $message_resource_manager; |
|
45 | - $this->_init_queue_and_generator(); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * This method sets (or resets) the various properties for use. |
|
53 | - * |
|
54 | - * - $_queue = holds the messages queue |
|
55 | - * - $_generator = holds the messages generator |
|
56 | - */ |
|
57 | - protected function _init_queue_and_generator() |
|
58 | - { |
|
59 | - $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
60 | - $this->_queue = $this->_generator->generation_queue(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * This returns the current set queue. |
|
68 | - * @return EE_Messages_Queue |
|
69 | - */ |
|
70 | - public function get_queue() |
|
71 | - { |
|
72 | - return $this->_queue; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * This method can be utilized to process messages from a queue and they will be processed immediately on the same |
|
78 | - * request. Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes |
|
79 | - * client code has already filtered those if necessary). |
|
80 | - * |
|
81 | - * @param EE_Messages_Queue $queue_to_process |
|
82 | - * @return bool true for success false for error. |
|
83 | - * @throws EE_Error |
|
84 | - * @throws EE_Error |
|
85 | - */ |
|
86 | - public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) |
|
87 | - { |
|
88 | - $success = false; |
|
89 | - $messages_to_send = array(); |
|
90 | - $messages_to_generate = array(); |
|
91 | - // loop through and setup the various messages from the queue so we know what is being processed |
|
92 | - $queue_to_process->get_message_repository()->rewind(); |
|
93 | - foreach ($queue_to_process->get_message_repository() as $message) { |
|
94 | - if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
95 | - $messages_to_generate[] = $message; |
|
96 | - continue; |
|
97 | - } |
|
98 | - |
|
99 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
100 | - $messages_to_send[] = $message; |
|
101 | - continue; |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - // do generation/sends |
|
106 | - if ($messages_to_generate) { |
|
107 | - $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
108 | - } |
|
109 | - |
|
110 | - if ($messages_to_send) { |
|
111 | - $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
112 | - // if there was messages to generate and it failed, then we override any success value for the sending process |
|
113 | - // otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
|
114 | - // Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
|
115 | - // all messages processing on the same request. |
|
116 | - $success = $messages_to_generate && ! $success ? false : $sent; |
|
117 | - } |
|
118 | - return $success; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator. |
|
124 | - * |
|
125 | - * @param EE_Message[] $messages Array of EE_Message objects (optional) to build the queue with. |
|
126 | - * @param bool $clear_queue Whether to ensure a fresh queue or not. |
|
127 | - * |
|
128 | - * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
|
129 | - * generated messages. |
|
130 | - */ |
|
131 | - public function batch_generate_from_queue($messages = array(), $clear_queue = false) |
|
132 | - { |
|
133 | - if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
134 | - $new_queue = $this->_generator->generate(); |
|
135 | - if ($new_queue instanceof EE_Messages_Queue) { |
|
136 | - // unlock queue |
|
137 | - $this->_queue->unlock_queue(); |
|
138 | - $new_queue->initiate_request_by_priority('send'); |
|
139 | - return $new_queue; |
|
140 | - } |
|
141 | - } |
|
142 | - $this->_queue->unlock_queue(); |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * This method preps a queue for generation. |
|
150 | - * |
|
151 | - * @since 4.9.0 |
|
152 | - * |
|
153 | - * @param EE_Message[] $messages Array of EE_Message objects to build the queue with |
|
154 | - * |
|
155 | - * @param bool $clear_queue This indicates whether the existing queue should be dumped or not. |
|
156 | - * |
|
157 | - * @return bool true means queue prepped, false means there was a lock so no generation please. |
|
158 | - */ |
|
159 | - protected function _build_queue_for_generation($messages = array(), $clear_queue = false) |
|
160 | - { |
|
161 | - |
|
162 | - if ($clear_queue) { |
|
163 | - $this->_init_queue_and_generator(); |
|
164 | - } |
|
165 | - |
|
166 | - if ($messages) { |
|
167 | - // if generation is locked then get out now because that means processing is already happening. |
|
168 | - if ($this->_queue->is_locked()) { |
|
169 | - return false; |
|
170 | - } |
|
171 | - |
|
172 | - $this->_queue->lock_queue(); |
|
173 | - $messages = is_array($messages) ? $messages : array( $messages ); |
|
174 | - foreach ($messages as $message) { |
|
175 | - if ($message instanceof EE_Message) { |
|
176 | - $data = $message->all_extra_meta_array(); |
|
177 | - $this->_queue->add($message, $data); |
|
178 | - } |
|
179 | - } |
|
180 | - return true; |
|
181 | - } else { |
|
182 | - return $this->_queue->get_batch_to_generate(); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * This method preps a queue for sending. |
|
189 | - * |
|
190 | - * @param EE_Message[] $messages |
|
191 | - * @param bool $clear_queue Used to indicate whether to start with a fresh queue or not. |
|
192 | - * |
|
193 | - * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
|
194 | - */ |
|
195 | - protected function _build_queue_for_sending($messages, $clear_queue = false) |
|
196 | - { |
|
197 | - // if sending is locked then get out now because that means processing is already happening. |
|
198 | - if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
199 | - return false; |
|
200 | - } |
|
201 | - |
|
202 | - $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
203 | - |
|
204 | - if ($clear_queue) { |
|
205 | - $this->_init_queue_and_generator(); |
|
206 | - } |
|
207 | - |
|
208 | - $messages = is_array($messages) ? $messages : array( $messages ); |
|
209 | - |
|
210 | - foreach ($messages as $message) { |
|
211 | - $this->_queue->add($message); |
|
212 | - } |
|
213 | - return true; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute() |
|
219 | - * to iterate and send unsent messages. |
|
220 | - * |
|
221 | - * @param EE_Message[] $messages If an array of messages is sent in then use it. |
|
222 | - * |
|
223 | - * @param bool $clear_queue Whether to initialize a new queue or keep the existing one. |
|
224 | - * |
|
225 | - * @return EE_Messages_Queue |
|
226 | - */ |
|
227 | - public function batch_send_from_queue($messages = array(), $clear_queue = false) |
|
228 | - { |
|
229 | - |
|
230 | - if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
231 | - $this->_queue->execute(); |
|
232 | - $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
233 | - } else { |
|
234 | - // get messages to send and execute. |
|
235 | - $this->_queue->get_to_send_batch_and_send(); |
|
236 | - } |
|
237 | - // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed |
|
238 | - // messages in the queue and decide how to handle at that point. |
|
239 | - return $this->_queue; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the |
|
249 | - * EE_Message_Queue with the generated messages for the caller to work with. Note, this does NOT save the generated |
|
250 | - * messages in the queue, leaving it up to the caller to do so. |
|
251 | - * |
|
252 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
253 | - * @return EE_Messages_Queue |
|
254 | - */ |
|
255 | - public function generate_and_return($messages_to_generate) |
|
256 | - { |
|
257 | - $this->_init_queue_and_generator(); |
|
258 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
259 | - return $this->_generator->generate(false); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Executes the generator generate method on the current internal queue, and returns the generated queue. |
|
267 | - * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false). |
|
268 | - * @return EE_Messages_Queue |
|
269 | - */ |
|
270 | - public function generate_queue($persist = true) |
|
271 | - { |
|
272 | - return $this->_generator->generate($persist); |
|
273 | - } |
|
19 | + /** |
|
20 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
21 | + */ |
|
22 | + protected $_message_resource_manager; |
|
23 | + |
|
24 | + /** |
|
25 | + * @type EE_Messages_Queue |
|
26 | + */ |
|
27 | + protected $_queue; |
|
28 | + |
|
29 | + /** |
|
30 | + * @type EE_Messages_Generator |
|
31 | + */ |
|
32 | + protected $_generator; |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * constructor |
|
39 | + * |
|
40 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
41 | + */ |
|
42 | + public function __construct(EE_Message_Resource_Manager $message_resource_manager) |
|
43 | + { |
|
44 | + $this->_message_resource_manager = $message_resource_manager; |
|
45 | + $this->_init_queue_and_generator(); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * This method sets (or resets) the various properties for use. |
|
53 | + * |
|
54 | + * - $_queue = holds the messages queue |
|
55 | + * - $_generator = holds the messages generator |
|
56 | + */ |
|
57 | + protected function _init_queue_and_generator() |
|
58 | + { |
|
59 | + $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
60 | + $this->_queue = $this->_generator->generation_queue(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * This returns the current set queue. |
|
68 | + * @return EE_Messages_Queue |
|
69 | + */ |
|
70 | + public function get_queue() |
|
71 | + { |
|
72 | + return $this->_queue; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * This method can be utilized to process messages from a queue and they will be processed immediately on the same |
|
78 | + * request. Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes |
|
79 | + * client code has already filtered those if necessary). |
|
80 | + * |
|
81 | + * @param EE_Messages_Queue $queue_to_process |
|
82 | + * @return bool true for success false for error. |
|
83 | + * @throws EE_Error |
|
84 | + * @throws EE_Error |
|
85 | + */ |
|
86 | + public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) |
|
87 | + { |
|
88 | + $success = false; |
|
89 | + $messages_to_send = array(); |
|
90 | + $messages_to_generate = array(); |
|
91 | + // loop through and setup the various messages from the queue so we know what is being processed |
|
92 | + $queue_to_process->get_message_repository()->rewind(); |
|
93 | + foreach ($queue_to_process->get_message_repository() as $message) { |
|
94 | + if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
95 | + $messages_to_generate[] = $message; |
|
96 | + continue; |
|
97 | + } |
|
98 | + |
|
99 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
100 | + $messages_to_send[] = $message; |
|
101 | + continue; |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + // do generation/sends |
|
106 | + if ($messages_to_generate) { |
|
107 | + $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
108 | + } |
|
109 | + |
|
110 | + if ($messages_to_send) { |
|
111 | + $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
112 | + // if there was messages to generate and it failed, then we override any success value for the sending process |
|
113 | + // otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
|
114 | + // Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
|
115 | + // all messages processing on the same request. |
|
116 | + $success = $messages_to_generate && ! $success ? false : $sent; |
|
117 | + } |
|
118 | + return $success; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator. |
|
124 | + * |
|
125 | + * @param EE_Message[] $messages Array of EE_Message objects (optional) to build the queue with. |
|
126 | + * @param bool $clear_queue Whether to ensure a fresh queue or not. |
|
127 | + * |
|
128 | + * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
|
129 | + * generated messages. |
|
130 | + */ |
|
131 | + public function batch_generate_from_queue($messages = array(), $clear_queue = false) |
|
132 | + { |
|
133 | + if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
134 | + $new_queue = $this->_generator->generate(); |
|
135 | + if ($new_queue instanceof EE_Messages_Queue) { |
|
136 | + // unlock queue |
|
137 | + $this->_queue->unlock_queue(); |
|
138 | + $new_queue->initiate_request_by_priority('send'); |
|
139 | + return $new_queue; |
|
140 | + } |
|
141 | + } |
|
142 | + $this->_queue->unlock_queue(); |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * This method preps a queue for generation. |
|
150 | + * |
|
151 | + * @since 4.9.0 |
|
152 | + * |
|
153 | + * @param EE_Message[] $messages Array of EE_Message objects to build the queue with |
|
154 | + * |
|
155 | + * @param bool $clear_queue This indicates whether the existing queue should be dumped or not. |
|
156 | + * |
|
157 | + * @return bool true means queue prepped, false means there was a lock so no generation please. |
|
158 | + */ |
|
159 | + protected function _build_queue_for_generation($messages = array(), $clear_queue = false) |
|
160 | + { |
|
161 | + |
|
162 | + if ($clear_queue) { |
|
163 | + $this->_init_queue_and_generator(); |
|
164 | + } |
|
165 | + |
|
166 | + if ($messages) { |
|
167 | + // if generation is locked then get out now because that means processing is already happening. |
|
168 | + if ($this->_queue->is_locked()) { |
|
169 | + return false; |
|
170 | + } |
|
171 | + |
|
172 | + $this->_queue->lock_queue(); |
|
173 | + $messages = is_array($messages) ? $messages : array( $messages ); |
|
174 | + foreach ($messages as $message) { |
|
175 | + if ($message instanceof EE_Message) { |
|
176 | + $data = $message->all_extra_meta_array(); |
|
177 | + $this->_queue->add($message, $data); |
|
178 | + } |
|
179 | + } |
|
180 | + return true; |
|
181 | + } else { |
|
182 | + return $this->_queue->get_batch_to_generate(); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * This method preps a queue for sending. |
|
189 | + * |
|
190 | + * @param EE_Message[] $messages |
|
191 | + * @param bool $clear_queue Used to indicate whether to start with a fresh queue or not. |
|
192 | + * |
|
193 | + * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
|
194 | + */ |
|
195 | + protected function _build_queue_for_sending($messages, $clear_queue = false) |
|
196 | + { |
|
197 | + // if sending is locked then get out now because that means processing is already happening. |
|
198 | + if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
199 | + return false; |
|
200 | + } |
|
201 | + |
|
202 | + $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
203 | + |
|
204 | + if ($clear_queue) { |
|
205 | + $this->_init_queue_and_generator(); |
|
206 | + } |
|
207 | + |
|
208 | + $messages = is_array($messages) ? $messages : array( $messages ); |
|
209 | + |
|
210 | + foreach ($messages as $message) { |
|
211 | + $this->_queue->add($message); |
|
212 | + } |
|
213 | + return true; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute() |
|
219 | + * to iterate and send unsent messages. |
|
220 | + * |
|
221 | + * @param EE_Message[] $messages If an array of messages is sent in then use it. |
|
222 | + * |
|
223 | + * @param bool $clear_queue Whether to initialize a new queue or keep the existing one. |
|
224 | + * |
|
225 | + * @return EE_Messages_Queue |
|
226 | + */ |
|
227 | + public function batch_send_from_queue($messages = array(), $clear_queue = false) |
|
228 | + { |
|
229 | + |
|
230 | + if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
231 | + $this->_queue->execute(); |
|
232 | + $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
233 | + } else { |
|
234 | + // get messages to send and execute. |
|
235 | + $this->_queue->get_to_send_batch_and_send(); |
|
236 | + } |
|
237 | + // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed |
|
238 | + // messages in the queue and decide how to handle at that point. |
|
239 | + return $this->_queue; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the |
|
249 | + * EE_Message_Queue with the generated messages for the caller to work with. Note, this does NOT save the generated |
|
250 | + * messages in the queue, leaving it up to the caller to do so. |
|
251 | + * |
|
252 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
253 | + * @return EE_Messages_Queue |
|
254 | + */ |
|
255 | + public function generate_and_return($messages_to_generate) |
|
256 | + { |
|
257 | + $this->_init_queue_and_generator(); |
|
258 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
259 | + return $this->_generator->generate(false); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Executes the generator generate method on the current internal queue, and returns the generated queue. |
|
267 | + * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false). |
|
268 | + * @return EE_Messages_Queue |
|
269 | + */ |
|
270 | + public function generate_queue($persist = true) |
|
271 | + { |
|
272 | + return $this->_generator->generate($persist); |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * Queue for generation. Note this does NOT persist to the db. Client code should call get_message_repository()->save() if desire |
|
280 | - * to persist. This method is provided to client code to decide what it wants to do with queued messages for generation. |
|
281 | - * @param EE_Message_To_Generate $message_to_generate |
|
282 | - * @param bool $test_send Whether this item is for a test send or not. |
|
283 | - * @return EE_Messages_Queue |
|
284 | - */ |
|
285 | - public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
286 | - { |
|
287 | - if ($message_to_generate->valid()) { |
|
288 | - $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue |
|
300 | - * and then persists to storage. |
|
301 | - * |
|
302 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
303 | - */ |
|
304 | - public function batch_queue_for_generation_and_persist($messages_to_generate) |
|
305 | - { |
|
306 | - $this->_init_queue_and_generator(); |
|
307 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
308 | - $this->_queue->save(); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation |
|
318 | - * queue. Does NOT persist to storage (unless there is an error. |
|
319 | - * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue() |
|
320 | - * |
|
321 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
322 | - */ |
|
323 | - public function batch_queue_for_generation_no_persist($messages_to_generate) |
|
324 | - { |
|
325 | - $this->_init_queue_and_generator(); |
|
326 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message |
|
334 | - * objects. |
|
335 | - * |
|
336 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
337 | - */ |
|
338 | - protected function _queue_for_generation_loop($messages_to_generate) |
|
339 | - { |
|
340 | - // make sure is in an array. |
|
341 | - if (! is_array($messages_to_generate)) { |
|
342 | - $messages_to_generate = array( $messages_to_generate ); |
|
343 | - } |
|
344 | - |
|
345 | - foreach ($messages_to_generate as $message_to_generate) { |
|
346 | - if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
347 | - $this->queue_for_generation($message_to_generate); |
|
348 | - } |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its |
|
358 | - * queued for sending). |
|
359 | - * @param EE_Message_To_Generate[] |
|
360 | - * @return EE_Messages_Queue |
|
361 | - */ |
|
362 | - public function generate_and_queue_for_sending($messages_to_generate) |
|
363 | - { |
|
364 | - $this->_init_queue_and_generator(); |
|
365 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
366 | - return $this->_generator->generate(true); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Generate for preview and execute right away. |
|
375 | - * |
|
376 | - * @param EE_Message_To_Generate $message_to_generate |
|
377 | - * @param bool $test_send Whether this is a test send or not. |
|
378 | - * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
|
379 | - */ |
|
380 | - public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
381 | - { |
|
382 | - if (! $message_to_generate->valid()) { |
|
383 | - EE_Error::add_error( |
|
384 | - __('Unable to generate preview because of invalid data', 'event_espresso'), |
|
385 | - __FILE__, |
|
386 | - __FUNCTION__, |
|
387 | - __LINE__ |
|
388 | - ); |
|
389 | - return false; |
|
390 | - } |
|
391 | - // just make sure preview is set on the $message_to_generate (in case client forgot) |
|
392 | - $message_to_generate->set_preview(true); |
|
393 | - $this->_init_queue_and_generator(); |
|
394 | - $this->queue_for_generation($message_to_generate, $test_send); |
|
395 | - $generated_queue = $this->_generator->generate(false); |
|
396 | - if ($generated_queue->execute(false)) { |
|
397 | - // the first queue item should be the preview |
|
398 | - $generated_queue->get_message_repository()->rewind(); |
|
399 | - if (! $generated_queue->get_message_repository()->valid()) { |
|
400 | - return $generated_queue; |
|
401 | - } |
|
402 | - return $generated_queue; |
|
403 | - } else { |
|
404 | - return false; |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * This queues for sending. |
|
411 | - * The messenger send now method is also verified to see if sending immediately is requested. |
|
412 | - * otherwise its just saved to the queue. |
|
413 | - * |
|
414 | - * @param EE_Message_To_Generate $message_to_generate |
|
415 | - * @return bool true or false for success. |
|
416 | - * @throws EE_Error |
|
417 | - * @throws EE_Error |
|
418 | - */ |
|
419 | - public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
|
420 | - { |
|
421 | - if (! $message_to_generate->valid()) { |
|
422 | - return false; |
|
423 | - } |
|
424 | - $this->_init_queue_and_generator(); |
|
425 | - $message = $message_to_generate->get_EE_Message(); |
|
426 | - $this->_queue->add($message); |
|
427 | - if ($message->send_now()) { |
|
428 | - $this->_queue->execute(false); |
|
429 | - } else { |
|
430 | - $this->_queue->save(); |
|
431 | - } |
|
432 | - return true; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * This generates and sends from the given EE_Message_To_Generate class immediately. |
|
438 | - * @param EE_Message_To_Generate $message_to_generate |
|
439 | - * @return EE_Messages_Queue | null |
|
440 | - */ |
|
441 | - public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
|
442 | - { |
|
443 | - if (! $message_to_generate->valid()) { |
|
444 | - return null; |
|
445 | - } |
|
446 | - // is there supposed to be a sending messenger for this message? |
|
447 | - if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
448 | - // make sure it's valid, but if it's not, |
|
449 | - // then set the value of $sending_messenger to an EE_Error object |
|
450 | - // so that downstream code can easily see that things went wrong. |
|
451 | - $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger |
|
452 | - ? $message_to_generate->sending_messenger() |
|
453 | - : new EE_Error( |
|
454 | - __( |
|
455 | - 'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.', |
|
456 | - 'event_espresso' |
|
457 | - ) |
|
458 | - ); |
|
459 | - } else { |
|
460 | - $sending_messenger = null; |
|
461 | - } |
|
462 | - |
|
463 | - if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
464 | - $this->_init_queue_and_generator(); |
|
465 | - $this->_queue->add($message_to_generate->get_EE_Message()); |
|
466 | - $this->_queue->execute(false, $sending_messenger); |
|
467 | - return $this->_queue; |
|
468 | - } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
469 | - $generated_queue = $this->generate_and_return(array( $message_to_generate )); |
|
470 | - $generated_queue->execute(false, $sending_messenger); |
|
471 | - return $generated_queue; |
|
472 | - } |
|
473 | - return null; |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Creates mtg objects for all active messengers and queues for generation. |
|
481 | - * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking |
|
482 | - * request to complete the action if the priority for the message requires immediate action. |
|
483 | - * @param string $message_type |
|
484 | - * @param mixed $data The data being used for generation. |
|
485 | - * @param bool $persist Whether to persist the queued messages to the db or not. |
|
486 | - */ |
|
487 | - public function generate_for_all_active_messengers($message_type, $data, $persist = true) |
|
488 | - { |
|
489 | - $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
490 | - if ($persist) { |
|
491 | - $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
492 | - $this->_queue->initiate_request_by_priority(); |
|
493 | - } else { |
|
494 | - $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * This simply loops through all active messengers and takes care of setting up the |
|
503 | - * EE_Message_To_Generate objects. |
|
504 | - * @param $message_type |
|
505 | - * @param $data |
|
506 | - * |
|
507 | - * @return EE_Message_To_Generate[] |
|
508 | - */ |
|
509 | - public function setup_mtgs_for_all_active_messengers($message_type, $data) |
|
510 | - { |
|
511 | - $messages_to_generate = array(); |
|
512 | - foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
513 | - $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
514 | - if ($message_to_generate->valid()) { |
|
515 | - $messages_to_generate[] = $message_to_generate; |
|
516 | - } |
|
517 | - } |
|
518 | - return $messages_to_generate; |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database |
|
524 | - * and send. |
|
525 | - * |
|
526 | - * @param array $message_ids |
|
527 | - * @throws EE_Error |
|
528 | - * @throws EE_Error |
|
529 | - */ |
|
530 | - public function setup_messages_from_ids_and_send($message_ids) |
|
531 | - { |
|
532 | - $this->_init_queue_and_generator(); |
|
533 | - $messages = EEM_Message::instance()->get_all(array( |
|
534 | - array( |
|
535 | - 'MSG_ID' => array( 'IN', $message_ids ), |
|
536 | - 'STS_ID' => array( |
|
537 | - 'IN', |
|
538 | - array_merge( |
|
539 | - EEM_Message::instance()->stati_indicating_sent(), |
|
540 | - array( EEM_Message::status_retry ) |
|
541 | - ), |
|
542 | - ), |
|
543 | - ), |
|
544 | - )); |
|
545 | - // set the Messages to resend. |
|
546 | - foreach ($messages as $message) { |
|
547 | - if ($message instanceof EE_Message) { |
|
548 | - $message->set_STS_ID(EEM_Message::status_resend); |
|
549 | - $this->_queue->add($message); |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - $this->_queue->initiate_request_by_priority('send'); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * This method checks for registration IDs in the request via the given key and creates the messages to generate |
|
559 | - * objects from them, then returns the array of messages to generate objects. |
|
560 | - * Note, this sets up registrations for the registration family of message types. |
|
561 | - * |
|
562 | - * @param string $registration_ids_key This is used to indicate what represents the registration ids in the request. |
|
563 | - * |
|
564 | - * @return EE_Message_To_Generate[]|bool |
|
565 | - * @throws EE_Error |
|
566 | - */ |
|
567 | - public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') |
|
568 | - { |
|
569 | - /** @var RequestInterface $request */ |
|
570 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
571 | - $regs_to_send = array(); |
|
572 | - $regIDs = $request->getRequestParam($registration_ids_key); |
|
573 | - if (empty($regIDs)) { |
|
574 | - EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
575 | - return false; |
|
576 | - } |
|
577 | - |
|
578 | - // make sure is an array |
|
579 | - $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs ); |
|
580 | - |
|
581 | - foreach ($regIDs as $regID) { |
|
582 | - $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
583 | - if (! $reg instanceof EE_Registration) { |
|
584 | - EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); |
|
585 | - return false; |
|
586 | - } |
|
587 | - $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
588 | - } |
|
589 | - |
|
590 | - $messages_to_generate = array(); |
|
591 | - |
|
592 | - foreach ($regs_to_send as $status_group) { |
|
593 | - foreach ($status_group as $status_id => $registrations) { |
|
594 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
|
595 | - if (! $message_type) { |
|
596 | - continue; |
|
597 | - } |
|
598 | - $messages_to_generate = array_merge( |
|
599 | - $messages_to_generate, |
|
600 | - $this->setup_mtgs_for_all_active_messengers( |
|
601 | - $message_type, |
|
602 | - array( $registrations, $status_id ) |
|
603 | - ) |
|
604 | - ); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - return $messages_to_generate; |
|
609 | - } |
|
278 | + /** |
|
279 | + * Queue for generation. Note this does NOT persist to the db. Client code should call get_message_repository()->save() if desire |
|
280 | + * to persist. This method is provided to client code to decide what it wants to do with queued messages for generation. |
|
281 | + * @param EE_Message_To_Generate $message_to_generate |
|
282 | + * @param bool $test_send Whether this item is for a test send or not. |
|
283 | + * @return EE_Messages_Queue |
|
284 | + */ |
|
285 | + public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
286 | + { |
|
287 | + if ($message_to_generate->valid()) { |
|
288 | + $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue |
|
300 | + * and then persists to storage. |
|
301 | + * |
|
302 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
303 | + */ |
|
304 | + public function batch_queue_for_generation_and_persist($messages_to_generate) |
|
305 | + { |
|
306 | + $this->_init_queue_and_generator(); |
|
307 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
308 | + $this->_queue->save(); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation |
|
318 | + * queue. Does NOT persist to storage (unless there is an error. |
|
319 | + * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue() |
|
320 | + * |
|
321 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
322 | + */ |
|
323 | + public function batch_queue_for_generation_no_persist($messages_to_generate) |
|
324 | + { |
|
325 | + $this->_init_queue_and_generator(); |
|
326 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message |
|
334 | + * objects. |
|
335 | + * |
|
336 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
337 | + */ |
|
338 | + protected function _queue_for_generation_loop($messages_to_generate) |
|
339 | + { |
|
340 | + // make sure is in an array. |
|
341 | + if (! is_array($messages_to_generate)) { |
|
342 | + $messages_to_generate = array( $messages_to_generate ); |
|
343 | + } |
|
344 | + |
|
345 | + foreach ($messages_to_generate as $message_to_generate) { |
|
346 | + if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
347 | + $this->queue_for_generation($message_to_generate); |
|
348 | + } |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its |
|
358 | + * queued for sending). |
|
359 | + * @param EE_Message_To_Generate[] |
|
360 | + * @return EE_Messages_Queue |
|
361 | + */ |
|
362 | + public function generate_and_queue_for_sending($messages_to_generate) |
|
363 | + { |
|
364 | + $this->_init_queue_and_generator(); |
|
365 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
366 | + return $this->_generator->generate(true); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Generate for preview and execute right away. |
|
375 | + * |
|
376 | + * @param EE_Message_To_Generate $message_to_generate |
|
377 | + * @param bool $test_send Whether this is a test send or not. |
|
378 | + * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
|
379 | + */ |
|
380 | + public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
381 | + { |
|
382 | + if (! $message_to_generate->valid()) { |
|
383 | + EE_Error::add_error( |
|
384 | + __('Unable to generate preview because of invalid data', 'event_espresso'), |
|
385 | + __FILE__, |
|
386 | + __FUNCTION__, |
|
387 | + __LINE__ |
|
388 | + ); |
|
389 | + return false; |
|
390 | + } |
|
391 | + // just make sure preview is set on the $message_to_generate (in case client forgot) |
|
392 | + $message_to_generate->set_preview(true); |
|
393 | + $this->_init_queue_and_generator(); |
|
394 | + $this->queue_for_generation($message_to_generate, $test_send); |
|
395 | + $generated_queue = $this->_generator->generate(false); |
|
396 | + if ($generated_queue->execute(false)) { |
|
397 | + // the first queue item should be the preview |
|
398 | + $generated_queue->get_message_repository()->rewind(); |
|
399 | + if (! $generated_queue->get_message_repository()->valid()) { |
|
400 | + return $generated_queue; |
|
401 | + } |
|
402 | + return $generated_queue; |
|
403 | + } else { |
|
404 | + return false; |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * This queues for sending. |
|
411 | + * The messenger send now method is also verified to see if sending immediately is requested. |
|
412 | + * otherwise its just saved to the queue. |
|
413 | + * |
|
414 | + * @param EE_Message_To_Generate $message_to_generate |
|
415 | + * @return bool true or false for success. |
|
416 | + * @throws EE_Error |
|
417 | + * @throws EE_Error |
|
418 | + */ |
|
419 | + public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
|
420 | + { |
|
421 | + if (! $message_to_generate->valid()) { |
|
422 | + return false; |
|
423 | + } |
|
424 | + $this->_init_queue_and_generator(); |
|
425 | + $message = $message_to_generate->get_EE_Message(); |
|
426 | + $this->_queue->add($message); |
|
427 | + if ($message->send_now()) { |
|
428 | + $this->_queue->execute(false); |
|
429 | + } else { |
|
430 | + $this->_queue->save(); |
|
431 | + } |
|
432 | + return true; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * This generates and sends from the given EE_Message_To_Generate class immediately. |
|
438 | + * @param EE_Message_To_Generate $message_to_generate |
|
439 | + * @return EE_Messages_Queue | null |
|
440 | + */ |
|
441 | + public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
|
442 | + { |
|
443 | + if (! $message_to_generate->valid()) { |
|
444 | + return null; |
|
445 | + } |
|
446 | + // is there supposed to be a sending messenger for this message? |
|
447 | + if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
448 | + // make sure it's valid, but if it's not, |
|
449 | + // then set the value of $sending_messenger to an EE_Error object |
|
450 | + // so that downstream code can easily see that things went wrong. |
|
451 | + $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger |
|
452 | + ? $message_to_generate->sending_messenger() |
|
453 | + : new EE_Error( |
|
454 | + __( |
|
455 | + 'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.', |
|
456 | + 'event_espresso' |
|
457 | + ) |
|
458 | + ); |
|
459 | + } else { |
|
460 | + $sending_messenger = null; |
|
461 | + } |
|
462 | + |
|
463 | + if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
464 | + $this->_init_queue_and_generator(); |
|
465 | + $this->_queue->add($message_to_generate->get_EE_Message()); |
|
466 | + $this->_queue->execute(false, $sending_messenger); |
|
467 | + return $this->_queue; |
|
468 | + } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
469 | + $generated_queue = $this->generate_and_return(array( $message_to_generate )); |
|
470 | + $generated_queue->execute(false, $sending_messenger); |
|
471 | + return $generated_queue; |
|
472 | + } |
|
473 | + return null; |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Creates mtg objects for all active messengers and queues for generation. |
|
481 | + * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking |
|
482 | + * request to complete the action if the priority for the message requires immediate action. |
|
483 | + * @param string $message_type |
|
484 | + * @param mixed $data The data being used for generation. |
|
485 | + * @param bool $persist Whether to persist the queued messages to the db or not. |
|
486 | + */ |
|
487 | + public function generate_for_all_active_messengers($message_type, $data, $persist = true) |
|
488 | + { |
|
489 | + $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
490 | + if ($persist) { |
|
491 | + $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
492 | + $this->_queue->initiate_request_by_priority(); |
|
493 | + } else { |
|
494 | + $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * This simply loops through all active messengers and takes care of setting up the |
|
503 | + * EE_Message_To_Generate objects. |
|
504 | + * @param $message_type |
|
505 | + * @param $data |
|
506 | + * |
|
507 | + * @return EE_Message_To_Generate[] |
|
508 | + */ |
|
509 | + public function setup_mtgs_for_all_active_messengers($message_type, $data) |
|
510 | + { |
|
511 | + $messages_to_generate = array(); |
|
512 | + foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
513 | + $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
514 | + if ($message_to_generate->valid()) { |
|
515 | + $messages_to_generate[] = $message_to_generate; |
|
516 | + } |
|
517 | + } |
|
518 | + return $messages_to_generate; |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database |
|
524 | + * and send. |
|
525 | + * |
|
526 | + * @param array $message_ids |
|
527 | + * @throws EE_Error |
|
528 | + * @throws EE_Error |
|
529 | + */ |
|
530 | + public function setup_messages_from_ids_and_send($message_ids) |
|
531 | + { |
|
532 | + $this->_init_queue_and_generator(); |
|
533 | + $messages = EEM_Message::instance()->get_all(array( |
|
534 | + array( |
|
535 | + 'MSG_ID' => array( 'IN', $message_ids ), |
|
536 | + 'STS_ID' => array( |
|
537 | + 'IN', |
|
538 | + array_merge( |
|
539 | + EEM_Message::instance()->stati_indicating_sent(), |
|
540 | + array( EEM_Message::status_retry ) |
|
541 | + ), |
|
542 | + ), |
|
543 | + ), |
|
544 | + )); |
|
545 | + // set the Messages to resend. |
|
546 | + foreach ($messages as $message) { |
|
547 | + if ($message instanceof EE_Message) { |
|
548 | + $message->set_STS_ID(EEM_Message::status_resend); |
|
549 | + $this->_queue->add($message); |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + $this->_queue->initiate_request_by_priority('send'); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * This method checks for registration IDs in the request via the given key and creates the messages to generate |
|
559 | + * objects from them, then returns the array of messages to generate objects. |
|
560 | + * Note, this sets up registrations for the registration family of message types. |
|
561 | + * |
|
562 | + * @param string $registration_ids_key This is used to indicate what represents the registration ids in the request. |
|
563 | + * |
|
564 | + * @return EE_Message_To_Generate[]|bool |
|
565 | + * @throws EE_Error |
|
566 | + */ |
|
567 | + public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') |
|
568 | + { |
|
569 | + /** @var RequestInterface $request */ |
|
570 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
571 | + $regs_to_send = array(); |
|
572 | + $regIDs = $request->getRequestParam($registration_ids_key); |
|
573 | + if (empty($regIDs)) { |
|
574 | + EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
575 | + return false; |
|
576 | + } |
|
577 | + |
|
578 | + // make sure is an array |
|
579 | + $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs ); |
|
580 | + |
|
581 | + foreach ($regIDs as $regID) { |
|
582 | + $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
583 | + if (! $reg instanceof EE_Registration) { |
|
584 | + EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); |
|
585 | + return false; |
|
586 | + } |
|
587 | + $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
588 | + } |
|
589 | + |
|
590 | + $messages_to_generate = array(); |
|
591 | + |
|
592 | + foreach ($regs_to_send as $status_group) { |
|
593 | + foreach ($status_group as $status_id => $registrations) { |
|
594 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
|
595 | + if (! $message_type) { |
|
596 | + continue; |
|
597 | + } |
|
598 | + $messages_to_generate = array_merge( |
|
599 | + $messages_to_generate, |
|
600 | + $this->setup_mtgs_for_all_active_messengers( |
|
601 | + $message_type, |
|
602 | + array( $registrations, $status_id ) |
|
603 | + ) |
|
604 | + ); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + return $messages_to_generate; |
|
609 | + } |
|
610 | 610 | } |
@@ -14,218 +14,218 @@ |
||
14 | 14 | class EE_Messages_Scheduler extends EE_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Number of seconds between batch sends/generates on the cron job. |
|
19 | - * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
20 | - * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
21 | - * |
|
22 | - * @type int |
|
23 | - */ |
|
24 | - const message_cron_schedule = 300; |
|
25 | - |
|
26 | - /** |
|
27 | - * Constructor |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - // register tasks (and make sure only registered once). |
|
32 | - if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
33 | - add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
|
34 | - } |
|
35 | - |
|
36 | - // register callbacks for scheduled events (but make sure they are set only once). |
|
37 | - if (! has_action( |
|
38 | - 'AHEE__EE_Messages_Scheduler__generation', |
|
39 | - array('EE_Messages_Scheduler', 'batch_generation') |
|
40 | - )) { |
|
41 | - add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
|
42 | - add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending')); |
|
43 | - add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup')); |
|
44 | - } |
|
45 | - |
|
46 | - // add custom schedules |
|
47 | - add_filter('cron_schedules', array($this, 'custom_schedules')); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Add custom schedules for wp_cron |
|
53 | - * |
|
54 | - * @param $schedules |
|
55 | - */ |
|
56 | - public function custom_schedules($schedules) |
|
57 | - { |
|
58 | - $schedules['ee_message_cron'] = array( |
|
59 | - 'interval' => self::message_cron_schedule, |
|
60 | - 'display' => __( |
|
61 | - 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
62 | - 'event_espresso' |
|
63 | - ), |
|
64 | - ); |
|
65 | - return $schedules; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
|
71 | - * remove. |
|
72 | - * |
|
73 | - * @param array $tasks already existing scheduled tasks |
|
74 | - * @return array |
|
75 | - * @throws EE_Error |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function register_scheduled_tasks($tasks) |
|
79 | - { |
|
80 | - EE_Registry::instance()->load_helper('DTT_Helper'); |
|
81 | - $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
|
82 | - $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
|
83 | - $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily'); |
|
84 | - return $tasks; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * This initiates a non-blocking separate request to execute on a scheduled task. |
|
90 | - * Note: The EED_Messages module has the handlers for these requests. |
|
91 | - * |
|
92 | - * @param string $task The task the request is being generated for. |
|
93 | - */ |
|
94 | - public static function initiate_scheduled_non_blocking_request($task) |
|
95 | - { |
|
96 | - if (apply_filters( |
|
97 | - 'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
|
98 | - true |
|
99 | - )) { |
|
100 | - $request_url = add_query_arg( |
|
101 | - array_merge( |
|
102 | - array('ee' => 'msg_cron_trigger'), |
|
103 | - EE_Messages_Scheduler::get_request_params($task) |
|
104 | - ), |
|
105 | - site_url() |
|
106 | - ); |
|
107 | - $request_args = array( |
|
108 | - 'timeout' => 300, |
|
109 | - 'blocking' => (defined('DOING_CRON') && DOING_CRON) |
|
110 | - || (defined('DOING_AJAX') && DOING_AJAX), |
|
111 | - 'sslverify' => false, |
|
112 | - 'redirection' => 10, |
|
113 | - ); |
|
114 | - $response = wp_remote_get($request_url, $request_args); |
|
115 | - if (is_wp_error($response)) { |
|
116 | - trigger_error($response->get_error_message()); |
|
117 | - } |
|
118 | - } else { |
|
119 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron($task); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This returns |
|
126 | - * the request params used for a scheduled message task request. |
|
127 | - * |
|
128 | - * @param string $task The task the request is for. |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - public static function get_request_params($task) |
|
132 | - { |
|
133 | - // transient is used for flood control on msg_cron_trigger requests |
|
134 | - $transient_key = 'ee_trans_' . uniqid($task); |
|
135 | - set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
|
136 | - return array( |
|
137 | - 'type' => $task, |
|
138 | - 'key' => $transient_key, |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
|
145 | - * |
|
146 | - * @param string $task The task the request is being generated for. |
|
147 | - */ |
|
148 | - public static function initiate_immediate_request_on_cron($task) |
|
149 | - { |
|
150 | - /** @var RequestInterface $request */ |
|
151 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
152 | - $request_args = EE_Messages_Scheduler::get_request_params($task); |
|
153 | - // set those request args in the request so it gets picked up |
|
154 | - foreach ($request_args as $request_key => $request_value) { |
|
155 | - $request->setRequestParam($request_key, $request_value); |
|
156 | - } |
|
157 | - EED_Messages::instance()->run_cron(); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
|
163 | - */ |
|
164 | - public static function batch_generation() |
|
165 | - { |
|
166 | - /** |
|
167 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
168 | - */ |
|
169 | - if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
170 | - || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
171 | - ) { |
|
172 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
|
179 | - */ |
|
180 | - public static function batch_sending() |
|
181 | - { |
|
182 | - /** |
|
183 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
184 | - */ |
|
185 | - if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
186 | - || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
187 | - ) { |
|
188 | - EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action. |
|
195 | - * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete |
|
196 | - * permanently from the database messages that have a MSG_modified date older than 30 days. |
|
197 | - * |
|
198 | - * @throws EE_Error |
|
199 | - * @throws EE_Error |
|
200 | - */ |
|
201 | - public static function cleanup() |
|
202 | - { |
|
203 | - // First, confirm that the generation and sending EE_Messages_Scheduler crons are |
|
204 | - // set and reschedule them if they are not. |
|
205 | - $message_crons_to_check = array( |
|
206 | - 'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron', |
|
207 | - 'AHEE__EE_Messages_Scheduler__sending' => 'ee_message_cron', |
|
208 | - ); |
|
209 | - foreach ($message_crons_to_check as $hook_name => $frequency) { |
|
210 | - if (! wp_next_scheduled($hook_name)) { |
|
211 | - wp_schedule_event(time(), $frequency, $hook_name); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - // check if user has cleanup turned on or if we're in maintenance mode. If in maintenance mode we'll wait |
|
216 | - // until the next scheduled event. |
|
217 | - if (! EE_Registry::instance()->CFG->messages->delete_threshold |
|
218 | - || ! EE_Maintenance_Mode::instance()->models_can_query() |
|
219 | - ) { |
|
220 | - return; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling |
|
225 | - * of deleting messages. |
|
226 | - */ |
|
227 | - if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) { |
|
228 | - EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold); |
|
229 | - } |
|
230 | - } |
|
17 | + /** |
|
18 | + * Number of seconds between batch sends/generates on the cron job. |
|
19 | + * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
20 | + * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
21 | + * |
|
22 | + * @type int |
|
23 | + */ |
|
24 | + const message_cron_schedule = 300; |
|
25 | + |
|
26 | + /** |
|
27 | + * Constructor |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + // register tasks (and make sure only registered once). |
|
32 | + if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) { |
|
33 | + add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10); |
|
34 | + } |
|
35 | + |
|
36 | + // register callbacks for scheduled events (but make sure they are set only once). |
|
37 | + if (! has_action( |
|
38 | + 'AHEE__EE_Messages_Scheduler__generation', |
|
39 | + array('EE_Messages_Scheduler', 'batch_generation') |
|
40 | + )) { |
|
41 | + add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation')); |
|
42 | + add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending')); |
|
43 | + add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup')); |
|
44 | + } |
|
45 | + |
|
46 | + // add custom schedules |
|
47 | + add_filter('cron_schedules', array($this, 'custom_schedules')); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Add custom schedules for wp_cron |
|
53 | + * |
|
54 | + * @param $schedules |
|
55 | + */ |
|
56 | + public function custom_schedules($schedules) |
|
57 | + { |
|
58 | + $schedules['ee_message_cron'] = array( |
|
59 | + 'interval' => self::message_cron_schedule, |
|
60 | + 'display' => __( |
|
61 | + 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
62 | + 'event_espresso' |
|
63 | + ), |
|
64 | + ); |
|
65 | + return $schedules; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and |
|
71 | + * remove. |
|
72 | + * |
|
73 | + * @param array $tasks already existing scheduled tasks |
|
74 | + * @return array |
|
75 | + * @throws EE_Error |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function register_scheduled_tasks($tasks) |
|
79 | + { |
|
80 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
81 | + $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron'; |
|
82 | + $tasks['AHEE__EE_Messages_Scheduler__sending'] = 'ee_message_cron'; |
|
83 | + $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily'); |
|
84 | + return $tasks; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * This initiates a non-blocking separate request to execute on a scheduled task. |
|
90 | + * Note: The EED_Messages module has the handlers for these requests. |
|
91 | + * |
|
92 | + * @param string $task The task the request is being generated for. |
|
93 | + */ |
|
94 | + public static function initiate_scheduled_non_blocking_request($task) |
|
95 | + { |
|
96 | + if (apply_filters( |
|
97 | + 'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request', |
|
98 | + true |
|
99 | + )) { |
|
100 | + $request_url = add_query_arg( |
|
101 | + array_merge( |
|
102 | + array('ee' => 'msg_cron_trigger'), |
|
103 | + EE_Messages_Scheduler::get_request_params($task) |
|
104 | + ), |
|
105 | + site_url() |
|
106 | + ); |
|
107 | + $request_args = array( |
|
108 | + 'timeout' => 300, |
|
109 | + 'blocking' => (defined('DOING_CRON') && DOING_CRON) |
|
110 | + || (defined('DOING_AJAX') && DOING_AJAX), |
|
111 | + 'sslverify' => false, |
|
112 | + 'redirection' => 10, |
|
113 | + ); |
|
114 | + $response = wp_remote_get($request_url, $request_args); |
|
115 | + if (is_wp_error($response)) { |
|
116 | + trigger_error($response->get_error_message()); |
|
117 | + } |
|
118 | + } else { |
|
119 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron($task); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This returns |
|
126 | + * the request params used for a scheduled message task request. |
|
127 | + * |
|
128 | + * @param string $task The task the request is for. |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + public static function get_request_params($task) |
|
132 | + { |
|
133 | + // transient is used for flood control on msg_cron_trigger requests |
|
134 | + $transient_key = 'ee_trans_' . uniqid($task); |
|
135 | + set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS); |
|
136 | + return array( |
|
137 | + 'type' => $task, |
|
138 | + 'key' => $transient_key, |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * This is used to execute an immediate call to the run_cron task performed by EED_Messages |
|
145 | + * |
|
146 | + * @param string $task The task the request is being generated for. |
|
147 | + */ |
|
148 | + public static function initiate_immediate_request_on_cron($task) |
|
149 | + { |
|
150 | + /** @var RequestInterface $request */ |
|
151 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
152 | + $request_args = EE_Messages_Scheduler::get_request_params($task); |
|
153 | + // set those request args in the request so it gets picked up |
|
154 | + foreach ($request_args as $request_key => $request_value) { |
|
155 | + $request->setRequestParam($request_key, $request_value); |
|
156 | + } |
|
157 | + EED_Messages::instance()->run_cron(); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event |
|
163 | + */ |
|
164 | + public static function batch_generation() |
|
165 | + { |
|
166 | + /** |
|
167 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
168 | + */ |
|
169 | + if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
170 | + || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
171 | + ) { |
|
172 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate'); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Callback for scheduled AHEE__EE_Messages_Scheduler__sending |
|
179 | + */ |
|
180 | + public static function batch_sending() |
|
181 | + { |
|
182 | + /** |
|
183 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority() |
|
184 | + */ |
|
185 | + if (! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
186 | + || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
187 | + ) { |
|
188 | + EE_Messages_Scheduler::initiate_immediate_request_on_cron('send'); |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action. |
|
195 | + * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete |
|
196 | + * permanently from the database messages that have a MSG_modified date older than 30 days. |
|
197 | + * |
|
198 | + * @throws EE_Error |
|
199 | + * @throws EE_Error |
|
200 | + */ |
|
201 | + public static function cleanup() |
|
202 | + { |
|
203 | + // First, confirm that the generation and sending EE_Messages_Scheduler crons are |
|
204 | + // set and reschedule them if they are not. |
|
205 | + $message_crons_to_check = array( |
|
206 | + 'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron', |
|
207 | + 'AHEE__EE_Messages_Scheduler__sending' => 'ee_message_cron', |
|
208 | + ); |
|
209 | + foreach ($message_crons_to_check as $hook_name => $frequency) { |
|
210 | + if (! wp_next_scheduled($hook_name)) { |
|
211 | + wp_schedule_event(time(), $frequency, $hook_name); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + // check if user has cleanup turned on or if we're in maintenance mode. If in maintenance mode we'll wait |
|
216 | + // until the next scheduled event. |
|
217 | + if (! EE_Registry::instance()->CFG->messages->delete_threshold |
|
218 | + || ! EE_Maintenance_Mode::instance()->models_can_query() |
|
219 | + ) { |
|
220 | + return; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling |
|
225 | + * of deleting messages. |
|
226 | + */ |
|
227 | + if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) { |
|
228 | + EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | } |
@@ -20,110 +20,110 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * This messenger is used to send the generated message. |
|
25 | - * |
|
26 | - * @type EE_messenger |
|
27 | - */ |
|
28 | - protected $_sending_messenger = ''; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Holds the token from the request. |
|
33 | - * |
|
34 | - * @type string |
|
35 | - */ |
|
36 | - public $token = ''; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Constructor |
|
41 | - * This instantiates the object using arguments from the given request and calling the parent constructor. |
|
42 | - * |
|
43 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
44 | - * @param RequestInterface $request |
|
45 | - * @throws EE_Error |
|
46 | - */ |
|
47 | - public function __construct(EE_Message_Resource_Manager $message_resource_manager, RequestInterface $request) |
|
48 | - { |
|
49 | - parent::__construct( |
|
50 | - $request->getRequestParam('gen_msgr'), |
|
51 | - $request->getRequestParam('message_type'), |
|
52 | - [], |
|
53 | - $request->getRequestParam('context') |
|
54 | - ); |
|
55 | - if (! $this->valid()) { |
|
56 | - return; |
|
57 | - } |
|
58 | - $this->token = $request->getRequestParam('token'); |
|
59 | - $this->_sending_messenger = $message_resource_manager->get_active_messenger( |
|
60 | - $request->getRequestParam('snd_msgr') |
|
61 | - ); |
|
62 | - $this->_validate_request(); |
|
63 | - $this->_data = $this->_get_data_from_request($request->getRequestParam('id')); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return EE_messenger |
|
69 | - */ |
|
70 | - public function sending_messenger() |
|
71 | - { |
|
72 | - return $this->_sending_messenger; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * This validates set properties from the incoming request. |
|
78 | - * |
|
79 | - * @throws EE_Error |
|
80 | - */ |
|
81 | - protected function _validate_request() |
|
82 | - { |
|
83 | - if (! $this->_sending_messenger instanceof EE_messenger |
|
84 | - || ! $this->_messenger instanceof EE_messenger |
|
85 | - || ! $this->_message_type instanceof EE_message_type |
|
86 | - || empty($this->_context) |
|
87 | - || empty($this->token) |
|
88 | - ) { |
|
89 | - throw new EE_Error(__('The request for the "msg_url_trigger" route has a malformed url.', |
|
90 | - 'event_espresso')); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * This returns the data property according to what is expected from the request. |
|
97 | - * |
|
98 | - * @param $id |
|
99 | - * @return mixed (whatever the data is returned from the message type). |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - protected function _get_data_from_request($id) |
|
103 | - { |
|
104 | - // get the EE_Registration from the token |
|
105 | - /** @type EE_Registration $registration */ |
|
106 | - $registration = EEM_Registration::instance()->get_one([['REG_url_link' => $this->token]]); |
|
107 | - // if no registration then bail early. |
|
108 | - if (! $registration instanceof EE_Registration) { |
|
109 | - throw new EE_Error(__('Unable to complete the request because the token is invalid.', 'event_espresso')); |
|
110 | - } |
|
111 | - |
|
112 | - return $this->_get_data_to_use($registration, $id); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This uses the set message type to retrieve the data in the correct format as it came from the url. |
|
118 | - * |
|
119 | - * @param EE_Registration $registration |
|
120 | - * @param int $data_id This is sometimes used for secondary data a message type requires. |
|
121 | - * @return mixed Data prepared as needed for generating this message. |
|
122 | - * @throws EE_Error |
|
123 | - */ |
|
124 | - protected function _get_data_to_use($registration, $data_id) |
|
125 | - { |
|
126 | - // use incoming data from url to setup data for the message type requirements |
|
127 | - return $this->_message_type->get_data_for_context($this->_context, $registration, $data_id); |
|
128 | - } |
|
23 | + /** |
|
24 | + * This messenger is used to send the generated message. |
|
25 | + * |
|
26 | + * @type EE_messenger |
|
27 | + */ |
|
28 | + protected $_sending_messenger = ''; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Holds the token from the request. |
|
33 | + * |
|
34 | + * @type string |
|
35 | + */ |
|
36 | + public $token = ''; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Constructor |
|
41 | + * This instantiates the object using arguments from the given request and calling the parent constructor. |
|
42 | + * |
|
43 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
44 | + * @param RequestInterface $request |
|
45 | + * @throws EE_Error |
|
46 | + */ |
|
47 | + public function __construct(EE_Message_Resource_Manager $message_resource_manager, RequestInterface $request) |
|
48 | + { |
|
49 | + parent::__construct( |
|
50 | + $request->getRequestParam('gen_msgr'), |
|
51 | + $request->getRequestParam('message_type'), |
|
52 | + [], |
|
53 | + $request->getRequestParam('context') |
|
54 | + ); |
|
55 | + if (! $this->valid()) { |
|
56 | + return; |
|
57 | + } |
|
58 | + $this->token = $request->getRequestParam('token'); |
|
59 | + $this->_sending_messenger = $message_resource_manager->get_active_messenger( |
|
60 | + $request->getRequestParam('snd_msgr') |
|
61 | + ); |
|
62 | + $this->_validate_request(); |
|
63 | + $this->_data = $this->_get_data_from_request($request->getRequestParam('id')); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return EE_messenger |
|
69 | + */ |
|
70 | + public function sending_messenger() |
|
71 | + { |
|
72 | + return $this->_sending_messenger; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * This validates set properties from the incoming request. |
|
78 | + * |
|
79 | + * @throws EE_Error |
|
80 | + */ |
|
81 | + protected function _validate_request() |
|
82 | + { |
|
83 | + if (! $this->_sending_messenger instanceof EE_messenger |
|
84 | + || ! $this->_messenger instanceof EE_messenger |
|
85 | + || ! $this->_message_type instanceof EE_message_type |
|
86 | + || empty($this->_context) |
|
87 | + || empty($this->token) |
|
88 | + ) { |
|
89 | + throw new EE_Error(__('The request for the "msg_url_trigger" route has a malformed url.', |
|
90 | + 'event_espresso')); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * This returns the data property according to what is expected from the request. |
|
97 | + * |
|
98 | + * @param $id |
|
99 | + * @return mixed (whatever the data is returned from the message type). |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + protected function _get_data_from_request($id) |
|
103 | + { |
|
104 | + // get the EE_Registration from the token |
|
105 | + /** @type EE_Registration $registration */ |
|
106 | + $registration = EEM_Registration::instance()->get_one([['REG_url_link' => $this->token]]); |
|
107 | + // if no registration then bail early. |
|
108 | + if (! $registration instanceof EE_Registration) { |
|
109 | + throw new EE_Error(__('Unable to complete the request because the token is invalid.', 'event_espresso')); |
|
110 | + } |
|
111 | + |
|
112 | + return $this->_get_data_to_use($registration, $id); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This uses the set message type to retrieve the data in the correct format as it came from the url. |
|
118 | + * |
|
119 | + * @param EE_Registration $registration |
|
120 | + * @param int $data_id This is sometimes used for secondary data a message type requires. |
|
121 | + * @return mixed Data prepared as needed for generating this message. |
|
122 | + * @throws EE_Error |
|
123 | + */ |
|
124 | + protected function _get_data_to_use($registration, $data_id) |
|
125 | + { |
|
126 | + // use incoming data from url to setup data for the message type requirements |
|
127 | + return $this->_message_type->get_data_for_context($this->_context, $registration, $data_id); |
|
128 | + } |
|
129 | 129 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | [], |
53 | 53 | $request->getRequestParam('context') |
54 | 54 | ); |
55 | - if (! $this->valid()) { |
|
55 | + if ( ! $this->valid()) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | $this->token = $request->getRequestParam('token'); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | protected function _validate_request() |
82 | 82 | { |
83 | - if (! $this->_sending_messenger instanceof EE_messenger |
|
83 | + if ( ! $this->_sending_messenger instanceof EE_messenger |
|
84 | 84 | || ! $this->_messenger instanceof EE_messenger |
85 | 85 | || ! $this->_message_type instanceof EE_message_type |
86 | 86 | || empty($this->_context) |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | /** @type EE_Registration $registration */ |
106 | 106 | $registration = EEM_Registration::instance()->get_one([['REG_url_link' => $this->token]]); |
107 | 107 | // if no registration then bail early. |
108 | - if (! $registration instanceof EE_Registration) { |
|
108 | + if ( ! $registration instanceof EE_Registration) { |
|
109 | 109 | throw new EE_Error(__('Unable to complete the request because the token is invalid.', 'event_espresso')); |
110 | 110 | } |
111 | 111 |
@@ -18,371 +18,371 @@ |
||
18 | 18 | class Iframe |
19 | 19 | { |
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | * HTML for notices and ajax gif |
23 | 23 | * @var string $title |
24 | 24 | */ |
25 | - protected $title = ''; |
|
25 | + protected $title = ''; |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | * HTML for the content being displayed |
29 | 29 | * @var string $content |
30 | 30 | */ |
31 | - protected $content = ''; |
|
31 | + protected $content = ''; |
|
32 | 32 | |
33 | - /* |
|
33 | + /* |
|
34 | 34 | * whether or not to call wp_head() and wp_footer() |
35 | 35 | * @var boolean $enqueue_wp_assets |
36 | 36 | */ |
37 | - protected $enqueue_wp_assets = false; |
|
37 | + protected $enqueue_wp_assets = false; |
|
38 | 38 | |
39 | - /* |
|
39 | + /* |
|
40 | 40 | * an array of CSS URLs |
41 | 41 | * @var array $css |
42 | 42 | */ |
43 | - protected $css = array(); |
|
43 | + protected $css = array(); |
|
44 | 44 | |
45 | - /* |
|
45 | + /* |
|
46 | 46 | * an array of JS URLs to be set in the HTML header. |
47 | 47 | * @var array $header_js |
48 | 48 | */ |
49 | - protected $header_js = array(); |
|
49 | + protected $header_js = array(); |
|
50 | 50 | |
51 | - /* |
|
51 | + /* |
|
52 | 52 | * an array of additional attributes to be added to <script> tags for header JS |
53 | 53 | * @var array $footer_js |
54 | 54 | */ |
55 | - protected $header_js_attributes = array(); |
|
55 | + protected $header_js_attributes = array(); |
|
56 | 56 | |
57 | - /* |
|
57 | + /* |
|
58 | 58 | * an array of JS URLs to be displayed before the HTML </body> tag |
59 | 59 | * @var array $footer_js |
60 | 60 | */ |
61 | - protected $footer_js = array(); |
|
61 | + protected $footer_js = array(); |
|
62 | 62 | |
63 | - /* |
|
63 | + /* |
|
64 | 64 | * an array of additional attributes to be added to <script> tags for footer JS |
65 | 65 | * @var array $footer_js_attributes |
66 | 66 | */ |
67 | - protected $footer_js_attributes = array(); |
|
67 | + protected $footer_js_attributes = array(); |
|
68 | 68 | |
69 | - /* |
|
69 | + /* |
|
70 | 70 | * an array of JSON vars to be set in the HTML header. |
71 | 71 | * @var array $localized_vars |
72 | 72 | */ |
73 | - protected $localized_vars = array(); |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Iframe constructor |
|
78 | - * |
|
79 | - * @param string $title |
|
80 | - * @param string $content |
|
81 | - * @throws DomainException |
|
82 | - */ |
|
83 | - public function __construct($title, $content) |
|
84 | - { |
|
85 | - global $wp_version; |
|
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | - define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | - } |
|
89 | - $this->setContent($content); |
|
90 | - $this->setTitle($title); |
|
91 | - $this->addStylesheets( |
|
92 | - apply_filters( |
|
93 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | - array( |
|
95 | - 'site_theme' => get_stylesheet_directory_uri() |
|
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | - ), |
|
101 | - $this |
|
102 | - ) |
|
103 | - ); |
|
104 | - $this->addScripts( |
|
105 | - apply_filters( |
|
106 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | - array( |
|
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | - ), |
|
112 | - $this |
|
113 | - ) |
|
114 | - ); |
|
115 | - if (apply_filters( |
|
116 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
117 | - false |
|
118 | - )) { |
|
119 | - $this->addStylesheets( |
|
120 | - apply_filters( |
|
121 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
122 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
123 | - $this |
|
124 | - ) |
|
125 | - ); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $title |
|
132 | - * @throws DomainException |
|
133 | - */ |
|
134 | - public function setTitle($title) |
|
135 | - { |
|
136 | - if (empty($title)) { |
|
137 | - throw new DomainException( |
|
138 | - esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
139 | - ); |
|
140 | - } |
|
141 | - $this->title = $title; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string $content |
|
147 | - * @throws DomainException |
|
148 | - */ |
|
149 | - public function setContent($content) |
|
150 | - { |
|
151 | - if (empty($content)) { |
|
152 | - throw new DomainException( |
|
153 | - esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
154 | - ); |
|
155 | - } |
|
156 | - $this->content = $content; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param boolean $enqueue_wp_assets |
|
162 | - */ |
|
163 | - public function setEnqueueWpAssets($enqueue_wp_assets) |
|
164 | - { |
|
165 | - $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param array $stylesheets |
|
171 | - * @throws DomainException |
|
172 | - */ |
|
173 | - public function addStylesheets(array $stylesheets) |
|
174 | - { |
|
175 | - if (empty($stylesheets)) { |
|
176 | - throw new DomainException( |
|
177 | - esc_html__( |
|
178 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
179 | - 'event_espresso' |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - foreach ($stylesheets as $handle => $stylesheet) { |
|
184 | - $this->css[ $handle ] = $stylesheet; |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @param array $scripts |
|
191 | - * @param bool $add_to_header |
|
192 | - * @throws DomainException |
|
193 | - */ |
|
194 | - public function addScripts(array $scripts, $add_to_header = false) |
|
195 | - { |
|
196 | - if (empty($scripts)) { |
|
197 | - throw new DomainException( |
|
198 | - esc_html__( |
|
199 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
200 | - 'event_espresso' |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - foreach ($scripts as $handle => $script) { |
|
205 | - if ($add_to_header) { |
|
206 | - $this->header_js[ $handle ] = $script; |
|
207 | - } else { |
|
208 | - $this->footer_js[ $handle ] = $script; |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @param array $script_attributes |
|
216 | - * @param bool $add_to_header |
|
217 | - * @throws DomainException |
|
218 | - */ |
|
219 | - public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
220 | - { |
|
221 | - if (empty($script_attributes)) { |
|
222 | - throw new DomainException( |
|
223 | - esc_html__( |
|
224 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
225 | - 'event_espresso' |
|
226 | - ) |
|
227 | - ); |
|
228 | - } |
|
229 | - foreach ($script_attributes as $handle => $script_attribute) { |
|
230 | - if ($add_to_header) { |
|
231 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
232 | - } else { |
|
233 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * @param array $vars |
|
241 | - * @param string $var_name |
|
242 | - * @throws DomainException |
|
243 | - */ |
|
244 | - public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
245 | - { |
|
246 | - if (empty($vars)) { |
|
247 | - throw new DomainException( |
|
248 | - esc_html__( |
|
249 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
250 | - 'event_espresso' |
|
251 | - ) |
|
252 | - ); |
|
253 | - } |
|
254 | - foreach ($vars as $handle => $var) { |
|
255 | - if ($var_name === 'eei18n') { |
|
256 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
257 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
258 | - $this->localized_vars[ $var_name ] = $var; |
|
259 | - } else { |
|
260 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | - $this->localized_vars[ $var_name ] = array(); |
|
262 | - } |
|
263 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $utm_content |
|
271 | - * @throws DomainException |
|
272 | - */ |
|
273 | - public function display($utm_content = '') |
|
274 | - { |
|
275 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
276 | - '', |
|
277 | - '', |
|
278 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
279 | - ); |
|
280 | - EE_System::do_not_cache(); |
|
281 | - echo $this->getTemplate(); |
|
282 | - exit; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @return string |
|
288 | - * @throws DomainException |
|
289 | - */ |
|
290 | - public function getTemplate() |
|
291 | - { |
|
292 | - return EEH_Template::display_template( |
|
293 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
294 | - array( |
|
295 | - 'title' => apply_filters( |
|
296 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
297 | - $this->title, |
|
298 | - $this |
|
299 | - ), |
|
300 | - 'content' => apply_filters( |
|
301 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
302 | - $this->content, |
|
303 | - $this |
|
304 | - ), |
|
305 | - 'enqueue_wp_assets' => apply_filters( |
|
306 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
307 | - $this->enqueue_wp_assets, |
|
308 | - $this |
|
309 | - ), |
|
310 | - 'css' => (array) apply_filters( |
|
311 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
312 | - $this->css, |
|
313 | - $this |
|
314 | - ), |
|
315 | - 'header_js' => (array) apply_filters( |
|
316 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
317 | - $this->header_js, |
|
318 | - $this |
|
319 | - ), |
|
320 | - 'header_js_attributes' => (array) apply_filters( |
|
321 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
322 | - $this->header_js_attributes, |
|
323 | - $this |
|
324 | - ), |
|
325 | - 'footer_js' => (array) apply_filters( |
|
326 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
327 | - $this->footer_js, |
|
328 | - $this |
|
329 | - ), |
|
330 | - 'footer_js_attributes' => (array) apply_filters( |
|
331 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
332 | - $this->footer_js_attributes, |
|
333 | - $this |
|
334 | - ), |
|
335 | - 'eei18n' => apply_filters( |
|
336 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
337 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
338 | - $this |
|
339 | - ), |
|
340 | - 'notices' => EEH_Template::display_template( |
|
341 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
342 | - array(), |
|
343 | - true |
|
344 | - ), |
|
345 | - ), |
|
346 | - true, |
|
347 | - true |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * localizeJsonVars |
|
354 | - * |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function localizeJsonVars() |
|
358 | - { |
|
359 | - $JSON = ''; |
|
360 | - foreach ($this->localized_vars as $var_name => $vars) { |
|
361 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
362 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
363 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
364 | - $JSON .= '; /* ]]> */'; |
|
365 | - } |
|
366 | - return $JSON; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param bool|int|float|string|array $var |
|
372 | - * @return array|string|null |
|
373 | - */ |
|
374 | - public function encodeJsonVars($var) |
|
375 | - { |
|
376 | - if (is_array($var)) { |
|
377 | - $localized_vars = array(); |
|
378 | - foreach ((array) $var as $key => $value) { |
|
379 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
380 | - } |
|
381 | - return $localized_vars; |
|
382 | - } |
|
383 | - if (is_scalar($var)) { |
|
384 | - return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
385 | - } |
|
386 | - return null; |
|
387 | - } |
|
73 | + protected $localized_vars = array(); |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Iframe constructor |
|
78 | + * |
|
79 | + * @param string $title |
|
80 | + * @param string $content |
|
81 | + * @throws DomainException |
|
82 | + */ |
|
83 | + public function __construct($title, $content) |
|
84 | + { |
|
85 | + global $wp_version; |
|
86 | + if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | + } |
|
89 | + $this->setContent($content); |
|
90 | + $this->setTitle($title); |
|
91 | + $this->addStylesheets( |
|
92 | + apply_filters( |
|
93 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | + array( |
|
95 | + 'site_theme' => get_stylesheet_directory_uri() |
|
96 | + . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | + ), |
|
101 | + $this |
|
102 | + ) |
|
103 | + ); |
|
104 | + $this->addScripts( |
|
105 | + apply_filters( |
|
106 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | + array( |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | + ), |
|
112 | + $this |
|
113 | + ) |
|
114 | + ); |
|
115 | + if (apply_filters( |
|
116 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
117 | + false |
|
118 | + )) { |
|
119 | + $this->addStylesheets( |
|
120 | + apply_filters( |
|
121 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
122 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
123 | + $this |
|
124 | + ) |
|
125 | + ); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $title |
|
132 | + * @throws DomainException |
|
133 | + */ |
|
134 | + public function setTitle($title) |
|
135 | + { |
|
136 | + if (empty($title)) { |
|
137 | + throw new DomainException( |
|
138 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
139 | + ); |
|
140 | + } |
|
141 | + $this->title = $title; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string $content |
|
147 | + * @throws DomainException |
|
148 | + */ |
|
149 | + public function setContent($content) |
|
150 | + { |
|
151 | + if (empty($content)) { |
|
152 | + throw new DomainException( |
|
153 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
154 | + ); |
|
155 | + } |
|
156 | + $this->content = $content; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param boolean $enqueue_wp_assets |
|
162 | + */ |
|
163 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
164 | + { |
|
165 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param array $stylesheets |
|
171 | + * @throws DomainException |
|
172 | + */ |
|
173 | + public function addStylesheets(array $stylesheets) |
|
174 | + { |
|
175 | + if (empty($stylesheets)) { |
|
176 | + throw new DomainException( |
|
177 | + esc_html__( |
|
178 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
179 | + 'event_espresso' |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
184 | + $this->css[ $handle ] = $stylesheet; |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @param array $scripts |
|
191 | + * @param bool $add_to_header |
|
192 | + * @throws DomainException |
|
193 | + */ |
|
194 | + public function addScripts(array $scripts, $add_to_header = false) |
|
195 | + { |
|
196 | + if (empty($scripts)) { |
|
197 | + throw new DomainException( |
|
198 | + esc_html__( |
|
199 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
200 | + 'event_espresso' |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + foreach ($scripts as $handle => $script) { |
|
205 | + if ($add_to_header) { |
|
206 | + $this->header_js[ $handle ] = $script; |
|
207 | + } else { |
|
208 | + $this->footer_js[ $handle ] = $script; |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @param array $script_attributes |
|
216 | + * @param bool $add_to_header |
|
217 | + * @throws DomainException |
|
218 | + */ |
|
219 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
220 | + { |
|
221 | + if (empty($script_attributes)) { |
|
222 | + throw new DomainException( |
|
223 | + esc_html__( |
|
224 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
225 | + 'event_espresso' |
|
226 | + ) |
|
227 | + ); |
|
228 | + } |
|
229 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
230 | + if ($add_to_header) { |
|
231 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
232 | + } else { |
|
233 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * @param array $vars |
|
241 | + * @param string $var_name |
|
242 | + * @throws DomainException |
|
243 | + */ |
|
244 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
245 | + { |
|
246 | + if (empty($vars)) { |
|
247 | + throw new DomainException( |
|
248 | + esc_html__( |
|
249 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
250 | + 'event_espresso' |
|
251 | + ) |
|
252 | + ); |
|
253 | + } |
|
254 | + foreach ($vars as $handle => $var) { |
|
255 | + if ($var_name === 'eei18n') { |
|
256 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
257 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
258 | + $this->localized_vars[ $var_name ] = $var; |
|
259 | + } else { |
|
260 | + if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | + $this->localized_vars[ $var_name ] = array(); |
|
262 | + } |
|
263 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $utm_content |
|
271 | + * @throws DomainException |
|
272 | + */ |
|
273 | + public function display($utm_content = '') |
|
274 | + { |
|
275 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
276 | + '', |
|
277 | + '', |
|
278 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
279 | + ); |
|
280 | + EE_System::do_not_cache(); |
|
281 | + echo $this->getTemplate(); |
|
282 | + exit; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @return string |
|
288 | + * @throws DomainException |
|
289 | + */ |
|
290 | + public function getTemplate() |
|
291 | + { |
|
292 | + return EEH_Template::display_template( |
|
293 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
294 | + array( |
|
295 | + 'title' => apply_filters( |
|
296 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
297 | + $this->title, |
|
298 | + $this |
|
299 | + ), |
|
300 | + 'content' => apply_filters( |
|
301 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
302 | + $this->content, |
|
303 | + $this |
|
304 | + ), |
|
305 | + 'enqueue_wp_assets' => apply_filters( |
|
306 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
307 | + $this->enqueue_wp_assets, |
|
308 | + $this |
|
309 | + ), |
|
310 | + 'css' => (array) apply_filters( |
|
311 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
312 | + $this->css, |
|
313 | + $this |
|
314 | + ), |
|
315 | + 'header_js' => (array) apply_filters( |
|
316 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
317 | + $this->header_js, |
|
318 | + $this |
|
319 | + ), |
|
320 | + 'header_js_attributes' => (array) apply_filters( |
|
321 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
322 | + $this->header_js_attributes, |
|
323 | + $this |
|
324 | + ), |
|
325 | + 'footer_js' => (array) apply_filters( |
|
326 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
327 | + $this->footer_js, |
|
328 | + $this |
|
329 | + ), |
|
330 | + 'footer_js_attributes' => (array) apply_filters( |
|
331 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
332 | + $this->footer_js_attributes, |
|
333 | + $this |
|
334 | + ), |
|
335 | + 'eei18n' => apply_filters( |
|
336 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
337 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
338 | + $this |
|
339 | + ), |
|
340 | + 'notices' => EEH_Template::display_template( |
|
341 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
342 | + array(), |
|
343 | + true |
|
344 | + ), |
|
345 | + ), |
|
346 | + true, |
|
347 | + true |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * localizeJsonVars |
|
354 | + * |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function localizeJsonVars() |
|
358 | + { |
|
359 | + $JSON = ''; |
|
360 | + foreach ($this->localized_vars as $var_name => $vars) { |
|
361 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
362 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
363 | + $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
364 | + $JSON .= '; /* ]]> */'; |
|
365 | + } |
|
366 | + return $JSON; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param bool|int|float|string|array $var |
|
372 | + * @return array|string|null |
|
373 | + */ |
|
374 | + public function encodeJsonVars($var) |
|
375 | + { |
|
376 | + if (is_array($var)) { |
|
377 | + $localized_vars = array(); |
|
378 | + foreach ((array) $var as $key => $value) { |
|
379 | + $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
380 | + } |
|
381 | + return $localized_vars; |
|
382 | + } |
|
383 | + if (is_scalar($var)) { |
|
384 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
385 | + } |
|
386 | + return null; |
|
387 | + } |
|
388 | 388 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function __construct($title, $content) |
84 | 84 | { |
85 | 85 | global $wp_version; |
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
86 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
87 | 87 | define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
88 | 88 | } |
89 | 89 | $this->setContent($content); |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
94 | 94 | array( |
95 | 95 | 'site_theme' => get_stylesheet_directory_uri() |
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
96 | + . '/style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
98 | 98 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
99 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
100 | 100 | ), |
101 | 101 | $this |
102 | 102 | ) |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | apply_filters( |
106 | 106 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
107 | 107 | array( |
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
109 | 109 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
110 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
111 | 111 | ), |
112 | 112 | $this |
113 | 113 | ) |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | foreach ($stylesheets as $handle => $stylesheet) { |
184 | - $this->css[ $handle ] = $stylesheet; |
|
184 | + $this->css[$handle] = $stylesheet; |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | } |
204 | 204 | foreach ($scripts as $handle => $script) { |
205 | 205 | if ($add_to_header) { |
206 | - $this->header_js[ $handle ] = $script; |
|
206 | + $this->header_js[$handle] = $script; |
|
207 | 207 | } else { |
208 | - $this->footer_js[ $handle ] = $script; |
|
208 | + $this->footer_js[$handle] = $script; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } |
229 | 229 | foreach ($script_attributes as $handle => $script_attribute) { |
230 | 230 | if ($add_to_header) { |
231 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
231 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
232 | 232 | } else { |
233 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
233 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | } |
254 | 254 | foreach ($vars as $handle => $var) { |
255 | 255 | if ($var_name === 'eei18n') { |
256 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
256 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
257 | 257 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
258 | - $this->localized_vars[ $var_name ] = $var; |
|
258 | + $this->localized_vars[$var_name] = $var; |
|
259 | 259 | } else { |
260 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | - $this->localized_vars[ $var_name ] = array(); |
|
260 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
261 | + $this->localized_vars[$var_name] = array(); |
|
262 | 262 | } |
263 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
263 | + $this->localized_vars[$var_name][$handle] = $var; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | public function getTemplate() |
291 | 291 | { |
292 | 292 | return EEH_Template::display_template( |
293 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
293 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
294 | 294 | array( |
295 | 295 | 'title' => apply_filters( |
296 | 296 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | ), |
335 | 335 | 'eei18n' => apply_filters( |
336 | 336 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
337 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
337 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
338 | 338 | $this |
339 | 339 | ), |
340 | 340 | 'notices' => EEH_Template::display_template( |
341 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
341 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
342 | 342 | array(), |
343 | 343 | true |
344 | 344 | ), |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | { |
359 | 359 | $JSON = ''; |
360 | 360 | foreach ($this->localized_vars as $var_name => $vars) { |
361 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
361 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
362 | 362 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
363 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
363 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
364 | 364 | $JSON .= '; /* ]]> */'; |
365 | 365 | } |
366 | 366 | return $JSON; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | if (is_array($var)) { |
377 | 377 | $localized_vars = array(); |
378 | 378 | foreach ((array) $var as $key => $value) { |
379 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
379 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
380 | 380 | } |
381 | 381 | return $localized_vars; |
382 | 382 | } |
@@ -16,266 +16,266 @@ |
||
16 | 16 | final class EE_Request_Handler implements InterminableInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var CurrentPage |
|
21 | - */ |
|
22 | - private $current_page; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var RequestInterface |
|
26 | - */ |
|
27 | - private $request; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var ResponseInterface |
|
31 | - */ |
|
32 | - private $response; |
|
33 | - |
|
34 | - /** |
|
35 | - * whether current request is via AJAX |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - public $ajax = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * whether current request is via AJAX from the frontend of the site |
|
43 | - * |
|
44 | - * @var boolean |
|
45 | - */ |
|
46 | - public $front_ajax = false; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param CurrentPage $current_page |
|
51 | - * @param RequestInterface $request |
|
52 | - * @param ResponseInterface $response |
|
53 | - */ |
|
54 | - public function __construct(CurrentPage $current_page, RequestInterface $request, ResponseInterface $response) |
|
55 | - { |
|
56 | - $this->current_page = $current_page; |
|
57 | - $this->request = $request; |
|
58 | - $this->response = $response; |
|
59 | - $this->ajax = $this->request->isAjax(); |
|
60 | - $this->front_ajax = $this->request->isFrontAjax(); |
|
61 | - do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param WP $WP |
|
67 | - * @return void |
|
68 | - * @deprecated $VID:$ |
|
69 | - */ |
|
70 | - public function parse_request($WP = null) |
|
71 | - { |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @param WP $WP |
|
77 | - * @return void |
|
78 | - * @deprecated $VID:$ |
|
79 | - */ |
|
80 | - public function set_request_vars($WP = null) |
|
81 | - { |
|
82 | - $this->current_page->parseQueryVars($WP); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param WP $WP |
|
88 | - * @return int |
|
89 | - * @deprecated $VID:$ |
|
90 | - */ |
|
91 | - public function get_post_id_from_request($WP = null) |
|
92 | - { |
|
93 | - return $this->current_page->postId(); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param WP $WP |
|
99 | - * @return string |
|
100 | - * @deprecated $VID:$ |
|
101 | - */ |
|
102 | - public function get_post_name_from_request($WP = null) |
|
103 | - { |
|
104 | - return $this->current_page->postName(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param WP $WP |
|
110 | - * @return array |
|
111 | - * @deprecated $VID:$ |
|
112 | - */ |
|
113 | - public function get_post_type_from_request($WP = null) |
|
114 | - { |
|
115 | - return $this->current_page->postType(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Just a helper method for getting the url for the displayed page. |
|
121 | - * |
|
122 | - * @param WP $WP |
|
123 | - * @return string |
|
124 | - * @deprecated $VID:$ |
|
125 | - */ |
|
126 | - public function get_current_page_permalink($WP = null) |
|
127 | - { |
|
128 | - return $this->current_page->getPermalink($WP); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return bool |
|
134 | - * @deprecated $VID:$ |
|
135 | - */ |
|
136 | - public function test_for_espresso_page() |
|
137 | - { |
|
138 | - return $this->current_page->isEspressoPage(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param $key |
|
144 | - * @param $value |
|
145 | - * @return void |
|
146 | - * @deprecated $VID:$ |
|
147 | - */ |
|
148 | - public function set_notice($key, $value) |
|
149 | - { |
|
150 | - $this->response->setNotice($key, $value); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param $key |
|
156 | - * @return mixed |
|
157 | - * @deprecated $VID:$ |
|
158 | - */ |
|
159 | - public function get_notice($key) |
|
160 | - { |
|
161 | - return $this->response->getNotice($key); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param $string |
|
167 | - * @return void |
|
168 | - * @deprecated $VID:$ |
|
169 | - */ |
|
170 | - public function add_output($string) |
|
171 | - { |
|
172 | - $this->response->addOutput($string); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return string |
|
178 | - * @deprecated $VID:$ |
|
179 | - */ |
|
180 | - public function get_output() |
|
181 | - { |
|
182 | - return $this->response->getOutput(); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param $item |
|
188 | - * @param $key |
|
189 | - * @deprecated $VID:$ |
|
190 | - */ |
|
191 | - public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
192 | - { |
|
193 | - $item = strpos($item, 'email') !== false |
|
194 | - ? sanitize_email($item) |
|
195 | - : sanitize_text_field($item); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @param null|bool $value |
|
201 | - * @return void |
|
202 | - * @deprecated $VID:$ |
|
203 | - */ |
|
204 | - public function set_espresso_page($value = null) |
|
205 | - { |
|
206 | - $this->current_page->setEspressoPage($value); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @return bool |
|
212 | - * @deprecated $VID:$ |
|
213 | - */ |
|
214 | - public function is_espresso_page() |
|
215 | - { |
|
216 | - return $this->current_page->isEspressoPage(); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * returns contents of $_REQUEST |
|
222 | - * |
|
223 | - * @return array |
|
224 | - * @deprecated $VID:$ |
|
225 | - */ |
|
226 | - public function params() |
|
227 | - { |
|
228 | - return $this->request->requestParams(); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $key |
|
234 | - * @param $value |
|
235 | - * @param bool $override_ee |
|
236 | - * @return void |
|
237 | - * @deprecated $VID:$ |
|
238 | - */ |
|
239 | - public function set($key, $value, $override_ee = false) |
|
240 | - { |
|
241 | - $this->request->setRequestParam($key, $value, $override_ee); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @param $key |
|
247 | - * @param null $default |
|
248 | - * @return mixed |
|
249 | - * @deprecated $VID:$ |
|
250 | - */ |
|
251 | - public function get($key, $default = null) |
|
252 | - { |
|
253 | - return $this->request->getRequestParam($key, $default); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * check if param exists |
|
259 | - * |
|
260 | - * @param $key |
|
261 | - * @return boolean |
|
262 | - * @deprecated $VID:$ |
|
263 | - */ |
|
264 | - public function is_set($key) |
|
265 | - { |
|
266 | - return $this->request->requestParamIsSet($key); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * remove param |
|
272 | - * |
|
273 | - * @param $key |
|
274 | - * @return void |
|
275 | - * @deprecated $VID:$ |
|
276 | - */ |
|
277 | - public function un_set($key) |
|
278 | - { |
|
279 | - $this->request->unSetRequestParam($key); |
|
280 | - } |
|
19 | + /** |
|
20 | + * @var CurrentPage |
|
21 | + */ |
|
22 | + private $current_page; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var RequestInterface |
|
26 | + */ |
|
27 | + private $request; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var ResponseInterface |
|
31 | + */ |
|
32 | + private $response; |
|
33 | + |
|
34 | + /** |
|
35 | + * whether current request is via AJAX |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + public $ajax = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * whether current request is via AJAX from the frontend of the site |
|
43 | + * |
|
44 | + * @var boolean |
|
45 | + */ |
|
46 | + public $front_ajax = false; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param CurrentPage $current_page |
|
51 | + * @param RequestInterface $request |
|
52 | + * @param ResponseInterface $response |
|
53 | + */ |
|
54 | + public function __construct(CurrentPage $current_page, RequestInterface $request, ResponseInterface $response) |
|
55 | + { |
|
56 | + $this->current_page = $current_page; |
|
57 | + $this->request = $request; |
|
58 | + $this->response = $response; |
|
59 | + $this->ajax = $this->request->isAjax(); |
|
60 | + $this->front_ajax = $this->request->isFrontAjax(); |
|
61 | + do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param WP $WP |
|
67 | + * @return void |
|
68 | + * @deprecated $VID:$ |
|
69 | + */ |
|
70 | + public function parse_request($WP = null) |
|
71 | + { |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @param WP $WP |
|
77 | + * @return void |
|
78 | + * @deprecated $VID:$ |
|
79 | + */ |
|
80 | + public function set_request_vars($WP = null) |
|
81 | + { |
|
82 | + $this->current_page->parseQueryVars($WP); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param WP $WP |
|
88 | + * @return int |
|
89 | + * @deprecated $VID:$ |
|
90 | + */ |
|
91 | + public function get_post_id_from_request($WP = null) |
|
92 | + { |
|
93 | + return $this->current_page->postId(); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param WP $WP |
|
99 | + * @return string |
|
100 | + * @deprecated $VID:$ |
|
101 | + */ |
|
102 | + public function get_post_name_from_request($WP = null) |
|
103 | + { |
|
104 | + return $this->current_page->postName(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param WP $WP |
|
110 | + * @return array |
|
111 | + * @deprecated $VID:$ |
|
112 | + */ |
|
113 | + public function get_post_type_from_request($WP = null) |
|
114 | + { |
|
115 | + return $this->current_page->postType(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Just a helper method for getting the url for the displayed page. |
|
121 | + * |
|
122 | + * @param WP $WP |
|
123 | + * @return string |
|
124 | + * @deprecated $VID:$ |
|
125 | + */ |
|
126 | + public function get_current_page_permalink($WP = null) |
|
127 | + { |
|
128 | + return $this->current_page->getPermalink($WP); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return bool |
|
134 | + * @deprecated $VID:$ |
|
135 | + */ |
|
136 | + public function test_for_espresso_page() |
|
137 | + { |
|
138 | + return $this->current_page->isEspressoPage(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param $key |
|
144 | + * @param $value |
|
145 | + * @return void |
|
146 | + * @deprecated $VID:$ |
|
147 | + */ |
|
148 | + public function set_notice($key, $value) |
|
149 | + { |
|
150 | + $this->response->setNotice($key, $value); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param $key |
|
156 | + * @return mixed |
|
157 | + * @deprecated $VID:$ |
|
158 | + */ |
|
159 | + public function get_notice($key) |
|
160 | + { |
|
161 | + return $this->response->getNotice($key); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param $string |
|
167 | + * @return void |
|
168 | + * @deprecated $VID:$ |
|
169 | + */ |
|
170 | + public function add_output($string) |
|
171 | + { |
|
172 | + $this->response->addOutput($string); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return string |
|
178 | + * @deprecated $VID:$ |
|
179 | + */ |
|
180 | + public function get_output() |
|
181 | + { |
|
182 | + return $this->response->getOutput(); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param $item |
|
188 | + * @param $key |
|
189 | + * @deprecated $VID:$ |
|
190 | + */ |
|
191 | + public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
192 | + { |
|
193 | + $item = strpos($item, 'email') !== false |
|
194 | + ? sanitize_email($item) |
|
195 | + : sanitize_text_field($item); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @param null|bool $value |
|
201 | + * @return void |
|
202 | + * @deprecated $VID:$ |
|
203 | + */ |
|
204 | + public function set_espresso_page($value = null) |
|
205 | + { |
|
206 | + $this->current_page->setEspressoPage($value); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @return bool |
|
212 | + * @deprecated $VID:$ |
|
213 | + */ |
|
214 | + public function is_espresso_page() |
|
215 | + { |
|
216 | + return $this->current_page->isEspressoPage(); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * returns contents of $_REQUEST |
|
222 | + * |
|
223 | + * @return array |
|
224 | + * @deprecated $VID:$ |
|
225 | + */ |
|
226 | + public function params() |
|
227 | + { |
|
228 | + return $this->request->requestParams(); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $key |
|
234 | + * @param $value |
|
235 | + * @param bool $override_ee |
|
236 | + * @return void |
|
237 | + * @deprecated $VID:$ |
|
238 | + */ |
|
239 | + public function set($key, $value, $override_ee = false) |
|
240 | + { |
|
241 | + $this->request->setRequestParam($key, $value, $override_ee); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @param $key |
|
247 | + * @param null $default |
|
248 | + * @return mixed |
|
249 | + * @deprecated $VID:$ |
|
250 | + */ |
|
251 | + public function get($key, $default = null) |
|
252 | + { |
|
253 | + return $this->request->getRequestParam($key, $default); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * check if param exists |
|
259 | + * |
|
260 | + * @param $key |
|
261 | + * @return boolean |
|
262 | + * @deprecated $VID:$ |
|
263 | + */ |
|
264 | + public function is_set($key) |
|
265 | + { |
|
266 | + return $this->request->requestParamIsSet($key); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * remove param |
|
272 | + * |
|
273 | + * @param $key |
|
274 | + * @return void |
|
275 | + * @deprecated $VID:$ |
|
276 | + */ |
|
277 | + public function un_set($key) |
|
278 | + { |
|
279 | + $this->request->unSetRequestParam($key); |
|
280 | + } |
|
281 | 281 | } |
@@ -20,1155 +20,1155 @@ |
||
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 = []; |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = []; |
|
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 ] = []; |
|
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 ]); |
|
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 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
326 | - * |
|
327 | - * @param string $class_name |
|
328 | - * @param string $dependency |
|
329 | - * @return int |
|
330 | - */ |
|
331 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
332 | - { |
|
333 | - // all legacy models have the same dependencies |
|
334 | - if (strpos($class_name, 'EEM_') === 0) { |
|
335 | - $class_name = 'LEGACY_MODELS'; |
|
336 | - } |
|
337 | - $dependency = $this->getFqnForAlias($dependency); |
|
338 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
339 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
340 | - : EE_Dependency_Map::not_registered; |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * @param string $class_name |
|
346 | - * @return string | Closure |
|
347 | - */ |
|
348 | - public function class_loader($class_name) |
|
349 | - { |
|
350 | - // all legacy models use load_model() |
|
351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
352 | - return 'load_model'; |
|
353 | - } |
|
354 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
355 | - // perform strpos() first to avoid loading regex every time we load a class |
|
356 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
357 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
358 | - ) { |
|
359 | - return 'load_core'; |
|
360 | - } |
|
361 | - $class_name = $this->getFqnForAlias($class_name); |
|
362 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * @return array |
|
368 | - */ |
|
369 | - public function class_loaders() |
|
370 | - { |
|
371 | - return $this->_class_loaders; |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * adds an alias for a classname |
|
377 | - * |
|
378 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
379 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
380 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
381 | - */ |
|
382 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
383 | - { |
|
384 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
390 | - * WHY? |
|
391 | - * Because if a class is type hinting for a concretion, |
|
392 | - * then why would we need to find another class to supply it? |
|
393 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
394 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
395 | - * Don't go looking for some substitute. |
|
396 | - * Whereas if a class is type hinting for an interface... |
|
397 | - * then we need to find an actual class to use. |
|
398 | - * So the interface IS the alias for some other FQN, |
|
399 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
400 | - * represents some other class. |
|
401 | - * |
|
402 | - * @param string $fqn |
|
403 | - * @param string $for_class |
|
404 | - * @return bool |
|
405 | - */ |
|
406 | - public function isAlias($fqn = '', $for_class = '') |
|
407 | - { |
|
408 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
414 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
415 | - * for example: |
|
416 | - * if the following two entries were added to the _aliases array: |
|
417 | - * array( |
|
418 | - * 'interface_alias' => 'some\namespace\interface' |
|
419 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
420 | - * ) |
|
421 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
422 | - * to load an instance of 'some\namespace\classname' |
|
423 | - * |
|
424 | - * @param string $alias |
|
425 | - * @param string $for_class |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
429 | - { |
|
430 | - return $this->class_cache->getFqnForAlias($alias, $for_class); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
436 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
437 | - * This is done by using the following class constants: |
|
438 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
439 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
440 | - */ |
|
441 | - protected function _register_core_dependencies() |
|
442 | - { |
|
443 | - $this->_dependency_map = [ |
|
444 | - 'EE_Request_Handler' => [ |
|
445 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
446 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
447 | - 'EventEspresso\core\services\request\Response' => EE_Dependency_Map::load_from_cache, |
|
448 | - ], |
|
449 | - 'EE_System' => [ |
|
450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | - ], |
|
455 | - 'EE_Session' => [ |
|
456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | - ], |
|
462 | - 'EE_Cart' => [ |
|
463 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | - ], |
|
465 | - 'EE_Front_Controller' => [ |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | - ], |
|
470 | - 'EE_Messenger_Collection_Loader' => [ |
|
471 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | - ], |
|
473 | - 'EE_Message_Type_Collection_Loader' => [ |
|
474 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | - ], |
|
476 | - 'EE_Message_Resource_Manager' => [ |
|
477 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | - ], |
|
481 | - 'EE_Message_Factory' => [ |
|
482 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ], |
|
484 | - 'EE_messages' => [ |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ], |
|
487 | - 'EE_Messages_Generator' => [ |
|
488 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | - ], |
|
493 | - 'EE_Messages_Processor' => [ |
|
494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | - ], |
|
496 | - 'EE_Messages_Queue' => [ |
|
497 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | - ], |
|
499 | - 'EE_Messages_Template_Defaults' => [ |
|
500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | - ], |
|
503 | - 'EE_Message_To_Generate_From_Request' => [ |
|
504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
506 | - ], |
|
507 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
508 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | - ], |
|
510 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
511 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | - ], |
|
514 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
515 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | - ], |
|
517 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
518 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | - ], |
|
521 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
522 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | - ], |
|
524 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
525 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | - ], |
|
527 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
528 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | - ], |
|
530 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | - ], |
|
533 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
534 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ], |
|
536 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
537 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ], |
|
539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ], |
|
542 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
543 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ], |
|
545 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
546 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ], |
|
548 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
549 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ], |
|
551 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
552 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ], |
|
554 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ], |
|
557 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
558 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | - ], |
|
560 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | - ], |
|
563 | - 'EE_Data_Migration_Class_Base' => [ |
|
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_1_0' => [ |
|
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_2_0' => [ |
|
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_3_0' => [ |
|
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_4_0' => [ |
|
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_5_0' => [ |
|
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_6_0' => [ |
|
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_7_0' => [ |
|
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 | - 'EE_DMS_Core_4_8_0' => [ |
|
596 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ], |
|
599 | - 'EE_DMS_Core_4_9_0' => [ |
|
600 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | - ], |
|
603 | - 'EE_DMS_Core_4_10_0' => [ |
|
604 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | - ], |
|
608 | - 'EventEspresso\core\services\assets\I18nRegistry' => [ |
|
609 | - [], |
|
610 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | - ], |
|
612 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
613 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | - ], |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => [ |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ], |
|
619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => [ |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | - ], |
|
622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => [ |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | - ], |
|
625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => [ |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ], |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => [ |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ], |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => [ |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ], |
|
634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => [ |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | - ], |
|
637 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
638 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | - ], |
|
640 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
641 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | - ], |
|
643 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
644 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | - ], |
|
647 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
648 | - null, |
|
649 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | - ], |
|
651 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
652 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | - ], |
|
654 | - 'LEGACY_MODELS' => [ |
|
655 | - null, |
|
656 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | - ], |
|
658 | - 'EE_Module_Request_Router' => [ |
|
659 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
660 | - ], |
|
661 | - 'EE_Registration_Processor' => [ |
|
662 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | - ], |
|
664 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
665 | - null, |
|
666 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | - ], |
|
669 | - 'EventEspresso\core\services\licensing\LicenseService' => [ |
|
670 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | - ], |
|
673 | - 'EE_Admin_Transactions_List_Table' => [ |
|
674 | - null, |
|
675 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | - ], |
|
677 | - 'EventEspresso\core\domain\services\pue\Stats' => [ |
|
678 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | - ], |
|
682 | - 'EventEspresso\core\domain\services\pue\Config' => [ |
|
683 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | - ], |
|
686 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => [ |
|
687 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | - ], |
|
695 | - 'EventEspresso\core\domain\services\admin\ExitModal' => [ |
|
696 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | - ], |
|
698 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => [ |
|
699 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | - ], |
|
701 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
702 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | - ], |
|
705 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => [ |
|
706 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | - ], |
|
708 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
709 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | - ], |
|
715 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
716 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | - ], |
|
718 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
719 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | - ], |
|
722 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
723 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | - ], |
|
725 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
726 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | - ], |
|
728 | - 'EE_CPT_Strategy' => [ |
|
729 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | - ], |
|
732 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
733 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | - ], |
|
735 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => [ |
|
736 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | - ], |
|
742 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => [ |
|
743 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
745 | - ], |
|
746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => [ |
|
747 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | - ], |
|
749 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => [ |
|
750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
752 | - ], |
|
753 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => [ |
|
754 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | - ], |
|
756 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => [ |
|
757 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | - ], |
|
759 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => [ |
|
760 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | - ], |
|
762 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => [ |
|
763 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | - ], |
|
765 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => [ |
|
766 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | - ], |
|
769 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
770 | - null, |
|
771 | - null, |
|
772 | - null, |
|
773 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
774 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | - ], |
|
777 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => [ |
|
778 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
780 | - ], |
|
781 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => [ |
|
782 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | - ], |
|
787 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => [ |
|
788 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | - ], |
|
792 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => [ |
|
793 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | - ], |
|
796 | - 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => [ |
|
797 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | - ], |
|
801 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => [ |
|
802 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | - ], |
|
806 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => [ |
|
807 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | - ], |
|
810 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => [ |
|
811 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | - ], |
|
814 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => [ |
|
815 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache, |
|
816 | - ], |
|
817 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => [ |
|
818 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | - ], |
|
820 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => [ |
|
821 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache, |
|
822 | - ], |
|
823 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => [ |
|
824 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
826 | - ], |
|
827 | - 'EventEspresso\core\libraries\rest_api\calculations\Event' => [ |
|
828 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
830 | - ], |
|
831 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration' => [ |
|
832 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
833 | - ], |
|
834 | - 'EventEspresso\core\services\session\SessionStartHandler' => [ |
|
835 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | - ], |
|
837 | - 'EE_URL_Validation_Strategy' => [ |
|
838 | - null, |
|
839 | - null, |
|
840 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
841 | - ], |
|
842 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => [ |
|
843 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | - 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | - ], |
|
849 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => [ |
|
850 | - 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | - 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache, |
|
852 | - ], |
|
853 | - 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => [ |
|
854 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | - ], |
|
857 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => [ |
|
858 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | - 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | - ], |
|
861 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
862 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | - ], |
|
864 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | - ], |
|
867 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | - null, |
|
869 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | - ], |
|
872 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | - ], |
|
876 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | - ], |
|
880 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | - ], |
|
884 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | - ], |
|
888 | - 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
889 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
890 | - ], |
|
891 | - 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
892 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
893 | - ], |
|
894 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
895 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
896 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
897 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
898 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
899 | - ], |
|
900 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
901 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
902 | - ], |
|
903 | - 'EventEspresso\core\services\request\CurrentPage' => [ |
|
904 | - 'EE_CPT_Strategy' => EE_Dependency_Map::load_from_cache, |
|
905 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
906 | - ], |
|
907 | - 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => [ |
|
908 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
909 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
910 | - ], |
|
911 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager' => [ |
|
912 | - 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => EE_Dependency_Map::load_from_cache, |
|
913 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
914 | - ], |
|
915 | - ]; |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * Registers how core classes are loaded. |
|
921 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
922 | - * 'EE_Request_Handler' => 'load_core' |
|
923 | - * 'EE_Messages_Queue' => 'load_lib' |
|
924 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
925 | - * or, if greater control is required, by providing a custom closure. For example: |
|
926 | - * 'Some_Class' => function () { |
|
927 | - * return new Some_Class(); |
|
928 | - * }, |
|
929 | - * This is required for instantiating dependencies |
|
930 | - * where an interface has been type hinted in a class constructor. For example: |
|
931 | - * 'Required_Interface' => function () { |
|
932 | - * return new A_Class_That_Implements_Required_Interface(); |
|
933 | - * }, |
|
934 | - */ |
|
935 | - protected function _register_core_class_loaders() |
|
936 | - { |
|
937 | - $this->_class_loaders = [ |
|
938 | - // load_core |
|
939 | - 'EE_Dependency_Map' => function () { |
|
940 | - return $this; |
|
941 | - }, |
|
942 | - 'EE_Capabilities' => 'load_core', |
|
943 | - 'EE_Encryption' => 'load_core', |
|
944 | - 'EE_Front_Controller' => 'load_core', |
|
945 | - 'EE_Module_Request_Router' => 'load_core', |
|
946 | - 'EE_Registry' => 'load_core', |
|
947 | - 'EE_Request' => function () { |
|
948 | - return $this->legacy_request; |
|
949 | - }, |
|
950 | - 'EventEspresso\core\services\request\Request' => function () { |
|
951 | - return $this->request; |
|
952 | - }, |
|
953 | - 'EventEspresso\core\services\request\Response' => function () { |
|
954 | - return $this->response; |
|
955 | - }, |
|
956 | - 'EE_Base' => 'load_core', |
|
957 | - 'EE_Request_Handler' => 'load_core', |
|
958 | - 'EE_Session' => 'load_core', |
|
959 | - 'EE_Cron_Tasks' => 'load_core', |
|
960 | - 'EE_System' => 'load_core', |
|
961 | - 'EE_Maintenance_Mode' => 'load_core', |
|
962 | - 'EE_Register_CPTs' => 'load_core', |
|
963 | - 'EE_Admin' => 'load_core', |
|
964 | - 'EE_CPT_Strategy' => 'load_core', |
|
965 | - // load_class |
|
966 | - 'EE_Registration_Processor' => 'load_class', |
|
967 | - // load_lib |
|
968 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
969 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
970 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
971 | - 'EE_Messenger_Collection' => 'load_lib', |
|
972 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
973 | - 'EE_Messages_Processor' => 'load_lib', |
|
974 | - 'EE_Message_Repository' => 'load_lib', |
|
975 | - 'EE_Messages_Queue' => 'load_lib', |
|
976 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
977 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
978 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
979 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
980 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
981 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
982 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
983 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
984 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
985 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
986 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
987 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
988 | - 'EE_Messages_Generator' => function () { |
|
989 | - return EE_Registry::instance()->load_lib( |
|
990 | - 'Messages_Generator', |
|
991 | - [], |
|
992 | - false, |
|
993 | - false |
|
994 | - ); |
|
995 | - }, |
|
996 | - 'EE_Messages_Template_Defaults' => function ($arguments = []) { |
|
997 | - return EE_Registry::instance()->load_lib( |
|
998 | - 'Messages_Template_Defaults', |
|
999 | - $arguments, |
|
1000 | - false, |
|
1001 | - false |
|
1002 | - ); |
|
1003 | - }, |
|
1004 | - // load_helper |
|
1005 | - 'EEH_Parse_Shortcodes' => function () { |
|
1006 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
1007 | - return new EEH_Parse_Shortcodes(); |
|
1008 | - } |
|
1009 | - return null; |
|
1010 | - }, |
|
1011 | - 'EE_Template_Config' => function () { |
|
1012 | - return EE_Config::instance()->template_settings; |
|
1013 | - }, |
|
1014 | - 'EE_Currency_Config' => function () { |
|
1015 | - return EE_Config::instance()->currency; |
|
1016 | - }, |
|
1017 | - 'EE_Registration_Config' => function () { |
|
1018 | - return EE_Config::instance()->registration; |
|
1019 | - }, |
|
1020 | - 'EE_Core_Config' => function () { |
|
1021 | - return EE_Config::instance()->core; |
|
1022 | - }, |
|
1023 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
1024 | - return LoaderFactory::getLoader(); |
|
1025 | - }, |
|
1026 | - 'EE_Network_Config' => function () { |
|
1027 | - return EE_Network_Config::instance(); |
|
1028 | - }, |
|
1029 | - 'EE_Config' => function () { |
|
1030 | - return EE_Config::instance(); |
|
1031 | - }, |
|
1032 | - 'EventEspresso\core\domain\Domain' => function () { |
|
1033 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
1034 | - }, |
|
1035 | - 'EE_Admin_Config' => function () { |
|
1036 | - return EE_Config::instance()->admin; |
|
1037 | - }, |
|
1038 | - 'EE_Organization_Config' => function () { |
|
1039 | - return EE_Config::instance()->organization; |
|
1040 | - }, |
|
1041 | - 'EE_Network_Core_Config' => function () { |
|
1042 | - return EE_Network_Config::instance()->core; |
|
1043 | - }, |
|
1044 | - 'EE_Environment_Config' => function () { |
|
1045 | - return EE_Config::instance()->environment; |
|
1046 | - }, |
|
1047 | - ]; |
|
1048 | - } |
|
1049 | - |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * can be used for supplying alternate names for classes, |
|
1053 | - * or for connecting interface names to instantiable classes |
|
1054 | - */ |
|
1055 | - protected function _register_core_aliases() |
|
1056 | - { |
|
1057 | - $aliases = [ |
|
1058 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1059 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1060 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1061 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1062 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1063 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1064 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1065 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1066 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1067 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1068 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1069 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1070 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1071 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1072 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1073 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1074 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1075 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1076 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1077 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1078 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1079 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1080 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1081 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1082 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1083 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1084 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1085 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1086 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1087 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1088 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1089 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1090 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1091 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1092 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1093 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1094 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1095 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
1096 | - ]; |
|
1097 | - foreach ($aliases as $alias => $fqn) { |
|
1098 | - if (is_array($fqn)) { |
|
1099 | - foreach ($fqn as $class => $for_class) { |
|
1100 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
1101 | - } |
|
1102 | - continue; |
|
1103 | - } |
|
1104 | - $this->class_cache->addAlias($fqn, $alias); |
|
1105 | - } |
|
1106 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1107 | - $this->class_cache->addAlias( |
|
1108 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1109 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1110 | - ); |
|
1111 | - } |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1117 | - * request Primarily used by unit tests. |
|
1118 | - */ |
|
1119 | - public function reset() |
|
1120 | - { |
|
1121 | - $this->_register_core_class_loaders(); |
|
1122 | - $this->_register_core_dependencies(); |
|
1123 | - } |
|
1124 | - |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
1128 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
1129 | - * WHY? |
|
1130 | - * Because if a class is type hinting for a concretion, |
|
1131 | - * then why would we need to find another class to supply it? |
|
1132 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1133 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1134 | - * Don't go looking for some substitute. |
|
1135 | - * Whereas if a class is type hinting for an interface... |
|
1136 | - * then we need to find an actual class to use. |
|
1137 | - * So the interface IS the alias for some other FQN, |
|
1138 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1139 | - * represents some other class. |
|
1140 | - * |
|
1141 | - * @param string $fqn |
|
1142 | - * @param string $for_class |
|
1143 | - * @return bool |
|
1144 | - * @deprecated 4.9.62.p |
|
1145 | - */ |
|
1146 | - public function has_alias($fqn = '', $for_class = '') |
|
1147 | - { |
|
1148 | - return $this->isAlias($fqn, $for_class); |
|
1149 | - } |
|
1150 | - |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1154 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1155 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1156 | - * for example: |
|
1157 | - * if the following two entries were added to the _aliases array: |
|
1158 | - * array( |
|
1159 | - * 'interface_alias' => 'some\namespace\interface' |
|
1160 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1161 | - * ) |
|
1162 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1163 | - * to load an instance of 'some\namespace\classname' |
|
1164 | - * |
|
1165 | - * @param string $alias |
|
1166 | - * @param string $for_class |
|
1167 | - * @return string |
|
1168 | - * @deprecated 4.9.62.p |
|
1169 | - */ |
|
1170 | - public function get_alias($alias = '', $for_class = '') |
|
1171 | - { |
|
1172 | - return $this->getFqnForAlias($alias, $for_class); |
|
1173 | - } |
|
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 = []; |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = []; |
|
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 ] = []; |
|
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 ]); |
|
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 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
326 | + * |
|
327 | + * @param string $class_name |
|
328 | + * @param string $dependency |
|
329 | + * @return int |
|
330 | + */ |
|
331 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
332 | + { |
|
333 | + // all legacy models have the same dependencies |
|
334 | + if (strpos($class_name, 'EEM_') === 0) { |
|
335 | + $class_name = 'LEGACY_MODELS'; |
|
336 | + } |
|
337 | + $dependency = $this->getFqnForAlias($dependency); |
|
338 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
339 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
340 | + : EE_Dependency_Map::not_registered; |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * @param string $class_name |
|
346 | + * @return string | Closure |
|
347 | + */ |
|
348 | + public function class_loader($class_name) |
|
349 | + { |
|
350 | + // all legacy models use load_model() |
|
351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
352 | + return 'load_model'; |
|
353 | + } |
|
354 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
355 | + // perform strpos() first to avoid loading regex every time we load a class |
|
356 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
357 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
358 | + ) { |
|
359 | + return 'load_core'; |
|
360 | + } |
|
361 | + $class_name = $this->getFqnForAlias($class_name); |
|
362 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * @return array |
|
368 | + */ |
|
369 | + public function class_loaders() |
|
370 | + { |
|
371 | + return $this->_class_loaders; |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * adds an alias for a classname |
|
377 | + * |
|
378 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
379 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
380 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
381 | + */ |
|
382 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
383 | + { |
|
384 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
390 | + * WHY? |
|
391 | + * Because if a class is type hinting for a concretion, |
|
392 | + * then why would we need to find another class to supply it? |
|
393 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
394 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
395 | + * Don't go looking for some substitute. |
|
396 | + * Whereas if a class is type hinting for an interface... |
|
397 | + * then we need to find an actual class to use. |
|
398 | + * So the interface IS the alias for some other FQN, |
|
399 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
400 | + * represents some other class. |
|
401 | + * |
|
402 | + * @param string $fqn |
|
403 | + * @param string $for_class |
|
404 | + * @return bool |
|
405 | + */ |
|
406 | + public function isAlias($fqn = '', $for_class = '') |
|
407 | + { |
|
408 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
414 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
415 | + * for example: |
|
416 | + * if the following two entries were added to the _aliases array: |
|
417 | + * array( |
|
418 | + * 'interface_alias' => 'some\namespace\interface' |
|
419 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
420 | + * ) |
|
421 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
422 | + * to load an instance of 'some\namespace\classname' |
|
423 | + * |
|
424 | + * @param string $alias |
|
425 | + * @param string $for_class |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
429 | + { |
|
430 | + return $this->class_cache->getFqnForAlias($alias, $for_class); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
436 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
437 | + * This is done by using the following class constants: |
|
438 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
439 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
440 | + */ |
|
441 | + protected function _register_core_dependencies() |
|
442 | + { |
|
443 | + $this->_dependency_map = [ |
|
444 | + 'EE_Request_Handler' => [ |
|
445 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
446 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
447 | + 'EventEspresso\core\services\request\Response' => EE_Dependency_Map::load_from_cache, |
|
448 | + ], |
|
449 | + 'EE_System' => [ |
|
450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | + ], |
|
455 | + 'EE_Session' => [ |
|
456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | + ], |
|
462 | + 'EE_Cart' => [ |
|
463 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | + ], |
|
465 | + 'EE_Front_Controller' => [ |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | + ], |
|
470 | + 'EE_Messenger_Collection_Loader' => [ |
|
471 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | + ], |
|
473 | + 'EE_Message_Type_Collection_Loader' => [ |
|
474 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | + ], |
|
476 | + 'EE_Message_Resource_Manager' => [ |
|
477 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | + ], |
|
481 | + 'EE_Message_Factory' => [ |
|
482 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ], |
|
484 | + 'EE_messages' => [ |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ], |
|
487 | + 'EE_Messages_Generator' => [ |
|
488 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | + ], |
|
493 | + 'EE_Messages_Processor' => [ |
|
494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | + ], |
|
496 | + 'EE_Messages_Queue' => [ |
|
497 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | + ], |
|
499 | + 'EE_Messages_Template_Defaults' => [ |
|
500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | + ], |
|
503 | + 'EE_Message_To_Generate_From_Request' => [ |
|
504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
506 | + ], |
|
507 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
508 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | + ], |
|
510 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
511 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | + ], |
|
514 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
515 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | + ], |
|
517 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
518 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | + ], |
|
521 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
522 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | + ], |
|
524 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
525 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | + ], |
|
527 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
528 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | + ], |
|
530 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | + ], |
|
533 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
534 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ], |
|
536 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
537 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ], |
|
539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ], |
|
542 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
543 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ], |
|
545 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
546 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ], |
|
548 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
549 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ], |
|
551 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
552 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ], |
|
554 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ], |
|
557 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
558 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | + ], |
|
560 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | + ], |
|
563 | + 'EE_Data_Migration_Class_Base' => [ |
|
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_1_0' => [ |
|
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_2_0' => [ |
|
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_3_0' => [ |
|
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_4_0' => [ |
|
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_5_0' => [ |
|
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_6_0' => [ |
|
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_7_0' => [ |
|
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 | + 'EE_DMS_Core_4_8_0' => [ |
|
596 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ], |
|
599 | + 'EE_DMS_Core_4_9_0' => [ |
|
600 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | + ], |
|
603 | + 'EE_DMS_Core_4_10_0' => [ |
|
604 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | + ], |
|
608 | + 'EventEspresso\core\services\assets\I18nRegistry' => [ |
|
609 | + [], |
|
610 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | + ], |
|
612 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
613 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | + ], |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => [ |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ], |
|
619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => [ |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | + ], |
|
622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => [ |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | + ], |
|
625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => [ |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ], |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => [ |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ], |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => [ |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ], |
|
634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => [ |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | + ], |
|
637 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
638 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | + ], |
|
640 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
641 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | + ], |
|
643 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
644 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | + ], |
|
647 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
648 | + null, |
|
649 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | + ], |
|
651 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
652 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | + ], |
|
654 | + 'LEGACY_MODELS' => [ |
|
655 | + null, |
|
656 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | + ], |
|
658 | + 'EE_Module_Request_Router' => [ |
|
659 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
660 | + ], |
|
661 | + 'EE_Registration_Processor' => [ |
|
662 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | + ], |
|
664 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
665 | + null, |
|
666 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | + ], |
|
669 | + 'EventEspresso\core\services\licensing\LicenseService' => [ |
|
670 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | + ], |
|
673 | + 'EE_Admin_Transactions_List_Table' => [ |
|
674 | + null, |
|
675 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | + ], |
|
677 | + 'EventEspresso\core\domain\services\pue\Stats' => [ |
|
678 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | + ], |
|
682 | + 'EventEspresso\core\domain\services\pue\Config' => [ |
|
683 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | + ], |
|
686 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => [ |
|
687 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | + ], |
|
695 | + 'EventEspresso\core\domain\services\admin\ExitModal' => [ |
|
696 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | + ], |
|
698 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => [ |
|
699 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | + ], |
|
701 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
702 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | + ], |
|
705 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => [ |
|
706 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | + ], |
|
708 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
709 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | + ], |
|
715 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
716 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | + ], |
|
718 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
719 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | + ], |
|
722 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
723 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | + ], |
|
725 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
726 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | + ], |
|
728 | + 'EE_CPT_Strategy' => [ |
|
729 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | + ], |
|
732 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
733 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | + ], |
|
735 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => [ |
|
736 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | + ], |
|
742 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => [ |
|
743 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
745 | + ], |
|
746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => [ |
|
747 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | + ], |
|
749 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => [ |
|
750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
752 | + ], |
|
753 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => [ |
|
754 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | + ], |
|
756 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => [ |
|
757 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | + ], |
|
759 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => [ |
|
760 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | + ], |
|
762 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => [ |
|
763 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | + ], |
|
765 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => [ |
|
766 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | + ], |
|
769 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
770 | + null, |
|
771 | + null, |
|
772 | + null, |
|
773 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
774 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | + ], |
|
777 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => [ |
|
778 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
780 | + ], |
|
781 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => [ |
|
782 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | + ], |
|
787 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => [ |
|
788 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | + ], |
|
792 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => [ |
|
793 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | + ], |
|
796 | + 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => [ |
|
797 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | + ], |
|
801 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => [ |
|
802 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | + ], |
|
806 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => [ |
|
807 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | + ], |
|
810 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => [ |
|
811 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | + ], |
|
814 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => [ |
|
815 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache, |
|
816 | + ], |
|
817 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => [ |
|
818 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | + ], |
|
820 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => [ |
|
821 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache, |
|
822 | + ], |
|
823 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => [ |
|
824 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
826 | + ], |
|
827 | + 'EventEspresso\core\libraries\rest_api\calculations\Event' => [ |
|
828 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
830 | + ], |
|
831 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration' => [ |
|
832 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
833 | + ], |
|
834 | + 'EventEspresso\core\services\session\SessionStartHandler' => [ |
|
835 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | + ], |
|
837 | + 'EE_URL_Validation_Strategy' => [ |
|
838 | + null, |
|
839 | + null, |
|
840 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
841 | + ], |
|
842 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => [ |
|
843 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | + 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | + ], |
|
849 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => [ |
|
850 | + 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | + 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache, |
|
852 | + ], |
|
853 | + 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => [ |
|
854 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | + ], |
|
857 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => [ |
|
858 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | + 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | + ], |
|
861 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
862 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | + ], |
|
864 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | + ], |
|
867 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | + null, |
|
869 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | + ], |
|
872 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | + ], |
|
876 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | + ], |
|
880 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | + ], |
|
884 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | + ], |
|
888 | + 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
889 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
890 | + ], |
|
891 | + 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
892 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
893 | + ], |
|
894 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
895 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
896 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
897 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
898 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
899 | + ], |
|
900 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
901 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
902 | + ], |
|
903 | + 'EventEspresso\core\services\request\CurrentPage' => [ |
|
904 | + 'EE_CPT_Strategy' => EE_Dependency_Map::load_from_cache, |
|
905 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
906 | + ], |
|
907 | + 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => [ |
|
908 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
909 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
910 | + ], |
|
911 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager' => [ |
|
912 | + 'EventEspresso\core\services\shortcodes\LegacyShortcodesManager' => EE_Dependency_Map::load_from_cache, |
|
913 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
914 | + ], |
|
915 | + ]; |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * Registers how core classes are loaded. |
|
921 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
922 | + * 'EE_Request_Handler' => 'load_core' |
|
923 | + * 'EE_Messages_Queue' => 'load_lib' |
|
924 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
925 | + * or, if greater control is required, by providing a custom closure. For example: |
|
926 | + * 'Some_Class' => function () { |
|
927 | + * return new Some_Class(); |
|
928 | + * }, |
|
929 | + * This is required for instantiating dependencies |
|
930 | + * where an interface has been type hinted in a class constructor. For example: |
|
931 | + * 'Required_Interface' => function () { |
|
932 | + * return new A_Class_That_Implements_Required_Interface(); |
|
933 | + * }, |
|
934 | + */ |
|
935 | + protected function _register_core_class_loaders() |
|
936 | + { |
|
937 | + $this->_class_loaders = [ |
|
938 | + // load_core |
|
939 | + 'EE_Dependency_Map' => function () { |
|
940 | + return $this; |
|
941 | + }, |
|
942 | + 'EE_Capabilities' => 'load_core', |
|
943 | + 'EE_Encryption' => 'load_core', |
|
944 | + 'EE_Front_Controller' => 'load_core', |
|
945 | + 'EE_Module_Request_Router' => 'load_core', |
|
946 | + 'EE_Registry' => 'load_core', |
|
947 | + 'EE_Request' => function () { |
|
948 | + return $this->legacy_request; |
|
949 | + }, |
|
950 | + 'EventEspresso\core\services\request\Request' => function () { |
|
951 | + return $this->request; |
|
952 | + }, |
|
953 | + 'EventEspresso\core\services\request\Response' => function () { |
|
954 | + return $this->response; |
|
955 | + }, |
|
956 | + 'EE_Base' => 'load_core', |
|
957 | + 'EE_Request_Handler' => 'load_core', |
|
958 | + 'EE_Session' => 'load_core', |
|
959 | + 'EE_Cron_Tasks' => 'load_core', |
|
960 | + 'EE_System' => 'load_core', |
|
961 | + 'EE_Maintenance_Mode' => 'load_core', |
|
962 | + 'EE_Register_CPTs' => 'load_core', |
|
963 | + 'EE_Admin' => 'load_core', |
|
964 | + 'EE_CPT_Strategy' => 'load_core', |
|
965 | + // load_class |
|
966 | + 'EE_Registration_Processor' => 'load_class', |
|
967 | + // load_lib |
|
968 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
969 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
970 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
971 | + 'EE_Messenger_Collection' => 'load_lib', |
|
972 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
973 | + 'EE_Messages_Processor' => 'load_lib', |
|
974 | + 'EE_Message_Repository' => 'load_lib', |
|
975 | + 'EE_Messages_Queue' => 'load_lib', |
|
976 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
977 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
978 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
979 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
980 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
981 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
982 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
983 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
984 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
985 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
986 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
987 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
988 | + 'EE_Messages_Generator' => function () { |
|
989 | + return EE_Registry::instance()->load_lib( |
|
990 | + 'Messages_Generator', |
|
991 | + [], |
|
992 | + false, |
|
993 | + false |
|
994 | + ); |
|
995 | + }, |
|
996 | + 'EE_Messages_Template_Defaults' => function ($arguments = []) { |
|
997 | + return EE_Registry::instance()->load_lib( |
|
998 | + 'Messages_Template_Defaults', |
|
999 | + $arguments, |
|
1000 | + false, |
|
1001 | + false |
|
1002 | + ); |
|
1003 | + }, |
|
1004 | + // load_helper |
|
1005 | + 'EEH_Parse_Shortcodes' => function () { |
|
1006 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
1007 | + return new EEH_Parse_Shortcodes(); |
|
1008 | + } |
|
1009 | + return null; |
|
1010 | + }, |
|
1011 | + 'EE_Template_Config' => function () { |
|
1012 | + return EE_Config::instance()->template_settings; |
|
1013 | + }, |
|
1014 | + 'EE_Currency_Config' => function () { |
|
1015 | + return EE_Config::instance()->currency; |
|
1016 | + }, |
|
1017 | + 'EE_Registration_Config' => function () { |
|
1018 | + return EE_Config::instance()->registration; |
|
1019 | + }, |
|
1020 | + 'EE_Core_Config' => function () { |
|
1021 | + return EE_Config::instance()->core; |
|
1022 | + }, |
|
1023 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
1024 | + return LoaderFactory::getLoader(); |
|
1025 | + }, |
|
1026 | + 'EE_Network_Config' => function () { |
|
1027 | + return EE_Network_Config::instance(); |
|
1028 | + }, |
|
1029 | + 'EE_Config' => function () { |
|
1030 | + return EE_Config::instance(); |
|
1031 | + }, |
|
1032 | + 'EventEspresso\core\domain\Domain' => function () { |
|
1033 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
1034 | + }, |
|
1035 | + 'EE_Admin_Config' => function () { |
|
1036 | + return EE_Config::instance()->admin; |
|
1037 | + }, |
|
1038 | + 'EE_Organization_Config' => function () { |
|
1039 | + return EE_Config::instance()->organization; |
|
1040 | + }, |
|
1041 | + 'EE_Network_Core_Config' => function () { |
|
1042 | + return EE_Network_Config::instance()->core; |
|
1043 | + }, |
|
1044 | + 'EE_Environment_Config' => function () { |
|
1045 | + return EE_Config::instance()->environment; |
|
1046 | + }, |
|
1047 | + ]; |
|
1048 | + } |
|
1049 | + |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * can be used for supplying alternate names for classes, |
|
1053 | + * or for connecting interface names to instantiable classes |
|
1054 | + */ |
|
1055 | + protected function _register_core_aliases() |
|
1056 | + { |
|
1057 | + $aliases = [ |
|
1058 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1059 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1060 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1061 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1062 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1063 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1064 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1065 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1066 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1067 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1068 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1069 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1070 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1071 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1072 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1073 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1074 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1075 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1076 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1077 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1078 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1079 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1080 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1081 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1082 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1083 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1084 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1085 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1086 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1087 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1088 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1089 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1090 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1091 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1092 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1093 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1094 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1095 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
1096 | + ]; |
|
1097 | + foreach ($aliases as $alias => $fqn) { |
|
1098 | + if (is_array($fqn)) { |
|
1099 | + foreach ($fqn as $class => $for_class) { |
|
1100 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
1101 | + } |
|
1102 | + continue; |
|
1103 | + } |
|
1104 | + $this->class_cache->addAlias($fqn, $alias); |
|
1105 | + } |
|
1106 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1107 | + $this->class_cache->addAlias( |
|
1108 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1109 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1110 | + ); |
|
1111 | + } |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1117 | + * request Primarily used by unit tests. |
|
1118 | + */ |
|
1119 | + public function reset() |
|
1120 | + { |
|
1121 | + $this->_register_core_class_loaders(); |
|
1122 | + $this->_register_core_dependencies(); |
|
1123 | + } |
|
1124 | + |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
1128 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
1129 | + * WHY? |
|
1130 | + * Because if a class is type hinting for a concretion, |
|
1131 | + * then why would we need to find another class to supply it? |
|
1132 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1133 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1134 | + * Don't go looking for some substitute. |
|
1135 | + * Whereas if a class is type hinting for an interface... |
|
1136 | + * then we need to find an actual class to use. |
|
1137 | + * So the interface IS the alias for some other FQN, |
|
1138 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1139 | + * represents some other class. |
|
1140 | + * |
|
1141 | + * @param string $fqn |
|
1142 | + * @param string $for_class |
|
1143 | + * @return bool |
|
1144 | + * @deprecated 4.9.62.p |
|
1145 | + */ |
|
1146 | + public function has_alias($fqn = '', $for_class = '') |
|
1147 | + { |
|
1148 | + return $this->isAlias($fqn, $for_class); |
|
1149 | + } |
|
1150 | + |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1154 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1155 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1156 | + * for example: |
|
1157 | + * if the following two entries were added to the _aliases array: |
|
1158 | + * array( |
|
1159 | + * 'interface_alias' => 'some\namespace\interface' |
|
1160 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1161 | + * ) |
|
1162 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1163 | + * to load an instance of 'some\namespace\classname' |
|
1164 | + * |
|
1165 | + * @param string $alias |
|
1166 | + * @param string $for_class |
|
1167 | + * @return string |
|
1168 | + * @deprecated 4.9.62.p |
|
1169 | + */ |
|
1170 | + public function get_alias($alias = '', $for_class = '') |
|
1171 | + { |
|
1172 | + return $this->getFqnForAlias($alias, $for_class); |
|
1173 | + } |
|
1174 | 1174 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | public static function instance(ClassInterfaceCache $class_cache = null) |
123 | 123 | { |
124 | 124 | // check if class object is instantiated, and instantiated properly |
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
125 | + if ( ! self::$_instance instanceof EE_Dependency_Map |
|
126 | 126 | && $class_cache instanceof ClassInterfaceCache |
127 | 127 | ) { |
128 | 128 | self::$_instance = new EE_Dependency_Map($class_cache); |
@@ -203,18 +203,18 @@ discard block |
||
203 | 203 | ) { |
204 | 204 | $class = trim($class, '\\'); |
205 | 205 | $registered = false; |
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = []; |
|
206 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
207 | + self::$_instance->_dependency_map[$class] = []; |
|
208 | 208 | } |
209 | 209 | // we need to make sure that any aliases used when registering a dependency |
210 | 210 | // get resolved to the correct class name |
211 | 211 | foreach ($dependencies as $dependency => $load_source) { |
212 | 212 | $alias = self::$_instance->getFqnForAlias($dependency); |
213 | 213 | if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
214 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
215 | 215 | ) { |
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
216 | + unset($dependencies[$dependency]); |
|
217 | + $dependencies[$alias] = $load_source; |
|
218 | 218 | $registered = true; |
219 | 219 | } |
220 | 220 | } |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
225 | 225 | // Union is way faster than array_merge() but should be used with caution... |
226 | 226 | // especially with numerically indexed arrays |
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
227 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
228 | 228 | // now we need to ensure that the resulting dependencies |
229 | 229 | // array only has the entries that are required for the class |
230 | 230 | // so first count how many dependencies were originally registered for the class |
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
232 | 232 | // if that count is non-zero (meaning dependencies were already registered) |
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
233 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
234 | 234 | // then truncate the final array to match that count |
235 | 235 | ? array_slice($dependencies, 0, $dependency_count) |
236 | 236 | // otherwise just take the incoming array because nothing previously existed |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public static function register_class_loader($class_name, $loader = 'load_core') |
249 | 249 | { |
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
250 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | 251 | throw new DomainException( |
252 | 252 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
253 | 253 | ); |
254 | 254 | } |
255 | 255 | // check that loader is callable or method starts with "load_" and exists in EE_Registry |
256 | - if (! is_callable($loader) |
|
256 | + if ( ! is_callable($loader) |
|
257 | 257 | && ( |
258 | 258 | strpos($loader, 'load_') !== 0 |
259 | 259 | || ! method_exists('EE_Registry', $loader) |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | ); |
271 | 271 | } |
272 | 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; |
|
273 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
274 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
275 | 275 | return true; |
276 | 276 | } |
277 | 277 | return false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | if (strpos($class_name, 'EEM_') === 0) { |
300 | 300 | $class_name = 'LEGACY_MODELS'; |
301 | 301 | } |
302 | - return isset($this->_dependency_map[ $class_name ]); |
|
302 | + return isset($this->_dependency_map[$class_name]); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $class_name = 'LEGACY_MODELS'; |
318 | 318 | } |
319 | 319 | $dependency = $this->getFqnForAlias($dependency, $class_name); |
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
320 | + return isset($this->_dependency_map[$class_name][$dependency]); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | } |
337 | 337 | $dependency = $this->getFqnForAlias($dependency); |
338 | 338 | return $this->has_dependency_for_class($class_name, $dependency) |
339 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
339 | + ? $this->_dependency_map[$class_name][$dependency] |
|
340 | 340 | : EE_Dependency_Map::not_registered; |
341 | 341 | } |
342 | 342 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | return 'load_core'; |
360 | 360 | } |
361 | 361 | $class_name = $this->getFqnForAlias($class_name); |
362 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
362 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | { |
937 | 937 | $this->_class_loaders = [ |
938 | 938 | // load_core |
939 | - 'EE_Dependency_Map' => function () { |
|
939 | + 'EE_Dependency_Map' => function() { |
|
940 | 940 | return $this; |
941 | 941 | }, |
942 | 942 | 'EE_Capabilities' => 'load_core', |
@@ -944,13 +944,13 @@ discard block |
||
944 | 944 | 'EE_Front_Controller' => 'load_core', |
945 | 945 | 'EE_Module_Request_Router' => 'load_core', |
946 | 946 | 'EE_Registry' => 'load_core', |
947 | - 'EE_Request' => function () { |
|
947 | + 'EE_Request' => function() { |
|
948 | 948 | return $this->legacy_request; |
949 | 949 | }, |
950 | - 'EventEspresso\core\services\request\Request' => function () { |
|
950 | + 'EventEspresso\core\services\request\Request' => function() { |
|
951 | 951 | return $this->request; |
952 | 952 | }, |
953 | - 'EventEspresso\core\services\request\Response' => function () { |
|
953 | + 'EventEspresso\core\services\request\Response' => function() { |
|
954 | 954 | return $this->response; |
955 | 955 | }, |
956 | 956 | 'EE_Base' => 'load_core', |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | 'EE_DMS_Core_4_8_0' => 'load_dms', |
986 | 986 | 'EE_DMS_Core_4_9_0' => 'load_dms', |
987 | 987 | 'EE_DMS_Core_4_10_0' => 'load_dms', |
988 | - 'EE_Messages_Generator' => function () { |
|
988 | + 'EE_Messages_Generator' => function() { |
|
989 | 989 | return EE_Registry::instance()->load_lib( |
990 | 990 | 'Messages_Generator', |
991 | 991 | [], |
@@ -993,7 +993,7 @@ discard block |
||
993 | 993 | false |
994 | 994 | ); |
995 | 995 | }, |
996 | - 'EE_Messages_Template_Defaults' => function ($arguments = []) { |
|
996 | + 'EE_Messages_Template_Defaults' => function($arguments = []) { |
|
997 | 997 | return EE_Registry::instance()->load_lib( |
998 | 998 | 'Messages_Template_Defaults', |
999 | 999 | $arguments, |
@@ -1002,46 +1002,46 @@ discard block |
||
1002 | 1002 | ); |
1003 | 1003 | }, |
1004 | 1004 | // load_helper |
1005 | - 'EEH_Parse_Shortcodes' => function () { |
|
1005 | + 'EEH_Parse_Shortcodes' => function() { |
|
1006 | 1006 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
1007 | 1007 | return new EEH_Parse_Shortcodes(); |
1008 | 1008 | } |
1009 | 1009 | return null; |
1010 | 1010 | }, |
1011 | - 'EE_Template_Config' => function () { |
|
1011 | + 'EE_Template_Config' => function() { |
|
1012 | 1012 | return EE_Config::instance()->template_settings; |
1013 | 1013 | }, |
1014 | - 'EE_Currency_Config' => function () { |
|
1014 | + 'EE_Currency_Config' => function() { |
|
1015 | 1015 | return EE_Config::instance()->currency; |
1016 | 1016 | }, |
1017 | - 'EE_Registration_Config' => function () { |
|
1017 | + 'EE_Registration_Config' => function() { |
|
1018 | 1018 | return EE_Config::instance()->registration; |
1019 | 1019 | }, |
1020 | - 'EE_Core_Config' => function () { |
|
1020 | + 'EE_Core_Config' => function() { |
|
1021 | 1021 | return EE_Config::instance()->core; |
1022 | 1022 | }, |
1023 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
1023 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
1024 | 1024 | return LoaderFactory::getLoader(); |
1025 | 1025 | }, |
1026 | - 'EE_Network_Config' => function () { |
|
1026 | + 'EE_Network_Config' => function() { |
|
1027 | 1027 | return EE_Network_Config::instance(); |
1028 | 1028 | }, |
1029 | - 'EE_Config' => function () { |
|
1029 | + 'EE_Config' => function() { |
|
1030 | 1030 | return EE_Config::instance(); |
1031 | 1031 | }, |
1032 | - 'EventEspresso\core\domain\Domain' => function () { |
|
1032 | + 'EventEspresso\core\domain\Domain' => function() { |
|
1033 | 1033 | return DomainFactory::getEventEspressoCoreDomain(); |
1034 | 1034 | }, |
1035 | - 'EE_Admin_Config' => function () { |
|
1035 | + 'EE_Admin_Config' => function() { |
|
1036 | 1036 | return EE_Config::instance()->admin; |
1037 | 1037 | }, |
1038 | - 'EE_Organization_Config' => function () { |
|
1038 | + 'EE_Organization_Config' => function() { |
|
1039 | 1039 | return EE_Config::instance()->organization; |
1040 | 1040 | }, |
1041 | - 'EE_Network_Core_Config' => function () { |
|
1041 | + 'EE_Network_Core_Config' => function() { |
|
1042 | 1042 | return EE_Network_Config::instance()->core; |
1043 | 1043 | }, |
1044 | - 'EE_Environment_Config' => function () { |
|
1044 | + 'EE_Environment_Config' => function() { |
|
1045 | 1045 | return EE_Config::instance()->environment; |
1046 | 1046 | }, |
1047 | 1047 | ]; |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | } |
1104 | 1104 | $this->class_cache->addAlias($fqn, $alias); |
1105 | 1105 | } |
1106 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1106 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1107 | 1107 | $this->class_cache->addAlias( |
1108 | 1108 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
1109 | 1109 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -20,231 +20,231 @@ discard block |
||
20 | 20 | class EEM_Transaction extends EEM_Base |
21 | 21 | { |
22 | 22 | |
23 | - // private instance of the Transaction object |
|
24 | - protected static $_instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
28 | - * but payment is pending. This is the state for transactions where payment is promised |
|
29 | - * from an offline gateway. |
|
30 | - */ |
|
31 | - // const open_status_code = 'TPN'; |
|
32 | - |
|
33 | - /** |
|
34 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
35 | - * either due to a technical reason (server or computer crash during registration), |
|
36 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
37 | - */ |
|
38 | - const failed_status_code = 'TFL'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
42 | - * either due to a technical reason (server or computer crash during registration), |
|
43 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
44 | - * HOWEVER... |
|
45 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
46 | - * registrant |
|
47 | - */ |
|
48 | - const abandoned_status_code = 'TAB'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
52 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
53 | - */ |
|
54 | - const incomplete_status_code = 'TIN'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
58 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
59 | - */ |
|
60 | - const complete_status_code = 'TCM'; |
|
61 | - |
|
62 | - /** |
|
63 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
64 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
65 | - */ |
|
66 | - const overpaid_status_code = 'TOP'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * private constructor to prevent direct creation |
|
71 | - * |
|
72 | - * @Constructor |
|
73 | - * @access protected |
|
74 | - * |
|
75 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
76 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
77 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
78 | - * timezone in the 'timezone_string' wp option) |
|
79 | - * |
|
80 | - * @throws EE_Error |
|
81 | - */ |
|
82 | - protected function __construct($timezone) |
|
83 | - { |
|
84 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
85 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
86 | - |
|
87 | - $this->_tables = [ |
|
88 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
89 | - ]; |
|
90 | - $this->_fields = [ |
|
91 | - 'TransactionTable' => [ |
|
92 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
93 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
94 | - 'TXN_timestamp', |
|
95 | - __('date when transaction was created', 'event_espresso'), |
|
96 | - false, |
|
97 | - EE_Datetime_Field::now, |
|
98 | - $timezone |
|
99 | - ), |
|
100 | - 'TXN_total' => new EE_Money_Field( |
|
101 | - 'TXN_total', |
|
102 | - __('Total value of Transaction', 'event_espresso'), |
|
103 | - false, |
|
104 | - 0 |
|
105 | - ), |
|
106 | - 'TXN_paid' => new EE_Money_Field( |
|
107 | - 'TXN_paid', |
|
108 | - __('Amount paid towards transaction to date', 'event_espresso'), |
|
109 | - false, |
|
110 | - 0 |
|
111 | - ), |
|
112 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
113 | - 'STS_ID', |
|
114 | - __('Status ID', 'event_espresso'), |
|
115 | - false, |
|
116 | - EEM_Transaction::failed_status_code, |
|
117 | - 'Status' |
|
118 | - ), |
|
119 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
120 | - 'TXN_session_data', |
|
121 | - __('Serialized session data', 'event_espresso'), |
|
122 | - true, |
|
123 | - '' |
|
124 | - ), |
|
125 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
126 | - 'TXN_hash_salt', |
|
127 | - __('Transaction Hash Salt', 'event_espresso'), |
|
128 | - true, |
|
129 | - '' |
|
130 | - ), |
|
131 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
132 | - 'PMD_ID', |
|
133 | - __("Last Used Payment Method", 'event_espresso'), |
|
134 | - true, |
|
135 | - null, |
|
136 | - 'Payment_Method' |
|
137 | - ), |
|
138 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
139 | - 'TXN_reg_steps', |
|
140 | - __('Registration Steps', 'event_espresso'), |
|
141 | - false, |
|
142 | - [] |
|
143 | - ), |
|
144 | - ], |
|
145 | - ]; |
|
146 | - $this->_model_relations = [ |
|
147 | - 'Registration' => new EE_Has_Many_Relation(), |
|
148 | - 'Payment' => new EE_Has_Many_Relation(), |
|
149 | - 'Status' => new EE_Belongs_To_Relation(), |
|
150 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
151 | - // you can delete a transaction without needing to delete its line items |
|
152 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
153 | - 'Message' => new EE_Has_Many_Relation(), |
|
154 | - ]; |
|
155 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
156 | - parent::__construct($timezone); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * txn_status_array |
|
162 | - * get list of transaction statuses |
|
163 | - * |
|
164 | - * @access public |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - public static function txn_status_array() |
|
168 | - { |
|
169 | - return apply_filters( |
|
170 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
171 | - [ |
|
172 | - EEM_Transaction::overpaid_status_code, |
|
173 | - EEM_Transaction::complete_status_code, |
|
174 | - EEM_Transaction::incomplete_status_code, |
|
175 | - EEM_Transaction::abandoned_status_code, |
|
176 | - EEM_Transaction::failed_status_code, |
|
177 | - ] |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * |
|
187 | - * @param string $period |
|
188 | - * |
|
189 | - * @return stdClass[] |
|
190 | - * @throws EE_Error |
|
191 | - * @throws EE_Error |
|
192 | - */ |
|
193 | - public function get_revenue_per_day_report($period = '-1 month') |
|
194 | - { |
|
195 | - $sql_date = $this->convert_datetime_for_query( |
|
196 | - 'TXN_timestamp', |
|
197 | - date('Y-m-d H:i:s', strtotime($period)), |
|
198 | - 'Y-m-d H:i:s', |
|
199 | - 'UTC' |
|
200 | - ); |
|
201 | - |
|
202 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
203 | - |
|
204 | - return $this->_get_all_wpdb_results( |
|
205 | - [ |
|
206 | - [ |
|
207 | - 'TXN_timestamp' => ['>=', $sql_date], |
|
208 | - ], |
|
209 | - 'group_by' => 'txnDate', |
|
210 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
211 | - ], |
|
212 | - OBJECT, |
|
213 | - [ |
|
214 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
215 | - 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
216 | - ] |
|
217 | - ); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
223 | - * |
|
224 | - * @access public |
|
225 | - * |
|
226 | - * @param string $period |
|
227 | - * |
|
228 | - * @return EE_Transaction[] |
|
229 | - */ |
|
230 | - public function get_revenue_per_event_report($period = '-1 month') |
|
231 | - { |
|
232 | - global $wpdb; |
|
233 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
236 | - $event_table = $wpdb->posts; |
|
237 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
238 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
239 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
240 | - $extra_event_on_join = ''; |
|
241 | - // exclude events not authored by user if permissions in effect |
|
242 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
244 | - } |
|
245 | - |
|
246 | - return $wpdb->get_results( |
|
247 | - "SELECT |
|
23 | + // private instance of the Transaction object |
|
24 | + protected static $_instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
28 | + * but payment is pending. This is the state for transactions where payment is promised |
|
29 | + * from an offline gateway. |
|
30 | + */ |
|
31 | + // const open_status_code = 'TPN'; |
|
32 | + |
|
33 | + /** |
|
34 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
35 | + * either due to a technical reason (server or computer crash during registration), |
|
36 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
37 | + */ |
|
38 | + const failed_status_code = 'TFL'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
42 | + * either due to a technical reason (server or computer crash during registration), |
|
43 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
44 | + * HOWEVER... |
|
45 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
46 | + * registrant |
|
47 | + */ |
|
48 | + const abandoned_status_code = 'TAB'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
52 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
53 | + */ |
|
54 | + const incomplete_status_code = 'TIN'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
58 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
59 | + */ |
|
60 | + const complete_status_code = 'TCM'; |
|
61 | + |
|
62 | + /** |
|
63 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
64 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
65 | + */ |
|
66 | + const overpaid_status_code = 'TOP'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * private constructor to prevent direct creation |
|
71 | + * |
|
72 | + * @Constructor |
|
73 | + * @access protected |
|
74 | + * |
|
75 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
76 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
77 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
78 | + * timezone in the 'timezone_string' wp option) |
|
79 | + * |
|
80 | + * @throws EE_Error |
|
81 | + */ |
|
82 | + protected function __construct($timezone) |
|
83 | + { |
|
84 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
85 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
86 | + |
|
87 | + $this->_tables = [ |
|
88 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
89 | + ]; |
|
90 | + $this->_fields = [ |
|
91 | + 'TransactionTable' => [ |
|
92 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
93 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
94 | + 'TXN_timestamp', |
|
95 | + __('date when transaction was created', 'event_espresso'), |
|
96 | + false, |
|
97 | + EE_Datetime_Field::now, |
|
98 | + $timezone |
|
99 | + ), |
|
100 | + 'TXN_total' => new EE_Money_Field( |
|
101 | + 'TXN_total', |
|
102 | + __('Total value of Transaction', 'event_espresso'), |
|
103 | + false, |
|
104 | + 0 |
|
105 | + ), |
|
106 | + 'TXN_paid' => new EE_Money_Field( |
|
107 | + 'TXN_paid', |
|
108 | + __('Amount paid towards transaction to date', 'event_espresso'), |
|
109 | + false, |
|
110 | + 0 |
|
111 | + ), |
|
112 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
113 | + 'STS_ID', |
|
114 | + __('Status ID', 'event_espresso'), |
|
115 | + false, |
|
116 | + EEM_Transaction::failed_status_code, |
|
117 | + 'Status' |
|
118 | + ), |
|
119 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
120 | + 'TXN_session_data', |
|
121 | + __('Serialized session data', 'event_espresso'), |
|
122 | + true, |
|
123 | + '' |
|
124 | + ), |
|
125 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
126 | + 'TXN_hash_salt', |
|
127 | + __('Transaction Hash Salt', 'event_espresso'), |
|
128 | + true, |
|
129 | + '' |
|
130 | + ), |
|
131 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
132 | + 'PMD_ID', |
|
133 | + __("Last Used Payment Method", 'event_espresso'), |
|
134 | + true, |
|
135 | + null, |
|
136 | + 'Payment_Method' |
|
137 | + ), |
|
138 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
139 | + 'TXN_reg_steps', |
|
140 | + __('Registration Steps', 'event_espresso'), |
|
141 | + false, |
|
142 | + [] |
|
143 | + ), |
|
144 | + ], |
|
145 | + ]; |
|
146 | + $this->_model_relations = [ |
|
147 | + 'Registration' => new EE_Has_Many_Relation(), |
|
148 | + 'Payment' => new EE_Has_Many_Relation(), |
|
149 | + 'Status' => new EE_Belongs_To_Relation(), |
|
150 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
151 | + // you can delete a transaction without needing to delete its line items |
|
152 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
153 | + 'Message' => new EE_Has_Many_Relation(), |
|
154 | + ]; |
|
155 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
156 | + parent::__construct($timezone); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * txn_status_array |
|
162 | + * get list of transaction statuses |
|
163 | + * |
|
164 | + * @access public |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + public static function txn_status_array() |
|
168 | + { |
|
169 | + return apply_filters( |
|
170 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
171 | + [ |
|
172 | + EEM_Transaction::overpaid_status_code, |
|
173 | + EEM_Transaction::complete_status_code, |
|
174 | + EEM_Transaction::incomplete_status_code, |
|
175 | + EEM_Transaction::abandoned_status_code, |
|
176 | + EEM_Transaction::failed_status_code, |
|
177 | + ] |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * |
|
187 | + * @param string $period |
|
188 | + * |
|
189 | + * @return stdClass[] |
|
190 | + * @throws EE_Error |
|
191 | + * @throws EE_Error |
|
192 | + */ |
|
193 | + public function get_revenue_per_day_report($period = '-1 month') |
|
194 | + { |
|
195 | + $sql_date = $this->convert_datetime_for_query( |
|
196 | + 'TXN_timestamp', |
|
197 | + date('Y-m-d H:i:s', strtotime($period)), |
|
198 | + 'Y-m-d H:i:s', |
|
199 | + 'UTC' |
|
200 | + ); |
|
201 | + |
|
202 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
203 | + |
|
204 | + return $this->_get_all_wpdb_results( |
|
205 | + [ |
|
206 | + [ |
|
207 | + 'TXN_timestamp' => ['>=', $sql_date], |
|
208 | + ], |
|
209 | + 'group_by' => 'txnDate', |
|
210 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
211 | + ], |
|
212 | + OBJECT, |
|
213 | + [ |
|
214 | + 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
215 | + 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
216 | + ] |
|
217 | + ); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
223 | + * |
|
224 | + * @access public |
|
225 | + * |
|
226 | + * @param string $period |
|
227 | + * |
|
228 | + * @return EE_Transaction[] |
|
229 | + */ |
|
230 | + public function get_revenue_per_event_report($period = '-1 month') |
|
231 | + { |
|
232 | + global $wpdb; |
|
233 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
236 | + $event_table = $wpdb->posts; |
|
237 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
238 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
239 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
240 | + $extra_event_on_join = ''; |
|
241 | + // exclude events not authored by user if permissions in effect |
|
242 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
244 | + } |
|
245 | + |
|
246 | + return $wpdb->get_results( |
|
247 | + "SELECT |
|
248 | 248 | Transaction_Event.event_name AS event_name, |
249 | 249 | SUM(Transaction_Event.paid) AS revenue |
250 | 250 | FROM |
@@ -272,236 +272,236 @@ discard block |
||
272 | 272 | $extra_event_on_join |
273 | 273 | ) AS Transaction_Event |
274 | 274 | GROUP BY event_name" |
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
281 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
282 | - * the registration pointed to by reg_url_link), if not returns null |
|
283 | - * |
|
284 | - * @param string $reg_url_link |
|
285 | - * |
|
286 | - * @return EE_Transaction |
|
287 | - * @throws EE_Error |
|
288 | - */ |
|
289 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
290 | - { |
|
291 | - if (empty($reg_url_link)) { |
|
292 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
293 | - $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
294 | - } |
|
295 | - return $this->get_one( |
|
296 | - [ |
|
297 | - [ |
|
298 | - 'Registration.REG_url_link' => $reg_url_link, |
|
299 | - ], |
|
300 | - ] |
|
301 | - ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * Updates the provided EE_Transaction with all the applicable payments |
|
307 | - * (or fetch the EE_Transaction from its ID) |
|
308 | - * |
|
309 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
310 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
311 | - * |
|
312 | - * @return array |
|
313 | - * @throws EE_Error |
|
314 | - * @throws ReflectionException |
|
315 | - * @deprecated |
|
316 | - * |
|
317 | - */ |
|
318 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
319 | - { |
|
320 | - EE_Error::doing_it_wrong( |
|
321 | - __CLASS__ . '::' . __FUNCTION__, |
|
322 | - sprintf( |
|
323 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
324 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
325 | - ), |
|
326 | - '4.6.0' |
|
327 | - ); |
|
328 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
329 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
330 | - |
|
331 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
332 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
333 | - ); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
339 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
340 | - * and so we only use wpdb directly and only do minimal joins. |
|
341 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
342 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
343 | - * it, it's probably not junk (regardless of what status it has). |
|
344 | - * The downside to this approach is that is addons are listening for object deletions |
|
345 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
346 | - * to catch these types of deletions. |
|
347 | - * |
|
348 | - * @return int |
|
349 | - * @throws EE_Error |
|
350 | - * @throws EE_Error |
|
351 | - * @global WPDB $wpdb |
|
352 | - */ |
|
353 | - public function delete_junk_transactions() |
|
354 | - { |
|
355 | - global $wpdb; |
|
356 | - $deleted = false; |
|
357 | - $time_to_leave_alone = (int) apply_filters( |
|
358 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
359 | - WEEK_IN_SECONDS |
|
360 | - ); |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
365 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
366 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
367 | - */ |
|
368 | - $ids_query = apply_filters( |
|
369 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
370 | - [ |
|
371 | - 0 => [ |
|
372 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
373 | - 'Payment.PAY_ID' => ['IS NULL'], |
|
374 | - 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
375 | - ], |
|
376 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
377 | - 'limit' => 1000, |
|
378 | - ], |
|
379 | - $time_to_leave_alone |
|
380 | - ); |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
385 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
386 | - */ |
|
387 | - $txn_ids = apply_filters( |
|
388 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
389 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
390 | - $time_to_leave_alone |
|
391 | - ); |
|
392 | - // now that we have the ids to delete |
|
393 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
395 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
396 | - |
|
397 | - // Create IDs placeholder. |
|
398 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
399 | - |
|
400 | - // Glue it together to use inside $wpdb->prepare. |
|
401 | - $format = implode(', ', $placeholders); |
|
402 | - |
|
403 | - // let's get deleting... |
|
404 | - // We got the ids from the original query to get them FROM |
|
405 | - // the db (which is sanitized) so no need to prepare them again. |
|
406 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | - $deleted = $wpdb->query($query); |
|
408 | - } |
|
409 | - if ($deleted) { |
|
410 | - /** |
|
411 | - * Allows code to do something after the transactions have been deleted. |
|
412 | - */ |
|
413 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
414 | - } |
|
415 | - |
|
416 | - return $deleted; |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @param array $transaction_IDs |
|
422 | - * |
|
423 | - * @return bool |
|
424 | - */ |
|
425 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
426 | - { |
|
427 | - $locked_transactions = get_option('ee_locked_transactions', []); |
|
428 | - $update = false; |
|
429 | - foreach ($transaction_IDs as $TXN_ID) { |
|
430 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | - unset($locked_transactions[ $TXN_ID ]); |
|
432 | - $update = true; |
|
433 | - } |
|
434 | - } |
|
435 | - if ($update) { |
|
436 | - update_option('ee_locked_transactions', $locked_transactions); |
|
437 | - } |
|
438 | - |
|
439 | - return $update; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
445 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
446 | - * |
|
447 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
448 | - * @throws EE_Error |
|
449 | - * @throws InvalidArgumentException |
|
450 | - * @throws InvalidDataTypeException |
|
451 | - * @throws InvalidInterfaceException |
|
452 | - */ |
|
453 | - public function get_transactions_in_progress() |
|
454 | - { |
|
455 | - return $this->_get_transactions_in_progress(); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
461 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
462 | - * |
|
463 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
464 | - * @throws EE_Error |
|
465 | - * @throws InvalidArgumentException |
|
466 | - * @throws InvalidDataTypeException |
|
467 | - * @throws InvalidInterfaceException |
|
468 | - */ |
|
469 | - public function get_transactions_not_in_progress() |
|
470 | - { |
|
471 | - return $this->_get_transactions_in_progress('<='); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * @param string $comparison |
|
477 | - * @return EE_Transaction[] |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidArgumentException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws InvalidInterfaceException |
|
482 | - */ |
|
483 | - private function _get_transactions_in_progress($comparison = '>=') |
|
484 | - { |
|
485 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
486 | - ? $comparison |
|
487 | - : '>='; |
|
488 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
489 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
490 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
491 | - ); |
|
492 | - return $this->get_all( |
|
493 | - [ |
|
494 | - [ |
|
495 | - 'TXN_timestamp' => [ |
|
496 | - $comparison, |
|
497 | - $session_lifespan->expiration(), |
|
498 | - ], |
|
499 | - 'STS_ID' => [ |
|
500 | - '!=', |
|
501 | - EEM_Transaction::complete_status_code, |
|
502 | - ], |
|
503 | - ], |
|
504 | - ] |
|
505 | - ); |
|
506 | - } |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
281 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
282 | + * the registration pointed to by reg_url_link), if not returns null |
|
283 | + * |
|
284 | + * @param string $reg_url_link |
|
285 | + * |
|
286 | + * @return EE_Transaction |
|
287 | + * @throws EE_Error |
|
288 | + */ |
|
289 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
290 | + { |
|
291 | + if (empty($reg_url_link)) { |
|
292 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
293 | + $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
294 | + } |
|
295 | + return $this->get_one( |
|
296 | + [ |
|
297 | + [ |
|
298 | + 'Registration.REG_url_link' => $reg_url_link, |
|
299 | + ], |
|
300 | + ] |
|
301 | + ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * Updates the provided EE_Transaction with all the applicable payments |
|
307 | + * (or fetch the EE_Transaction from its ID) |
|
308 | + * |
|
309 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
310 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
311 | + * |
|
312 | + * @return array |
|
313 | + * @throws EE_Error |
|
314 | + * @throws ReflectionException |
|
315 | + * @deprecated |
|
316 | + * |
|
317 | + */ |
|
318 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
319 | + { |
|
320 | + EE_Error::doing_it_wrong( |
|
321 | + __CLASS__ . '::' . __FUNCTION__, |
|
322 | + sprintf( |
|
323 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
324 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
325 | + ), |
|
326 | + '4.6.0' |
|
327 | + ); |
|
328 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
329 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
330 | + |
|
331 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
332 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
333 | + ); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
339 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
340 | + * and so we only use wpdb directly and only do minimal joins. |
|
341 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
342 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
343 | + * it, it's probably not junk (regardless of what status it has). |
|
344 | + * The downside to this approach is that is addons are listening for object deletions |
|
345 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
346 | + * to catch these types of deletions. |
|
347 | + * |
|
348 | + * @return int |
|
349 | + * @throws EE_Error |
|
350 | + * @throws EE_Error |
|
351 | + * @global WPDB $wpdb |
|
352 | + */ |
|
353 | + public function delete_junk_transactions() |
|
354 | + { |
|
355 | + global $wpdb; |
|
356 | + $deleted = false; |
|
357 | + $time_to_leave_alone = (int) apply_filters( |
|
358 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
359 | + WEEK_IN_SECONDS |
|
360 | + ); |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
365 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
366 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
367 | + */ |
|
368 | + $ids_query = apply_filters( |
|
369 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
370 | + [ |
|
371 | + 0 => [ |
|
372 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
373 | + 'Payment.PAY_ID' => ['IS NULL'], |
|
374 | + 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
375 | + ], |
|
376 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
377 | + 'limit' => 1000, |
|
378 | + ], |
|
379 | + $time_to_leave_alone |
|
380 | + ); |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
385 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
386 | + */ |
|
387 | + $txn_ids = apply_filters( |
|
388 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
389 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
390 | + $time_to_leave_alone |
|
391 | + ); |
|
392 | + // now that we have the ids to delete |
|
393 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
395 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
396 | + |
|
397 | + // Create IDs placeholder. |
|
398 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
399 | + |
|
400 | + // Glue it together to use inside $wpdb->prepare. |
|
401 | + $format = implode(', ', $placeholders); |
|
402 | + |
|
403 | + // let's get deleting... |
|
404 | + // We got the ids from the original query to get them FROM |
|
405 | + // the db (which is sanitized) so no need to prepare them again. |
|
406 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | + $deleted = $wpdb->query($query); |
|
408 | + } |
|
409 | + if ($deleted) { |
|
410 | + /** |
|
411 | + * Allows code to do something after the transactions have been deleted. |
|
412 | + */ |
|
413 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
414 | + } |
|
415 | + |
|
416 | + return $deleted; |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @param array $transaction_IDs |
|
422 | + * |
|
423 | + * @return bool |
|
424 | + */ |
|
425 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
426 | + { |
|
427 | + $locked_transactions = get_option('ee_locked_transactions', []); |
|
428 | + $update = false; |
|
429 | + foreach ($transaction_IDs as $TXN_ID) { |
|
430 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | + unset($locked_transactions[ $TXN_ID ]); |
|
432 | + $update = true; |
|
433 | + } |
|
434 | + } |
|
435 | + if ($update) { |
|
436 | + update_option('ee_locked_transactions', $locked_transactions); |
|
437 | + } |
|
438 | + |
|
439 | + return $update; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
445 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
446 | + * |
|
447 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
448 | + * @throws EE_Error |
|
449 | + * @throws InvalidArgumentException |
|
450 | + * @throws InvalidDataTypeException |
|
451 | + * @throws InvalidInterfaceException |
|
452 | + */ |
|
453 | + public function get_transactions_in_progress() |
|
454 | + { |
|
455 | + return $this->_get_transactions_in_progress(); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
461 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
462 | + * |
|
463 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
464 | + * @throws EE_Error |
|
465 | + * @throws InvalidArgumentException |
|
466 | + * @throws InvalidDataTypeException |
|
467 | + * @throws InvalidInterfaceException |
|
468 | + */ |
|
469 | + public function get_transactions_not_in_progress() |
|
470 | + { |
|
471 | + return $this->_get_transactions_in_progress('<='); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * @param string $comparison |
|
477 | + * @return EE_Transaction[] |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidArgumentException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws InvalidInterfaceException |
|
482 | + */ |
|
483 | + private function _get_transactions_in_progress($comparison = '>=') |
|
484 | + { |
|
485 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
486 | + ? $comparison |
|
487 | + : '>='; |
|
488 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
489 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
490 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
491 | + ); |
|
492 | + return $this->get_all( |
|
493 | + [ |
|
494 | + [ |
|
495 | + 'TXN_timestamp' => [ |
|
496 | + $comparison, |
|
497 | + $session_lifespan->expiration(), |
|
498 | + ], |
|
499 | + 'STS_ID' => [ |
|
500 | + '!=', |
|
501 | + EEM_Transaction::complete_status_code, |
|
502 | + ], |
|
503 | + ], |
|
504 | + ] |
|
505 | + ); |
|
506 | + } |
|
507 | 507 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | ), |
144 | 144 | ], |
145 | 145 | ]; |
146 | - $this->_model_relations = [ |
|
146 | + $this->_model_relations = [ |
|
147 | 147 | 'Registration' => new EE_Has_Many_Relation(), |
148 | 148 | 'Payment' => new EE_Has_Many_Relation(), |
149 | 149 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | ], |
212 | 212 | OBJECT, |
213 | 213 | [ |
214 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | + 'txnDate' => ['DATE('.$query_interval.')', '%s'], |
|
215 | 215 | 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
216 | 216 | ] |
217 | 217 | ); |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | public function get_revenue_per_event_report($period = '-1 month') |
231 | 231 | { |
232 | 232 | global $wpdb; |
233 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
233 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
234 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
235 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
236 | 236 | $event_table = $wpdb->posts; |
237 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
238 | 238 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
239 | 239 | $approved_payment_status = EEM_Payment::status_id_approved; |
240 | 240 | $extra_event_on_join = ''; |
241 | 241 | // exclude events not authored by user if permissions in effect |
242 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
242 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $wpdb->get_results( |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
319 | 319 | { |
320 | 320 | EE_Error::doing_it_wrong( |
321 | - __CLASS__ . '::' . __FUNCTION__, |
|
321 | + __CLASS__.'::'.__FUNCTION__, |
|
322 | 322 | sprintf( |
323 | 323 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
324 | 324 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | $time_to_leave_alone |
391 | 391 | ); |
392 | 392 | // now that we have the ids to delete |
393 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | 394 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
395 | 395 | EEM_Transaction::unset_locked_transactions($txn_ids); |
396 | 396 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | // let's get deleting... |
404 | 404 | // We got the ids from the original query to get them FROM |
405 | 405 | // the db (which is sanitized) so no need to prepare them again. |
406 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | 407 | $deleted = $wpdb->query($query); |
408 | 408 | } |
409 | 409 | if ($deleted) { |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | $locked_transactions = get_option('ee_locked_transactions', []); |
428 | 428 | $update = false; |
429 | 429 | foreach ($transaction_IDs as $TXN_ID) { |
430 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | - unset($locked_transactions[ $TXN_ID ]); |
|
430 | + if (isset($locked_transactions[$TXN_ID])) { |
|
431 | + unset($locked_transactions[$TXN_ID]); |
|
432 | 432 | $update = true; |
433 | 433 | } |
434 | 434 | } |
@@ -3,36 +3,36 @@ |
||
3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string $table_column name fo column for field |
|
8 | - * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
9 | - * @param boolean $nullable |
|
10 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | - * dbe a string |
|
12 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | - * "EEM_" |
|
14 | - */ |
|
15 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | - { |
|
17 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | - $this->setSchemaType('integer'); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param string $table_column name fo column for field |
|
8 | + * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
9 | + * @param boolean $nullable |
|
10 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | + * dbe a string |
|
12 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | + * "EEM_" |
|
14 | + */ |
|
15 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | + { |
|
17 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | + $this->setSchemaType('integer'); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | - } |
|
31 | - return absint($value_inputted_for_field_on_model_object); |
|
32 | - } |
|
22 | + /** |
|
23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | + } |
|
31 | + return absint($value_inputted_for_field_on_model_object); |
|
32 | + } |
|
33 | 33 | |
34 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | - { |
|
36 | - return intval($value_found_in_db_for_model_object); |
|
37 | - } |
|
34 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | + { |
|
36 | + return intval($value_found_in_db_for_model_object); |
|
37 | + } |
|
38 | 38 | } |
@@ -8,89 +8,89 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base |
10 | 10 | { |
11 | - /** |
|
12 | - * Usually the name of a single model. However, as in the case for custom post types, |
|
13 | - * it can actually be an array of models |
|
14 | - * |
|
15 | - * @var string or array |
|
16 | - */ |
|
17 | - protected $_model_name_pointed_to; |
|
11 | + /** |
|
12 | + * Usually the name of a single model. However, as in the case for custom post types, |
|
13 | + * it can actually be an array of models |
|
14 | + * |
|
15 | + * @var string or array |
|
16 | + */ |
|
17 | + protected $_model_name_pointed_to; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $table_column name fo column for field |
|
21 | - * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
22 | - * @param boolean $nullable |
|
23 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
24 | - * dbe a string |
|
25 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name |
|
26 | - * without the |
|
27 | - * "EEM_" |
|
28 | - */ |
|
29 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
30 | - { |
|
31 | - $this->_model_name_pointed_to = $model_name; |
|
32 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
33 | - } |
|
19 | + /** |
|
20 | + * @param string $table_column name fo column for field |
|
21 | + * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
22 | + * @param boolean $nullable |
|
23 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
24 | + * dbe a string |
|
25 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name |
|
26 | + * without the |
|
27 | + * "EEM_" |
|
28 | + */ |
|
29 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
30 | + { |
|
31 | + $this->_model_name_pointed_to = $model_name; |
|
32 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Returns the name of the model(s) pointed to |
|
37 | - * |
|
38 | - * @deprecated since version 4.6.7 |
|
39 | - * @return mixed string or array of strings |
|
40 | - */ |
|
41 | - public function get_model_name_pointed_to() |
|
42 | - { |
|
43 | - EE_Error::doing_it_wrong( |
|
44 | - 'get_model_name_pointed_to', |
|
45 | - __( |
|
46 | - 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
47 | - 'event_espresso' |
|
48 | - ), |
|
49 | - '4.6.7' |
|
50 | - ); |
|
51 | - return $this->_model_name_pointed_to; |
|
52 | - } |
|
35 | + /** |
|
36 | + * Returns the name of the model(s) pointed to |
|
37 | + * |
|
38 | + * @deprecated since version 4.6.7 |
|
39 | + * @return mixed string or array of strings |
|
40 | + */ |
|
41 | + public function get_model_name_pointed_to() |
|
42 | + { |
|
43 | + EE_Error::doing_it_wrong( |
|
44 | + 'get_model_name_pointed_to', |
|
45 | + __( |
|
46 | + 'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
47 | + 'event_espresso' |
|
48 | + ), |
|
49 | + '4.6.7' |
|
50 | + ); |
|
51 | + return $this->_model_name_pointed_to; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Gets the model names pointed to by this field, always as an array |
|
56 | - * (even if there's only one) |
|
57 | - * |
|
58 | - * @return array of model names pointed to by this field |
|
59 | - */ |
|
60 | - public function get_model_names_pointed_to() |
|
61 | - { |
|
62 | - if (is_array($this->_model_name_pointed_to)) { |
|
63 | - return $this->_model_name_pointed_to; |
|
64 | - } else { |
|
65 | - return array($this->_model_name_pointed_to); |
|
66 | - } |
|
67 | - } |
|
54 | + /** |
|
55 | + * Gets the model names pointed to by this field, always as an array |
|
56 | + * (even if there's only one) |
|
57 | + * |
|
58 | + * @return array of model names pointed to by this field |
|
59 | + */ |
|
60 | + public function get_model_names_pointed_to() |
|
61 | + { |
|
62 | + if (is_array($this->_model_name_pointed_to)) { |
|
63 | + return $this->_model_name_pointed_to; |
|
64 | + } else { |
|
65 | + return array($this->_model_name_pointed_to); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns the model's classname (eg EE_Event instead of just Event) |
|
71 | - * |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function get_model_class_names_pointed_to() |
|
75 | - { |
|
76 | - $model_names = array(); |
|
77 | - if (is_array($this->_model_name_pointed_to)) { |
|
78 | - foreach ($this->_model_name_pointed_to as $model_name) { |
|
79 | - $model_names[] = "EE_" . $model_name; |
|
80 | - } |
|
81 | - } else { |
|
82 | - $model_names = array("EE_" . $this->_model_name_pointed_to); |
|
83 | - } |
|
84 | - return $model_names; |
|
85 | - } |
|
69 | + /** |
|
70 | + * Returns the model's classname (eg EE_Event instead of just Event) |
|
71 | + * |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function get_model_class_names_pointed_to() |
|
75 | + { |
|
76 | + $model_names = array(); |
|
77 | + if (is_array($this->_model_name_pointed_to)) { |
|
78 | + foreach ($this->_model_name_pointed_to as $model_name) { |
|
79 | + $model_names[] = "EE_" . $model_name; |
|
80 | + } |
|
81 | + } else { |
|
82 | + $model_names = array("EE_" . $this->_model_name_pointed_to); |
|
83 | + } |
|
84 | + return $model_names; |
|
85 | + } |
|
86 | 86 | |
87 | - public function is_model_obj_of_type_pointed_to($model_obj_or_ID) |
|
88 | - { |
|
89 | - foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
90 | - if ($model_obj_or_ID instanceof $model_obj_classname) { |
|
91 | - return true; |
|
92 | - } |
|
93 | - } |
|
94 | - return false; |
|
95 | - } |
|
87 | + public function is_model_obj_of_type_pointed_to($model_obj_or_ID) |
|
88 | + { |
|
89 | + foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
90 | + if ($model_obj_or_ID instanceof $model_obj_classname) { |
|
91 | + return true; |
|
92 | + } |
|
93 | + } |
|
94 | + return false; |
|
95 | + } |
|
96 | 96 | } |