PluginProbe
seQura / 3.1.0
seQura v3.1.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / src / class-bootstrap.php

class-bootstrap.php in seQura 3.1.0, at src/class-bootstrap.php

904 lines 34.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Implementation for the core bootstrap class.
4 *
5 * @package SeQura/WC
6 */
7
8 namespace SeQura\WC;
9
10 use SeQura\Core\BusinessLogic\AdminAPI\GeneralSettings\GeneralSettingsController;
11 use SeQura\Core\BusinessLogic\AdminAPI\PromotionalWidgets\PromotionalWidgetsController;
12 use SeQura\Core\BusinessLogic\BootstrapComponent;
13 use SeQura\Core\BusinessLogic\DataAccess\ConnectionData\Entities\ConnectionData;
14 use SeQura\Core\BusinessLogic\DataAccess\OrderSettings\Entities\OrderStatusSettings;
15 use SeQura\Core\BusinessLogic\DataAccess\PromotionalWidgets\Entities\WidgetSettings;
16 use SeQura\Core\BusinessLogic\DataAccess\SendReport\Entities\SendReport;
17 use SeQura\Core\BusinessLogic\DataAccess\StatisticalData\Entities\StatisticalData;
18 use SeQura\Core\BusinessLogic\DataAccess\TransactionLog\Entities\TransactionLog;
19 use SeQura\Core\BusinessLogic\DataAccess\CountryConfiguration\Entities\CountryConfiguration;
20 use SeQura\Core\BusinessLogic\DataAccess\GeneralSettings\Entities\GeneralSettings;
21 use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\RepositoryContracts\CountryConfigurationRepositoryInterface;
22 use SeQura\Core\BusinessLogic\Domain\GeneralSettings\RepositoryContracts\GeneralSettingsRepositoryInterface;
23 use SeQura\Core\BusinessLogic\Domain\GeneralSettings\Services\CategoryService;
24 use SeQura\Core\BusinessLogic\Domain\GeneralSettings\Services\GeneralSettingsService;
25 use SeQura\Core\BusinessLogic\Domain\Integration\Category\CategoryServiceInterface;
26 use SeQura\Core\BusinessLogic\Domain\Integration\Disconnect\DisconnectServiceInterface;
27 use SeQura\Core\BusinessLogic\Domain\Integration\OrderReport\OrderReportServiceInterface;
28 use SeQura\Core\BusinessLogic\Domain\Integration\SellingCountries\SellingCountriesServiceInterface;
29 use SeQura\Core\BusinessLogic\Domain\Integration\ShopOrderStatuses\ShopOrderStatusesServiceInterface;
30 use SeQura\Core\BusinessLogic\Domain\Integration\Store\StoreServiceInterface;
31 use SeQura\Core\BusinessLogic\Domain\Integration\Version\VersionServiceInterface;
32 use SeQura\Core\BusinessLogic\Domain\Multistore\StoreContext;
33 use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\AbstractItemFactory;
34 use SeQura\Core\BusinessLogic\Domain\Order\Models\SeQuraOrder;
35 use SeQura\Core\BusinessLogic\Domain\Order\RepositoryContracts\SeQuraOrderRepositoryInterface;
36 use SeQura\Core\BusinessLogic\Domain\OrderStatusSettings\RepositoryContracts\OrderStatusSettingsRepositoryInterface;
37 use SeQura\Core\BusinessLogic\Domain\OrderStatusSettings\Services\OrderStatusSettingsService;
38 use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\RepositoryContracts\WidgetSettingsRepositoryInterface;
39 use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Services\WidgetSettingsService;
40 use SeQura\Core\BusinessLogic\Domain\StatisticalData\RepositoryContracts\StatisticalDataRepositoryInterface;
41 use SeQura\Core\BusinessLogic\Domain\Stores\Services\StoreService;
42 use SeQura\Core\BusinessLogic\Utility\EncryptorInterface;
43 use SeQura\Core\BusinessLogic\Webhook\Services\ShopOrderService;
44 use SeQura\Core\Infrastructure\Configuration\ConfigEntity;
45 use SeQura\Core\Infrastructure\Exceptions\ServiceNotRegisteredException;
46 use SeQura\Core\Infrastructure\Logger\Interfaces\DefaultLoggerAdapter;
47 use SeQura\Core\Infrastructure\Logger\Interfaces\ShopLoggerAdapter;
48 use SeQura\Core\Infrastructure\Logger\LoggerConfiguration;
49 use SeQura\Core\Infrastructure\ORM\RepositoryRegistry;
50 use SeQura\Core\Infrastructure\Serializer\Concrete\JsonSerializer;
51 use SeQura\Core\Infrastructure\Serializer\Serializer;
52 use SeQura\Core\Infrastructure\ServiceRegister as Reg;
53 use SeQura\Core\Infrastructure\TaskExecution\Process;
54 use SeQura\Core\Infrastructure\TaskExecution\QueueItem;
55 use SeQura\Core\Infrastructure\Utility\TimeProvider;
56 use SeQura\WC\Controllers\Hooks\Asset\Assets_Controller;
57 use SeQura\WC\Controllers\Hooks\Asset\Interface_Assets_Controller;
58 use SeQura\WC\Controllers\Hooks\Product\Interface_Product_Controller;
59 use SeQura\WC\Controllers\Hooks\Product\Product_Controller;
60 use SeQura\WC\Controllers\Hooks\I18n\I18n_Controller;
61 use SeQura\WC\Controllers\Hooks\I18n\Interface_I18n_Controller;
62 use SeQura\WC\Controllers\Hooks\Order\Interface_Order_Controller;
63 use SeQura\WC\Controllers\Hooks\Order\Order_Controller;
64 use SeQura\WC\Controllers\Hooks\Payment\Interface_Payment_Controller;
65 use SeQura\WC\Controllers\Hooks\Payment\Payment_Controller;
66 use SeQura\WC\Controllers\Hooks\Process\Async_Process_Controller;
67 use SeQura\WC\Controllers\Hooks\Process\Interface_Async_Process_Controller;
68 use SeQura\WC\Controllers\Hooks\Settings\Interface_Settings_Controller;
69 use SeQura\WC\Controllers\Hooks\Settings\Settings_Controller;
70 use SeQura\WC\Controllers\Rest\General_Settings_REST_Controller;
71 use SeQura\WC\Controllers\Rest\Log_REST_Controller;
72 use SeQura\WC\Controllers\Rest\Onboarding_REST_Controller;
73 use SeQura\WC\Controllers\Rest\Payment_REST_Controller;
74 use SeQura\WC\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\Item_Factory;
75 use SeQura\WC\Core\Extension\BusinessLogic\Domain\Order\Builders\Interface_Create_Order_Request_Builder;
76 use SeQura\WC\Core\Extension\BusinessLogic\Domain\OrderStatusSettings\Services\Order_Status_Settings_Service;
77 use SeQura\WC\Core\Extension\Infrastructure\Configuration\Configuration;
78 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Category\Category_Service;
79 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Disconnect\Disconnect_Service;
80 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\ShopOrderStatuses\Shop_Order_Status_Service;
81 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Order\Builders\Create_Order_Request_Builder;
82 use SeQura\WC\Core\Implementation\BusinessLogic\Utility\Encryptor;
83 use SeQura\WC\Core\Implementation\BusinessLogic\Webhook\Services\Shop_Order_Service;
84 use SeQura\WC\Core\Implementation\Infrastructure\Logger\Interfaces\Default_Logger_Adapter;
85 use SeQura\WC\Core\Implementation\Infrastructure\Logger\Interfaces\Shop_Logger_Adapter;
86 use SeQura\WC\Core\Extension\BusinessLogic\AdminAPI\GeneralSettings\General_Settings_Controller;
87 use SeQura\WC\Core\Extension\BusinessLogic\AdminAPI\PromotionalWidgets\Promotional_Widgets_Controller;
88 use SeQura\WC\Core\Extension\BusinessLogic\DataAccess\GeneralSettings\Repositories\General_Settings_Repository;
89 use SeQura\WC\Core\Extension\BusinessLogic\DataAccess\PaymentMethods\Entities\Payment_Methods;
90 use SeQura\WC\Core\Extension\BusinessLogic\DataAccess\PromotionalWidgets\Repositories\Widget_Settings_Repository;
91 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\OrderReport\Order_Report_Service;
92 use SeQura\WC\Repositories\Entity_Repository;
93 use SeQura\WC\Repositories\Interface_Deletable_Repository;
94 use SeQura\WC\Repositories\Migrations\Migration_Install_300;
95 use SeQura\WC\Repositories\Queue_Item_Repository;
96 use SeQura\WC\Repositories\SeQura_Order_Repository;
97 use SeQura\WC\Services\Assets\Assets;
98 use SeQura\WC\Services\Assets\Interface_Assets;
99 use SeQura\WC\Services\Cart\Cart_Service;
100 use SeQura\WC\Services\Cart\Interface_Cart_Service;
101 use SeQura\WC\Services\Constants;
102 use SeQura\WC\Services\Core\Selling_Countries_Service;
103 use SeQura\WC\Services\Core\Store_Service;
104 use SeQura\WC\Services\Core\Version_Service;
105 use SeQura\WC\Services\Shopper\Shopper_Service;
106 use SeQura\WC\Services\Shopper\Interface_Shopper_Service;
107 use SeQura\WC\Services\I18n\I18n;
108 use SeQura\WC\Services\I18n\Interface_I18n;
109 use SeQura\WC\Services\Interface_Log_File;
110 use SeQura\WC\Services\Interface_Logger_Service;
111 use SeQura\WC\Services\Log_File;
112 use SeQura\WC\Services\Logger_Service;
113 use SeQura\WC\Services\Migration\Interface_Migration_Manager;
114 use SeQura\WC\Services\Migration\Migration_Manager;
115 use SeQura\WC\Services\Order\Interface_Order_Service;
116 use SeQura\WC\Services\Order\Order_Service;
117 use SeQura\WC\Services\Payment\Interface_Payment_Method_Service;
118 use SeQura\WC\Services\Payment\Interface_Payment_Service;
119 use SeQura\WC\Services\Payment\Payment_Method_Service;
120 use SeQura\WC\Services\Payment\Payment_Service;
121 use SeQura\WC\Services\Payment\Sequra_Payment_Gateway_Block_Support;
122 use SeQura\WC\Services\Pricing\Interface_Pricing_Service;
123 use SeQura\WC\Services\Pricing\Pricing_Service;
124 use SeQura\WC\Services\Product\Interface_Product_Service;
125 use SeQura\WC\Services\Product\Product_Service;
126 use SeQura\WC\Services\Regex\Interface_Regex;
127 use SeQura\WC\Services\Regex\Regex;
128 use SeQura\WC\Services\Report\Interface_Report_Service;
129 use SeQura\WC\Services\Report\Report_Service;
130 use SeQura\WC\Services\Interface_Constants;
131
132 /**
133 * Implementation for the core bootstrap class.
134 */
135 class Bootstrap extends BootstrapComponent {
136
137
138 /**
139 * Cache for Service instances.
140 *
141 * @var array<string, mixed>
142 */
143 private static $cache = array();
144
145 /**
146 * Initialize the bootstrap.
147 */
148 public static function init(): void {
149 self::initConstants();
150 parent::init();
151
152 Reg::registerService(
153 Plugin::class,
154 static function () {
155 return new Plugin(
156 Reg::getService( Interface_Constants::class ),
157 Reg::getService( Interface_Migration_Manager::class ),
158 Reg::getService( Interface_I18n_Controller::class ),
159 Reg::getService( Interface_Assets_Controller::class ),
160 Reg::getService( Interface_Settings_Controller::class ),
161 Reg::getService( Interface_Payment_Controller::class ),
162 Reg::getService( General_Settings_REST_Controller::class ),
163 Reg::getService( Onboarding_REST_Controller::class ),
164 Reg::getService( Payment_REST_Controller::class ),
165 Reg::getService( Log_REST_Controller::class ),
166 Reg::getService( Interface_Product_Controller::class ),
167 Reg::getService( Interface_Async_Process_Controller::class ),
168 Reg::getService( Interface_Order_Controller::class )
169 );
170 }
171 );
172 }
173
174 /**
175 * Initializes constants.
176 */
177 public static function initConstants(): void {
178 Reg::registerService(
179 Interface_Constants::class,
180 static function () {
181
182 if ( ! isset( self::$cache[ Interface_Constants::class ] ) ) {
183 $dir_path = \trailingslashit( dirname( __DIR__, 1 ) );
184 $plugin_file_path = $dir_path . 'sequra.php';
185
186 if ( ! function_exists( 'get_plugin_data' ) ) {
187 require_once ABSPATH . 'wp-admin/includes/plugin.php';
188 }
189 $add_wc_headers = function ( $headers ) {
190 $headers['WC requires at least'] = 'WC requires at least';
191 return $headers;
192 };
193 \add_filter( 'extra_plugin_headers', $add_wc_headers );
194 $data = \get_plugin_data( $plugin_file_path, true, false );
195 \remove_filter( 'extra_plugin_headers', $add_wc_headers );
196 $data['RequiresWC'] = $data['WC requires at least'];
197 unset( $data['WC requires at least'] );
198
199 /**
200 * Database instance.
201 *
202 * @var \wpdb $wpdb
203 */
204 $wpdb = Reg::getService( \wpdb::class );
205 global $wp_version;
206
207 $environment_data = array(
208 'php_version' => phpversion(),
209 'php_os' => PHP_OS,
210 'uname' => php_uname(),
211 'db_name' => false === strpos( strtolower( $wpdb->db_server_info() ), 'mariadb' ) ? 'mysql' : 'mariadb',
212 'db_version' => $wpdb->db_version() ?? '',
213 'wp_version' => strval( $wp_version ),
214 );
215
216 $dir_url = \plugin_dir_url( $plugin_file_path );
217
218 self::$cache[ Interface_Constants::class ] = new Constants(
219 $dir_path,
220 $plugin_file_path,
221 $dir_path . 'sequra.{storeId}.log',
222 \plugin_basename( $plugin_file_path ),
223 $dir_url,
224 'sequra/v1',
225 $data,
226 \get_plugin_data( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php', true, false ),
227 $environment_data,
228 $dir_path . 'templates/',
229 $dir_path . 'assets',
230 \untrailingslashit( $dir_url ) . '/assets'
231 );
232 }
233
234 return self::$cache[ Interface_Constants::class ];
235 }
236 );
237 }
238
239 /**
240 * Get the constants instance.
241 *
242 * @return Interface_Constants
243 * @throws ServiceNotRegisteredException
244 */
245 private static function get_constants() {
246 return Reg::getService( Interface_Constants::class );
247 }
248
249 /**
250 * Initializes services and utilities.
251 */
252 protected static function initServices(): void {
253 parent::initServices();
254
255 // Core Default.
256 Reg::registerService(
257 LoggerConfiguration::class,
258 static function () {
259 if ( ! isset( self::$cache[ LoggerConfiguration::class ] ) ) {
260 $loggerConfig = LoggerConfiguration::getInstance();
261 if ( ! $loggerConfig->isDefaultLoggerEnabled() ) {
262 $loggerConfig->setIsDefaultLoggerEnabled( false );
263 }
264 self::$cache[ LoggerConfiguration::class ] = $loggerConfig;
265 }
266 return self::$cache[ LoggerConfiguration::class ];
267 }
268 );
269
270 // Core Extension.
271 Reg::registerService(
272 Order_Status_Settings_Service::class,
273 static function () {
274 if ( ! isset( self::$cache[ Order_Status_Settings_Service::class ] ) ) {
275 self::$cache[ Order_Status_Settings_Service::class ] = new Order_Status_Settings_Service(
276 Reg::getService( OrderStatusSettingsRepositoryInterface::class ),
277 Reg::getService( ShopOrderStatusesServiceInterface::class )
278 );
279 }
280 return self::$cache[ Order_Status_Settings_Service::class ];
281 }
282 );
283 Reg::registerService(
284 OrderStatusSettingsService::class,
285 static function () {
286 return Reg::getService( Order_Status_Settings_Service::class );
287 }
288 );
289 Reg::registerService(
290 Configuration::class,
291 static function () {
292 if ( ! isset( self::$cache[ Configuration::class ] ) ) {
293 self::$cache[ Configuration::class ] = Configuration::getInstance();
294 }
295 return self::$cache[ Configuration::class ];
296 }
297 );
298 Reg::registerService(
299 \SeQura\Core\Infrastructure\Configuration\Configuration::CLASS_NAME,
300 static function () {
301 return Reg::getService( Configuration::class );
302 }
303 );
304 Reg::registerService(
305 Interface_Create_Order_Request_Builder::class,
306 static function () {
307 if ( ! isset( self::$cache[ Interface_Create_Order_Request_Builder::class ] ) ) {
308 self::$cache[ Interface_Create_Order_Request_Builder::class ] = new Create_Order_Request_Builder(
309 Reg::getService( Interface_Payment_Service::class ),
310 Reg::getService( Interface_Cart_Service::class ),
311 Reg::getService( Configuration::class ),
312 Reg::getService( Interface_Product_Service::class ),
313 Reg::getService( Interface_Order_Service::class ),
314 Reg::getService( Interface_I18n::class ),
315 Reg::getService( Interface_Shopper_Service::class ),
316 Reg::getService( Interface_Logger_Service::class )
317 );
318 }
319 return self::$cache[ Interface_Create_Order_Request_Builder::class ];
320 }
321 );
322 Reg::registerService(
323 AbstractItemFactory::class,
324 static function () {
325 if ( ! isset( self::$cache[ AbstractItemFactory::class ] ) ) {
326 self::$cache[ AbstractItemFactory::class ] = new Item_Factory();
327 }
328 return self::$cache[ AbstractItemFactory::class ];
329 }
330 );
331
332 // Core Implementation.
333 Reg::registerService(
334 EncryptorInterface::class,
335 static function () {
336 if ( ! isset( self::$cache[ EncryptorInterface::class ] ) ) {
337 self::$cache[ EncryptorInterface::class ] = new Encryptor();
338 }
339 return self::$cache[ EncryptorInterface::class ];
340 }
341 );
342 Reg::registerService(
343 DisconnectServiceInterface::class,
344 static function () {
345 if ( ! isset( self::$cache[ DisconnectServiceInterface::class ] ) ) {
346 self::$cache[ DisconnectServiceInterface::class ] = new Disconnect_Service(
347 array(
348 RepositoryRegistry::getRepository( ConnectionData::class ),
349 RepositoryRegistry::getRepository( StatisticalData::class ),
350 RepositoryRegistry::getRepository( SendReport::class ),
351 RepositoryRegistry::getRepository( QueueItem::class ),
352 //phpcs:ignore
353 // RepositoryRegistry::getRepository( SeQuraOrder::class ),
354 )
355 );
356 }
357 return self::$cache[ DisconnectServiceInterface::class ];
358 }
359 );
360 Reg::registerService(
361 OrderReportServiceInterface::class,
362 static function () {
363 if ( ! isset( self::$cache[ OrderReportServiceInterface::class ] ) ) {
364 self::$cache[ OrderReportServiceInterface::class ] = new Order_Report_Service(
365 Reg::getService( Configuration::CLASS_NAME ),
366 Reg::getService( Interface_Pricing_Service::class ),
367 Reg::getService( Interface_Cart_Service::class ),
368 Reg::getService( Interface_Order_Service::class ),
369 Reg::getService( Interface_I18n::class )
370 );
371 }
372 return self::$cache[ OrderReportServiceInterface::class ];
373 }
374 );
375
376
377 Reg::registerService(
378 Serializer::class,
379 static function () {
380 if ( ! isset( self::$cache[ Serializer::class ] ) ) {
381 self::$cache[ Serializer::class ] = new JsonSerializer();
382 }
383 return self::$cache[ Serializer::class ];
384 }
385 );
386 Reg::registerService(
387 SellingCountriesServiceInterface::class,
388 static function () {
389 if ( ! isset( self::$cache[ SellingCountriesServiceInterface::class ] ) ) {
390 self::$cache[ SellingCountriesServiceInterface::class ] = new Selling_Countries_Service();
391 }
392 return self::$cache[ SellingCountriesServiceInterface::class ];
393 }
394 );
395 Reg::registerService(
396 StoreServiceInterface::class,
397 static function () {
398 if ( ! isset( self::$cache[ StoreServiceInterface::class ] ) ) {
399 self::$cache[ StoreServiceInterface::class ] = new Store_Service();
400 }
401 return self::$cache[ StoreServiceInterface::class ];
402 }
403 );
404 Reg::registerService(
405 VersionServiceInterface::class,
406 static function () {
407 if ( ! isset( self::$cache[ VersionServiceInterface::class ] ) ) {
408 self::$cache[ VersionServiceInterface::class ] = new Version_Service(
409 self::get_constants()->get_plugin_data()['Version']
410 );
411 }
412 return self::$cache[ VersionServiceInterface::class ];
413 }
414 );
415 Reg::registerService(
416 CategoryServiceInterface::class,
417 static function () {
418 if ( ! isset( self::$cache[ CategoryServiceInterface::class ] ) ) {
419 self::$cache[ CategoryServiceInterface::class ] = new Category_Service();
420 }
421 return self::$cache[ CategoryServiceInterface::class ];
422 }
423 );
424 Reg::registerService(
425 ShopOrderStatusesServiceInterface::class,
426 static function () {
427 if ( ! isset( self::$cache[ ShopOrderStatusesServiceInterface::class ] ) ) {
428 self::$cache[ ShopOrderStatusesServiceInterface::class ] = new Shop_Order_Status_Service();
429 }
430 return self::$cache[ ShopOrderStatusesServiceInterface::class ];
431 }
432 );
433 Reg::registerService(
434 ShopLoggerAdapter::CLASS_NAME,
435 static function () {
436 if ( ! isset( self::$cache[ ShopLoggerAdapter::CLASS_NAME ] ) ) {
437 self::$cache[ ShopLoggerAdapter::CLASS_NAME ] = new Shop_Logger_Adapter();
438 }
439 return self::$cache[ ShopLoggerAdapter::CLASS_NAME ];
440 }
441 );
442 Reg::registerService(
443 DefaultLoggerAdapter::CLASS_NAME,
444 static function () {
445 if ( ! isset( self::$cache[ DefaultLoggerAdapter::CLASS_NAME ] ) ) {
446 self::$cache[ DefaultLoggerAdapter::CLASS_NAME ] = new Default_Logger_Adapter(
447 Reg::getService( Interface_Log_File::class ),
448 Reg::getService( TimeProvider::CLASS_NAME )
449 );
450 }
451 return self::$cache[ DefaultLoggerAdapter::CLASS_NAME ];
452 }
453 );
454
455 // Plugin services.
456 Reg::registerService(
457 Interface_Log_File::class,
458 static function () {
459 if ( ! isset( self::$cache[ Interface_Log_File::class ] ) ) {
460 self::$cache[ Interface_Log_File::class ] = new Log_File(
461 self::get_constants()->get_plugin_log_file_path()
462 );
463 }
464 return self::$cache[ Interface_Log_File::class ];
465 }
466 );
467 Reg::registerService(
468 Interface_Migration_Manager::class,
469 static function () {
470 if ( ! isset( self::$cache[ Interface_Migration_Manager::class ] ) ) {
471 self::$cache[ Interface_Migration_Manager::class ] = new Migration_Manager(
472 self::get_constants()->get_plugin_basename(),
473 Reg::getService( Configuration::CLASS_NAME ),
474 self::get_constants()->get_plugin_data()['Version'],
475 array(
476 new Migration_Install_300(
477 Reg::getService( \wpdb::class ),
478 Reg::getService( Configuration::CLASS_NAME )
479 ),
480 )
481 );
482 }
483 return self::$cache[ Interface_Migration_Manager::class ];
484 }
485 );
486 Reg::registerService(
487 Interface_I18n::class,
488 static function () {
489 if ( ! isset( self::$cache[ Interface_I18n::class ] ) ) {
490 self::$cache[ Interface_I18n::class ] = new I18n();
491 }
492 return self::$cache[ Interface_I18n::class ];
493 }
494 );
495 Reg::registerService(
496 Interface_Regex::class,
497 static function () {
498 if ( ! isset( self::$cache[ Interface_Regex::class ] ) ) {
499 self::$cache[ Interface_Regex::class ] = new Regex();
500 }
501 return self::$cache[ Interface_Regex::class ];
502 }
503 );
504 Reg::registerService(
505 Interface_Report_Service::class,
506 static function () {
507 if ( ! isset( self::$cache[ Interface_Report_Service::class ] ) ) {
508 self::$cache[ Interface_Report_Service::class ] = new Report_Service(
509 Reg::getService( Configuration::class ),
510 Reg::getService( StoreService::class ),
511 Reg::getService( ShopOrderService::class ),
512 Reg::getService( StatisticalDataRepositoryInterface::class ),
513 Reg::getService( CountryConfigurationRepositoryInterface::class ),
514 Reg::getService( Interface_Order_Service::class ),
515 Reg::getService( StoreContext::class )
516 );
517 }
518 return self::$cache[ Interface_Report_Service::class ];
519 }
520 );
521 Reg::registerService(
522 Interface_Logger_Service::class,
523 static function () {
524 if ( ! isset( self::$cache[ Interface_Logger_Service::class ] ) ) {
525 self::$cache[ Interface_Logger_Service::class ] = new Logger_Service(
526 Reg::getService( LoggerConfiguration::class ),
527 Reg::getService( Interface_Log_File::class )
528 );
529 }
530 return self::$cache[ Interface_Logger_Service::class ];
531 }
532 );
533 Reg::registerService(
534 Interface_Payment_Service::class,
535 static function () {
536 if ( ! isset( self::$cache[ Interface_Payment_Service::class ] ) ) {
537 self::$cache[ Interface_Payment_Service::class ] = new Payment_Service(
538 Reg::getService( Configuration::class ),
539 Reg::getService( Interface_I18n::class )
540 );
541 }
542 return self::$cache[ Interface_Payment_Service::class ];
543 }
544 );
545
546 Reg::registerService(
547 Sequra_Payment_Gateway_Block_Support::class,
548 static function () {
549 if ( ! isset( self::$cache[ Sequra_Payment_Gateway_Block_Support::class ] ) ) {
550 self::$cache[ Sequra_Payment_Gateway_Block_Support::class ] = new Sequra_Payment_Gateway_Block_Support(
551 self::get_constants()->get_plugin_assets_path(),
552 self::get_constants()->get_plugin_assets_url(),
553 self::get_constants()->get_plugin_data()['Version']
554 );
555 }
556 return self::$cache[ Sequra_Payment_Gateway_Block_Support::class ];
557 }
558 );
559 Reg::registerService(
560 Interface_Pricing_Service::class,
561 static function () {
562 if ( ! isset( self::$cache[ Interface_Pricing_Service::class ] ) ) {
563 self::$cache[ Interface_Pricing_Service::class ] = new Pricing_Service();
564 }
565 return self::$cache[ Interface_Pricing_Service::class ];
566 }
567 );
568 Reg::registerService(
569 Interface_Order_Service::class,
570 static function () {
571 if ( ! isset( self::$cache[ Interface_Order_Service::class ] ) ) {
572 self::$cache[ Interface_Order_Service::class ] = new Order_Service(
573 Reg::getService( SeQuraOrderRepositoryInterface::class ),
574 Reg::getService( Interface_Payment_Service::class ),
575 Reg::getService( Interface_Pricing_Service::class ),
576 Reg::getService( OrderStatusSettingsService::class ),
577 Reg::getService( Configuration::class ),
578 Reg::getService( Interface_Cart_Service::class ),
579 Reg::getService( StoreContext::class ),
580 Reg::getService( Interface_Logger_Service::class )
581 );
582 }
583 return self::$cache[ Interface_Order_Service::class ];
584 }
585 );
586 Reg::registerService(
587 Interface_Cart_Service::class,
588 static function () {
589 if ( ! isset( self::$cache[ Interface_Cart_Service::class ] ) ) {
590 self::$cache[ Interface_Cart_Service::class ] = new Cart_Service(
591 Reg::getService( Interface_Product_Service::class ),
592 Reg::getService( Configuration::class ),
593 Reg::getService( Interface_Pricing_Service::class ),
594 Reg::getService( Interface_Logger_Service::class )
595 );
596 }
597 return self::$cache[ Interface_Cart_Service::class ];
598 }
599 );
600 Reg::registerService(
601 Interface_Product_Service::class,
602 static function () {
603 if ( ! isset( self::$cache[ Interface_Product_Service::class ] ) ) {
604 self::$cache[ Interface_Product_Service::class ] = new Product_Service(
605 Reg::getService( Configuration::class ),
606 Reg::getService( Interface_Pricing_Service::class ),
607 Reg::getService( Interface_Regex::class )
608 );
609 }
610 return self::$cache[ Interface_Product_Service::class ];
611 }
612 );
613 Reg::registerService(
614 Interface_Shopper_Service::class,
615 static function () {
616 if ( ! isset( self::$cache[ Interface_Shopper_Service::class ] ) ) {
617 self::$cache[ Interface_Shopper_Service::class ] = new Shopper_Service();
618 }
619 return self::$cache[ Interface_Shopper_Service::class ];
620 }
621 );
622 Reg::registerService(
623 ShopOrderService::class,
624 static function () {
625 if ( ! isset( self::$cache[ ShopOrderService::class ] ) ) {
626 self::$cache[ ShopOrderService::class ] = new Shop_Order_Service(
627 Reg::getService( SeQuraOrderRepositoryInterface::class ),
628 Reg::getService( Interface_Logger_Service::class ),
629 Reg::getService( Interface_Create_Order_Request_Builder::class )
630 );
631 }
632 return self::$cache[ ShopOrderService::class ];
633 }
634 );
635 Reg::registerService(
636 Interface_Assets::class,
637 static function () {
638 if ( ! isset( self::$cache[ Interface_Assets::class ] ) ) {
639 self::$cache[ Interface_Assets::class ] = new Assets();
640 }
641 return self::$cache[ Interface_Assets::class ];
642 }
643 );
644 }
645
646 /**
647 * Initializes repositories.
648 */
649 protected static function initRepositories(): void {
650
651 Reg::registerService(
652 \wpdb::class,
653 static function () {
654 if ( ! isset( self::$cache[ \wpdb::class ] ) ) {
655 global $wpdb;
656 self::$cache[ \wpdb::class ] = $wpdb;
657 }
658 return self::$cache[ \wpdb::class ];
659 }
660 );
661
662 parent::initRepositories();
663
664 // Extend GeneralSettingsRepository.
665 Reg::registerService(
666 GeneralSettingsRepositoryInterface::class,
667 static function () {
668 return new General_Settings_Repository(
669 RepositoryRegistry::getRepository( GeneralSettings::getClassName() ),
670 Reg::getService( StoreContext::class )
671 );
672 }
673 );
674
675 // Extend WidgetSettingsRepository.
676 Reg::registerService(
677 WidgetSettingsRepositoryInterface::class,
678 static function () {
679 return new Widget_Settings_Repository(
680 RepositoryRegistry::getRepository( WidgetSettings::getClassName() ),
681 Reg::getService( StoreContext::class )
682 );
683 }
684 );
685
686 RepositoryRegistry::registerRepository( ConfigEntity::class, Entity_Repository::class );
687 RepositoryRegistry::registerRepository( QueueItem::class, Queue_Item_Repository::class );
688 RepositoryRegistry::registerRepository( Process::class, Entity_Repository::class );
689 RepositoryRegistry::registerRepository( ConnectionData::class, Entity_Repository::class );
690 RepositoryRegistry::registerRepository( OrderStatusSettings::class, Entity_Repository::class );
691 RepositoryRegistry::registerRepository( StatisticalData::class, Entity_Repository::class );
692 RepositoryRegistry::registerRepository( CountryConfiguration::class, Entity_Repository::class );
693 RepositoryRegistry::registerRepository( GeneralSettings::class, Entity_Repository::class );
694 RepositoryRegistry::registerRepository( SeQuraOrder::class, SeQura_Order_Repository::class );
695 RepositoryRegistry::registerRepository( WidgetSettings::class, Entity_Repository::class );
696 RepositoryRegistry::registerRepository( SendReport::class, Entity_Repository::class );
697 RepositoryRegistry::registerRepository( TransactionLog::class, Entity_Repository::class );
698 RepositoryRegistry::registerRepository( Payment_Methods::class, Entity_Repository::class );
699 }
700
701 /**
702 * Initializes controllers.
703 */
704 protected static function initControllers(): void {
705 parent::initControllers();
706
707 // Extend GeneralSettingsController.
708 Reg::registerService(
709 GeneralSettingsController::class,
710 static function () {
711 return new General_Settings_Controller(
712 Reg::getService( GeneralSettingsService::class ),
713 Reg::getService( CategoryService::class )
714 );
715 }
716 );
717
718 // Extend PromotionalWidgetsController.
719 Reg::registerService(
720 PromotionalWidgetsController::class,
721 static function () {
722 return new Promotional_Widgets_Controller(
723 Reg::getService( WidgetSettingsService::class )
724 );
725 }
726 );
727
728 // Plugin controllers.
729 Reg::registerService(
730 Interface_I18n_Controller::class,
731 static function () {
732 if ( ! isset( self::$cache[ Interface_I18n_Controller::class ] ) ) {
733 $data = self::get_constants()->get_plugin_data();
734 $domain = $data['TextDomain'];
735 self::$cache[ Interface_I18n_Controller::class ] = new I18n_Controller(
736 $domain . $data['DomainPath'],
737 $domain,
738 Reg::getService( Interface_Logger_Service::class ),
739 self::get_constants()->get_plugin_templates_path()
740 );
741 }
742 return self::$cache[ Interface_I18n_Controller::class ];
743 }
744 );
745 Reg::registerService(
746 Interface_Assets_Controller::class,
747 static function () {
748 if ( ! isset( self::$cache[ Interface_Assets_Controller::class ] ) ) {
749 $env_data = self::get_constants()->get_environment_data();
750 self::$cache[ Interface_Assets_Controller::class ] = new Assets_Controller(
751 self::get_constants()->get_plugin_assets_url(),
752 self::get_constants()->get_plugin_assets_path(),
753 self::get_constants()->get_plugin_data()['Version'],
754 $env_data['wp_version'] ?? '',
755 Reg::getService( Interface_I18n::class ),
756 Reg::getService( Interface_Logger_Service::class ),
757 self::get_constants()->get_plugin_templates_path(),
758 Reg::getService( Configuration::class ),
759 Reg::getService( Interface_Assets::class ),
760 Reg::getService( Interface_Payment_Method_Service::class ),
761 Reg::getService( Interface_Regex::class )
762 );
763 }
764 return self::$cache[ Interface_Assets_Controller::class ];
765 }
766 );
767 Reg::registerService(
768 Interface_Settings_Controller::class,
769 static function () {
770 if ( ! isset( self::$cache[ Interface_Settings_Controller::class ] ) ) {
771 self::$cache[ Interface_Settings_Controller::class ] = new Settings_Controller(
772 self::get_constants()->get_plugin_templates_path(),
773 Reg::getService( Configuration::class ),
774 Reg::getService( Interface_Logger_Service::class ),
775 self::get_constants()->get_plugin_basename()
776 );
777 }
778 return self::$cache[ Interface_Settings_Controller::class ];
779 }
780 );
781 Reg::registerService(
782 Interface_Payment_Controller::class,
783 static function () {
784 if ( ! isset( self::$cache[ Interface_Payment_Controller::class ] ) ) {
785 self::$cache[ Interface_Payment_Controller::class ] = new Payment_Controller(
786 Reg::getService( Interface_Logger_Service::class ),
787 self::get_constants()->get_plugin_templates_path(),
788 Reg::getService( Interface_Order_Service::class )
789 );
790 }
791 return self::$cache[ Interface_Payment_Controller::class ];
792 }
793 );
794 Reg::registerService(
795 Interface_Product_Controller::class,
796 static function () {
797 if ( ! isset( self::$cache[ Interface_Product_Controller::class ] ) ) {
798 self::$cache[ Interface_Product_Controller::class ] = new Product_Controller(
799 Reg::getService( Interface_Logger_Service::class ),
800 self::get_constants()->get_plugin_templates_path(),
801 Reg::getService( Configuration::class ),
802 Reg::getService( Interface_Product_Service::class ),
803 Reg::getService( Interface_Payment_Service::class ),
804 Reg::getService( Interface_Payment_Method_Service::class ),
805 Reg::getService( Interface_I18n::class ),
806 Reg::getService( Interface_Regex::class )
807 );
808 }
809 return self::$cache[ Interface_Product_Controller::class ];
810 }
811 );
812 Reg::registerService(
813 Interface_Async_Process_Controller::class,
814 static function () {
815 if ( ! isset( self::$cache[ Interface_Async_Process_Controller::class ] ) ) {
816 self::$cache[ Interface_Async_Process_Controller::class ] = new Async_Process_Controller(
817 Reg::getService( Interface_Logger_Service::class ),
818 self::get_constants()->get_plugin_templates_path(),
819 Reg::getService( Interface_Report_Service::class )
820 );
821 }
822 return self::$cache[ Interface_Async_Process_Controller::class ];
823 }
824 );
825 Reg::registerService(
826 Interface_Order_Controller::class,
827 static function () {
828 if ( ! isset( self::$cache[ Interface_Order_Controller::class ] ) ) {
829 self::$cache[ Interface_Order_Controller::class ] = new Order_Controller(
830 Reg::getService( Interface_Logger_Service::class ),
831 self::get_constants()->get_plugin_templates_path(),
832 Reg::getService( Interface_Order_Service::class )
833 );
834 }
835 return self::$cache[ Interface_Order_Controller::class ];
836 }
837 );
838 Reg::registerService(
839 Onboarding_REST_Controller::class,
840 static function () {
841 if ( ! isset( self::$cache[ Onboarding_REST_Controller::class ] ) ) {
842 self::$cache[ Onboarding_REST_Controller::class ] = new Onboarding_REST_Controller(
843 self::get_constants()->get_plugin_rest_namespace(),
844 Reg::getService( Interface_Logger_Service::class )
845 );
846 }
847 return self::$cache[ Onboarding_REST_Controller::class ];
848 }
849 );
850 Reg::registerService(
851 Payment_REST_Controller::class,
852 static function () {
853 if ( ! isset( self::$cache[ Payment_REST_Controller::class ] ) ) {
854 self::$cache[ Payment_REST_Controller::class ] = new Payment_REST_Controller(
855 self::get_constants()->get_plugin_rest_namespace(),
856 Reg::getService( Interface_Logger_Service::class ),
857 Reg::getService( Interface_Payment_Method_Service::class )
858 );
859 }
860 return self::$cache[ Payment_REST_Controller::class ];
861 }
862 );
863 Reg::registerService(
864 General_Settings_REST_Controller::class,
865 static function () {
866 if ( ! isset( self::$cache[ General_Settings_REST_Controller::class ] ) ) {
867 self::$cache[ General_Settings_REST_Controller::class ] = new General_Settings_REST_Controller(
868 self::get_constants()->get_plugin_rest_namespace(),
869 Reg::getService( Interface_Logger_Service::class )
870 );
871 }
872 return self::$cache[ General_Settings_REST_Controller::class ];
873 }
874 );
875 Reg::registerService(
876 Log_REST_Controller::class,
877 static function () {
878 if ( ! isset( self::$cache[ Log_REST_Controller::class ] ) ) {
879 self::$cache[ Log_REST_Controller::class ] = new Log_REST_Controller(
880 self::get_constants()->get_plugin_rest_namespace(),
881 Reg::getService( Interface_Logger_Service::class )
882 );
883 }
884 return self::$cache[ Log_REST_Controller::class ];
885 }
886 );
887 Reg::registerService(
888 Interface_Payment_Method_Service::class,
889 static function () {
890 if ( ! isset( self::$cache[ Interface_Payment_Method_Service::class ] ) ) {
891 self::$cache[ Interface_Payment_Method_Service::class ] = new Payment_Method_Service(
892 Reg::getService( Configuration::class ),
893 Reg::getService( Interface_Create_Order_Request_Builder::class ),
894 Reg::getService( Interface_Order_Service::class ),
895 Reg::getService( Interface_Logger_Service::class ),
896 RepositoryRegistry::getRepository( Payment_Methods::CLASS_NAME )
897 );
898 }
899 return self::$cache[ Interface_Payment_Method_Service::class ];
900 }
901 );
902 }
903 }
904