PluginProbe
seQura / 3.0.5
seQura v3.0.5
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.0.5, at src/class-bootstrap.php

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