PluginProbe
seQura / 3.1.1
seQura v3.1.1
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.1, at src/class-bootstrap.php

912 lines 35.2 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 /**
573 * This will return Sequra_Order_Repository that implements Interface_Deletable_Repository.
574 *
575 * @var Interface_Deletable_Repository $deletable_repo
576 */
577 $deletable_repo = RepositoryRegistry::getRepository( SeQuraOrder::class );
578
579 self::$cache[ Interface_Order_Service::class ] = new Order_Service(
580 $deletable_repo,
581 Reg::getService( SeQuraOrderRepositoryInterface::class ),
582 Reg::getService( Interface_Payment_Service::class ),
583 Reg::getService( Interface_Pricing_Service::class ),
584 Reg::getService( OrderStatusSettingsService::class ),
585 Reg::getService( Configuration::class ),
586 Reg::getService( Interface_Cart_Service::class ),
587 Reg::getService( StoreContext::class ),
588 Reg::getService( Interface_Logger_Service::class )
589 );
590 }
591 return self::$cache[ Interface_Order_Service::class ];
592 }
593 );
594 Reg::registerService(
595 Interface_Cart_Service::class,
596 static function () {
597 if ( ! isset( self::$cache[ Interface_Cart_Service::class ] ) ) {
598 self::$cache[ Interface_Cart_Service::class ] = new Cart_Service(
599 Reg::getService( Interface_Product_Service::class ),
600 Reg::getService( Configuration::class ),
601 Reg::getService( Interface_Pricing_Service::class ),
602 Reg::getService( Interface_Logger_Service::class )
603 );
604 }
605 return self::$cache[ Interface_Cart_Service::class ];
606 }
607 );
608 Reg::registerService(
609 Interface_Product_Service::class,
610 static function () {
611 if ( ! isset( self::$cache[ Interface_Product_Service::class ] ) ) {
612 self::$cache[ Interface_Product_Service::class ] = new Product_Service(
613 Reg::getService( Configuration::class ),
614 Reg::getService( Interface_Pricing_Service::class ),
615 Reg::getService( Interface_Regex::class )
616 );
617 }
618 return self::$cache[ Interface_Product_Service::class ];
619 }
620 );
621 Reg::registerService(
622 Interface_Shopper_Service::class,
623 static function () {
624 if ( ! isset( self::$cache[ Interface_Shopper_Service::class ] ) ) {
625 self::$cache[ Interface_Shopper_Service::class ] = new Shopper_Service();
626 }
627 return self::$cache[ Interface_Shopper_Service::class ];
628 }
629 );
630 Reg::registerService(
631 ShopOrderService::class,
632 static function () {
633 if ( ! isset( self::$cache[ ShopOrderService::class ] ) ) {
634 self::$cache[ ShopOrderService::class ] = new Shop_Order_Service(
635 Reg::getService( SeQuraOrderRepositoryInterface::class ),
636 Reg::getService( Interface_Logger_Service::class ),
637 Reg::getService( Interface_Create_Order_Request_Builder::class )
638 );
639 }
640 return self::$cache[ ShopOrderService::class ];
641 }
642 );
643 Reg::registerService(
644 Interface_Assets::class,
645 static function () {
646 if ( ! isset( self::$cache[ Interface_Assets::class ] ) ) {
647 self::$cache[ Interface_Assets::class ] = new Assets();
648 }
649 return self::$cache[ Interface_Assets::class ];
650 }
651 );
652 }
653
654 /**
655 * Initializes repositories.
656 */
657 protected static function initRepositories(): void {
658
659 Reg::registerService(
660 \wpdb::class,
661 static function () {
662 if ( ! isset( self::$cache[ \wpdb::class ] ) ) {
663 global $wpdb;
664 self::$cache[ \wpdb::class ] = $wpdb;
665 }
666 return self::$cache[ \wpdb::class ];
667 }
668 );
669
670 parent::initRepositories();
671
672 // Extend GeneralSettingsRepository.
673 Reg::registerService(
674 GeneralSettingsRepositoryInterface::class,
675 static function () {
676 return new General_Settings_Repository(
677 RepositoryRegistry::getRepository( GeneralSettings::getClassName() ),
678 Reg::getService( StoreContext::class )
679 );
680 }
681 );
682
683 // Extend WidgetSettingsRepository.
684 Reg::registerService(
685 WidgetSettingsRepositoryInterface::class,
686 static function () {
687 return new Widget_Settings_Repository(
688 RepositoryRegistry::getRepository( WidgetSettings::getClassName() ),
689 Reg::getService( StoreContext::class )
690 );
691 }
692 );
693
694 RepositoryRegistry::registerRepository( ConfigEntity::class, Entity_Repository::class );
695 RepositoryRegistry::registerRepository( QueueItem::class, Queue_Item_Repository::class );
696 RepositoryRegistry::registerRepository( Process::class, Entity_Repository::class );
697 RepositoryRegistry::registerRepository( ConnectionData::class, Entity_Repository::class );
698 RepositoryRegistry::registerRepository( OrderStatusSettings::class, Entity_Repository::class );
699 RepositoryRegistry::registerRepository( StatisticalData::class, Entity_Repository::class );
700 RepositoryRegistry::registerRepository( CountryConfiguration::class, Entity_Repository::class );
701 RepositoryRegistry::registerRepository( GeneralSettings::class, Entity_Repository::class );
702 RepositoryRegistry::registerRepository( SeQuraOrder::class, SeQura_Order_Repository::class );
703 RepositoryRegistry::registerRepository( WidgetSettings::class, Entity_Repository::class );
704 RepositoryRegistry::registerRepository( SendReport::class, Entity_Repository::class );
705 RepositoryRegistry::registerRepository( TransactionLog::class, Entity_Repository::class );
706 RepositoryRegistry::registerRepository( Payment_Methods::class, Entity_Repository::class );
707 }
708
709 /**
710 * Initializes controllers.
711 */
712 protected static function initControllers(): void {
713 parent::initControllers();
714
715 // Extend GeneralSettingsController.
716 Reg::registerService(
717 GeneralSettingsController::class,
718 static function () {
719 return new General_Settings_Controller(
720 Reg::getService( GeneralSettingsService::class ),
721 Reg::getService( CategoryService::class )
722 );
723 }
724 );
725
726 // Extend PromotionalWidgetsController.
727 Reg::registerService(
728 PromotionalWidgetsController::class,
729 static function () {
730 return new Promotional_Widgets_Controller(
731 Reg::getService( WidgetSettingsService::class )
732 );
733 }
734 );
735
736 // Plugin controllers.
737 Reg::registerService(
738 Interface_I18n_Controller::class,
739 static function () {
740 if ( ! isset( self::$cache[ Interface_I18n_Controller::class ] ) ) {
741 $data = self::get_constants()->get_plugin_data();
742 $domain = $data['TextDomain'];
743 self::$cache[ Interface_I18n_Controller::class ] = new I18n_Controller(
744 $domain . $data['DomainPath'],
745 $domain,
746 Reg::getService( Interface_Logger_Service::class ),
747 self::get_constants()->get_plugin_templates_path()
748 );
749 }
750 return self::$cache[ Interface_I18n_Controller::class ];
751 }
752 );
753 Reg::registerService(
754 Interface_Assets_Controller::class,
755 static function () {
756 if ( ! isset( self::$cache[ Interface_Assets_Controller::class ] ) ) {
757 $env_data = self::get_constants()->get_environment_data();
758 self::$cache[ Interface_Assets_Controller::class ] = new Assets_Controller(
759 self::get_constants()->get_plugin_assets_url(),
760 self::get_constants()->get_plugin_assets_path(),
761 self::get_constants()->get_plugin_data()['Version'],
762 $env_data['wp_version'] ?? '',
763 Reg::getService( Interface_I18n::class ),
764 Reg::getService( Interface_Logger_Service::class ),
765 self::get_constants()->get_plugin_templates_path(),
766 Reg::getService( Configuration::class ),
767 Reg::getService( Interface_Assets::class ),
768 Reg::getService( Interface_Payment_Method_Service::class ),
769 Reg::getService( Interface_Regex::class )
770 );
771 }
772 return self::$cache[ Interface_Assets_Controller::class ];
773 }
774 );
775 Reg::registerService(
776 Interface_Settings_Controller::class,
777 static function () {
778 if ( ! isset( self::$cache[ Interface_Settings_Controller::class ] ) ) {
779 self::$cache[ Interface_Settings_Controller::class ] = new Settings_Controller(
780 self::get_constants()->get_plugin_templates_path(),
781 Reg::getService( Configuration::class ),
782 Reg::getService( Interface_Logger_Service::class ),
783 self::get_constants()->get_plugin_basename()
784 );
785 }
786 return self::$cache[ Interface_Settings_Controller::class ];
787 }
788 );
789 Reg::registerService(
790 Interface_Payment_Controller::class,
791 static function () {
792 if ( ! isset( self::$cache[ Interface_Payment_Controller::class ] ) ) {
793 self::$cache[ Interface_Payment_Controller::class ] = new Payment_Controller(
794 Reg::getService( Interface_Logger_Service::class ),
795 self::get_constants()->get_plugin_templates_path(),
796 Reg::getService( Interface_Order_Service::class )
797 );
798 }
799 return self::$cache[ Interface_Payment_Controller::class ];
800 }
801 );
802 Reg::registerService(
803 Interface_Product_Controller::class,
804 static function () {
805 if ( ! isset( self::$cache[ Interface_Product_Controller::class ] ) ) {
806 self::$cache[ Interface_Product_Controller::class ] = new Product_Controller(
807 Reg::getService( Interface_Logger_Service::class ),
808 self::get_constants()->get_plugin_templates_path(),
809 Reg::getService( Configuration::class ),
810 Reg::getService( Interface_Product_Service::class ),
811 Reg::getService( Interface_Payment_Service::class ),
812 Reg::getService( Interface_Payment_Method_Service::class ),
813 Reg::getService( Interface_I18n::class ),
814 Reg::getService( Interface_Regex::class )
815 );
816 }
817 return self::$cache[ Interface_Product_Controller::class ];
818 }
819 );
820 Reg::registerService(
821 Interface_Async_Process_Controller::class,
822 static function () {
823 if ( ! isset( self::$cache[ Interface_Async_Process_Controller::class ] ) ) {
824 self::$cache[ Interface_Async_Process_Controller::class ] = new Async_Process_Controller(
825 Reg::getService( Interface_Logger_Service::class ),
826 self::get_constants()->get_plugin_templates_path(),
827 Reg::getService( Interface_Report_Service::class )
828 );
829 }
830 return self::$cache[ Interface_Async_Process_Controller::class ];
831 }
832 );
833 Reg::registerService(
834 Interface_Order_Controller::class,
835 static function () {
836 if ( ! isset( self::$cache[ Interface_Order_Controller::class ] ) ) {
837 self::$cache[ Interface_Order_Controller::class ] = new Order_Controller(
838 Reg::getService( Interface_Logger_Service::class ),
839 self::get_constants()->get_plugin_templates_path(),
840 Reg::getService( Interface_Order_Service::class )
841 );
842 }
843 return self::$cache[ Interface_Order_Controller::class ];
844 }
845 );
846 Reg::registerService(
847 Onboarding_REST_Controller::class,
848 static function () {
849 if ( ! isset( self::$cache[ Onboarding_REST_Controller::class ] ) ) {
850 self::$cache[ Onboarding_REST_Controller::class ] = new Onboarding_REST_Controller(
851 self::get_constants()->get_plugin_rest_namespace(),
852 Reg::getService( Interface_Logger_Service::class )
853 );
854 }
855 return self::$cache[ Onboarding_REST_Controller::class ];
856 }
857 );
858 Reg::registerService(
859 Payment_REST_Controller::class,
860 static function () {
861 if ( ! isset( self::$cache[ Payment_REST_Controller::class ] ) ) {
862 self::$cache[ Payment_REST_Controller::class ] = new Payment_REST_Controller(
863 self::get_constants()->get_plugin_rest_namespace(),
864 Reg::getService( Interface_Logger_Service::class ),
865 Reg::getService( Interface_Payment_Method_Service::class )
866 );
867 }
868 return self::$cache[ Payment_REST_Controller::class ];
869 }
870 );
871 Reg::registerService(
872 General_Settings_REST_Controller::class,
873 static function () {
874 if ( ! isset( self::$cache[ General_Settings_REST_Controller::class ] ) ) {
875 self::$cache[ General_Settings_REST_Controller::class ] = new General_Settings_REST_Controller(
876 self::get_constants()->get_plugin_rest_namespace(),
877 Reg::getService( Interface_Logger_Service::class )
878 );
879 }
880 return self::$cache[ General_Settings_REST_Controller::class ];
881 }
882 );
883 Reg::registerService(
884 Log_REST_Controller::class,
885 static function () {
886 if ( ! isset( self::$cache[ Log_REST_Controller::class ] ) ) {
887 self::$cache[ Log_REST_Controller::class ] = new Log_REST_Controller(
888 self::get_constants()->get_plugin_rest_namespace(),
889 Reg::getService( Interface_Logger_Service::class )
890 );
891 }
892 return self::$cache[ Log_REST_Controller::class ];
893 }
894 );
895 Reg::registerService(
896 Interface_Payment_Method_Service::class,
897 static function () {
898 if ( ! isset( self::$cache[ Interface_Payment_Method_Service::class ] ) ) {
899 self::$cache[ Interface_Payment_Method_Service::class ] = new Payment_Method_Service(
900 Reg::getService( Configuration::class ),
901 Reg::getService( Interface_Create_Order_Request_Builder::class ),
902 Reg::getService( Interface_Order_Service::class ),
903 Reg::getService( Interface_Logger_Service::class ),
904 RepositoryRegistry::getRepository( Payment_Methods::CLASS_NAME )
905 );
906 }
907 return self::$cache[ Interface_Payment_Method_Service::class ];
908 }
909 );
910 }
911 }
912