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

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