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

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

1,070 lines 41.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Implementation for the core bootstrap class.
4 *
5 * @package SeQura/WC
6 */
7
8 namespace SeQura\WC;
9
10 use SeQura\Core\BusinessLogic\BootstrapComponent;
11 use SeQura\Core\BusinessLogic\DataAccess\ConnectionData\Entities\ConnectionData;
12 use SeQura\Core\BusinessLogic\DataAccess\OrderSettings\Entities\OrderStatusSettings;
13 use SeQura\Core\BusinessLogic\DataAccess\PromotionalWidgets\Entities\WidgetSettings;
14 use SeQura\Core\BusinessLogic\DataAccess\SendReport\Entities\SendReport;
15 use SeQura\Core\BusinessLogic\DataAccess\StatisticalData\Entities\StatisticalData;
16 use SeQura\Core\BusinessLogic\DataAccess\TransactionLog\Entities\TransactionLog;
17 use SeQura\Core\BusinessLogic\DataAccess\CountryConfiguration\Entities\CountryConfiguration;
18 use SeQura\Core\BusinessLogic\DataAccess\Credentials\Entities\Credentials;
19 use SeQura\Core\BusinessLogic\DataAccess\Deployments\Entities\Deployment;
20 use SeQura\Core\BusinessLogic\DataAccess\GeneralSettings\Entities\GeneralSettings;
21 use SeQura\Core\BusinessLogic\DataAccess\PaymentMethod\Entities\PaymentMethod;
22 use SeQura\Core\BusinessLogic\Domain\Connection\Services\ConnectionService;
23 use SeQura\Core\BusinessLogic\Domain\Connection\Services\CredentialsService;
24 use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\RepositoryContracts\CountryConfigurationRepositoryInterface;
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\Order\MerchantDataProviderInterface;
28 use SeQura\Core\BusinessLogic\Domain\Integration\Order\OrderCreationInterface;
29 use SeQura\Core\BusinessLogic\Domain\Integration\OrderReport\OrderReportServiceInterface;
30 use SeQura\Core\BusinessLogic\Domain\Integration\Product\ProductServiceInterface;
31 use SeQura\Core\BusinessLogic\Domain\Integration\SellingCountries\SellingCountriesServiceInterface;
32 use SeQura\Core\BusinessLogic\Domain\Integration\ShopOrderStatuses\ShopOrderStatusesServiceInterface;
33 use SeQura\Core\BusinessLogic\Domain\Integration\Store\StoreServiceInterface;
34 use SeQura\Core\BusinessLogic\Domain\Integration\Version\VersionServiceInterface;
35 use SeQura\Core\BusinessLogic\Domain\Multistore\StoreContext;
36 use SeQura\Core\BusinessLogic\Domain\Order\Models\SeQuraOrder;
37 use SeQura\Core\BusinessLogic\Domain\Order\RepositoryContracts\SeQuraOrderRepositoryInterface;
38 use SeQura\Core\BusinessLogic\Domain\OrderStatusSettings\RepositoryContracts\OrderStatusSettingsRepositoryInterface;
39 use SeQura\Core\BusinessLogic\Domain\OrderStatusSettings\Services\OrderStatusSettingsService;
40 use SeQura\Core\BusinessLogic\Domain\StatisticalData\RepositoryContracts\StatisticalDataRepositoryInterface;
41 use SeQura\Core\BusinessLogic\Utility\EncryptorInterface;
42 use SeQura\Core\BusinessLogic\Webhook\Services\ShopOrderService;
43 use SeQura\Core\Infrastructure\Configuration\ConfigEntity;
44 use SeQura\Core\Infrastructure\Exceptions\ServiceNotRegisteredException;
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\Extension\BusinessLogic\Domain\Order\Builders\Interface_Create_Order_Request_Builder;
74 use SeQura\WC\Core\Extension\BusinessLogic\Domain\OrderStatusSettings\Services\Order_Status_Settings_Service;
75 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Category\Category_Service;
76 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Disconnect\Disconnect_Service;
77 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\ShopOrderStatuses\Shop_Order_Status_Service;
78 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Order\Builders\Create_Order_Request_Builder;
79 use SeQura\WC\Core\Implementation\BusinessLogic\Utility\Encryptor;
80 use SeQura\WC\Core\Implementation\BusinessLogic\Webhook\Services\Shop_Order_Service;
81 use SeQura\WC\Core\Implementation\Infrastructure\Logger\Interfaces\Default_Logger_Adapter;
82 use SeQura\WC\Core\Implementation\Infrastructure\Logger\Interfaces\Shop_Logger_Adapter;
83 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\OrderReport\Order_Report_Service;
84 use SeQura\WC\Repositories\Entity_Repository;
85 use SeQura\WC\Repositories\Migrations\Migration_Install_300;
86 use SeQura\WC\Repositories\Migrations\Migration_Install_320;
87 use SeQura\WC\Repositories\Queue_Item_Repository;
88 use SeQura\WC\Repositories\Repository;
89 use SeQura\WC\Repositories\SeQura_Order_Repository;
90 use SeQura\WC\Services\Cart\Cart_Service;
91 use SeQura\WC\Services\Cart\Interface_Cart_Service;
92 use SeQura\WC\Services\Constants\Constants;
93 use SeQura\WC\Services\Core\Selling_Countries_Service;
94 use SeQura\WC\Services\Core\Store_Service;
95 use SeQura\WC\Services\Core\Version_Service;
96 use SeQura\WC\Services\Shopper\Shopper_Service;
97 use SeQura\WC\Services\Shopper\Interface_Shopper_Service;
98 use SeQura\WC\Services\I18n\I18n;
99 use SeQura\WC\Services\I18n\Interface_I18n;
100 use SeQura\WC\Services\Log\Interface_Log_File;
101 use SeQura\WC\Services\Log\Interface_Logger_Service;
102 use SeQura\WC\Services\Log\Log_File;
103 use SeQura\WC\Services\Log\Logger_Service;
104 use SeQura\WC\Services\Migration\Interface_Migration_Manager;
105 use SeQura\WC\Services\Migration\Migration_Manager;
106 use SeQura\WC\Services\Order\Interface_Order_Service;
107 use SeQura\WC\Services\Order\Order_Service;
108 use SeQura\WC\Services\Payment\Interface_Payment_Method_Service;
109 use SeQura\WC\Services\Payment\Payment_Method_Service;
110 use SeQura\WC\Services\Payment\Sequra_Payment_Gateway_Block_Support;
111 use SeQura\WC\Services\Pricing\Interface_Pricing_Service;
112 use SeQura\WC\Services\Pricing\Pricing_Service;
113 use SeQura\WC\Services\Product\Interface_Product_Service;
114 use SeQura\WC\Services\Product\Product_Service;
115 use SeQura\WC\Services\Report\Interface_Report_Service;
116 use SeQura\WC\Services\Report\Report_Service;
117 use SeQura\WC\Services\Constants\Interface_Constants;
118 use SeQura\WC\Services\Time\Interface_Time_Checker_Service;
119 use SeQura\WC\Services\Time\Time_Checker_Service;
120 use SeQura\Core\BusinessLogic\Domain\Integration\PromotionalWidgets\WidgetConfiguratorInterface;
121 use SeQura\Core\BusinessLogic\Domain\Integration\PromotionalWidgets\MiniWidgetMessagesProviderInterface;
122 use SeQura\Core\BusinessLogic\Domain\Order\Builders\MerchantOrderRequestBuilder;
123 use SeQura\Core\BusinessLogic\Domain\Order\Service\OrderService;
124 use SeQura\Core\Infrastructure\Configuration\Configuration;
125 use SeQura\Core\Infrastructure\Utility\RegexProvider;
126 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Order\Merchant_Data_Provider;
127 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Order\Order_Creation;
128 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\Product\Product_Service as Core_Product_Service;
129 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\PromotionalWidgets\Mini_Widget_Messages_Provider;
130 use SeQura\WC\Core\Implementation\BusinessLogic\Domain\Integration\PromotionalWidgets\Widget_Configurator;
131 use SeQura\WC\Repositories\Migrations\Migration_Install_400;
132 use SeQura\WC\Services\Order\Current_Order_Provider;
133 use SeQura\WC\Services\Order\Interface_Current_Order_Provider;
134 use SeQura\WC\Services\Platform\Interface_Platform_Provider;
135 use SeQura\WC\Services\Platform\Platform_Provider;
136 use SeQura\WC\Services\Widgets\Interface_Widgets_Service;
137 use SeQura\WC\Services\Widgets\Widgets_Service;
138 use SeQura\Core\BusinessLogic\Domain\Integration\Store\StoreIdProvider;
139 use SeQura\Core\Infrastructure\Configuration\ConfigurationManager;
140 use SeQura\WC\Core\Extension\BusinessLogic\Domain\Integration\Store\Store_Id_Provider;
141 use SeQura\WC\Services\Order\Builder\Interface_Order_Address_Builder;
142 use SeQura\WC\Services\Order\Builder\Order_Address_Builder;
143 use SeQura\WC\Services\Order\Builder\Interface_Order_Customer_Builder;
144 use SeQura\WC\Services\Order\Builder\Interface_Order_Delivery_Method_Builder;
145 use SeQura\WC\Services\Order\Builder\Order_Customer_Builder;
146 use SeQura\WC\Services\Order\Builder\Order_Delivery_Method_Builder;
147 use SeQura\WC\Services\Service\Interface_Settings_Service;
148 use SeQura\WC\Services\Service\Settings_Service;
149
150 /**
151 * Implementation for the core bootstrap class.
152 */
153 class Bootstrap extends BootstrapComponent {
154
155
156 /**
157 * Cache for Service instances.
158 *
159 * @var array<string, mixed>
160 */
161 private static $cache = array();
162
163 /**
164 * Initialize the bootstrap.
165 */
166 public static function init(): void {
167 self::initConstants();
168 parent::init();
169
170 Reg::registerService(
171 Plugin::class,
172 static function () {
173 return new Plugin(
174 Reg::getService( Interface_Constants::class ),
175 Reg::getService( Interface_Migration_Manager::class ),
176 Reg::getService( Interface_I18n_Controller::class ),
177 Reg::getService( Interface_Assets_Controller::class ),
178 Reg::getService( Interface_Settings_Controller::class ),
179 Reg::getService( Interface_Payment_Controller::class ),
180 Reg::getService( General_Settings_REST_Controller::class ),
181 Reg::getService( Onboarding_REST_Controller::class ),
182 Reg::getService( Payment_REST_Controller::class ),
183 Reg::getService( Log_REST_Controller::class ),
184 Reg::getService( Interface_Product_Controller::class ),
185 Reg::getService( Interface_Async_Process_Controller::class ),
186 Reg::getService( Interface_Order_Controller::class )
187 );
188 }
189 );
190 }
191
192 /**
193 * Initializes constants.
194 */
195 public static function initConstants(): void {
196 Reg::registerService(
197 Interface_Constants::class,
198 static function () {
199
200 if ( ! isset( self::$cache[ Interface_Constants::class ] ) ) {
201 $dir_path = \trailingslashit( dirname( __DIR__, 1 ) );
202 $plugin_file_path = $dir_path . 'sequra.php';
203
204 if ( ! function_exists( 'get_plugin_data' ) ) {
205 require_once ABSPATH . 'wp-admin/includes/plugin.php';
206 }
207 $add_wc_headers = function ( $headers ) {
208 $headers['WC requires at least'] = 'WC requires at least';
209 return $headers;
210 };
211 \add_filter( 'extra_plugin_headers', $add_wc_headers );
212 $data = \get_plugin_data( $plugin_file_path, true, false );
213 \remove_filter( 'extra_plugin_headers', $add_wc_headers );
214 $data['RequiresWC'] = $data['WC requires at least'];
215 unset( $data['WC requires at least'] );
216
217 /**
218 * Database instance.
219 *
220 * @var \wpdb $wpdb
221 */
222 $wpdb = Reg::getService( \wpdb::class );
223 global $wp_version;
224
225 $environment_data = array(
226 'php_version' => phpversion(),
227 'php_os' => PHP_OS,
228 'uname' => php_uname(),
229 'db_name' => false === strpos( strtolower( $wpdb->db_server_info() ), 'mariadb' ) ? 'mysql' : 'mariadb',
230 'db_version' => $wpdb->db_version() ?? '',
231 'wp_version' => strval( $wp_version ),
232 );
233
234 $dir_url = \plugin_dir_url( $plugin_file_path );
235
236 self::$cache[ Interface_Constants::class ] = new Constants(
237 $dir_path,
238 $plugin_file_path,
239 $dir_path . 'sequra.{storeId}.log',
240 \plugin_basename( $plugin_file_path ),
241 $dir_url,
242 'sequra/v1',
243 $data,
244 \get_plugin_data( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php', true, false ),
245 $environment_data,
246 $dir_path . 'templates/',
247 $dir_path . 'assets',
248 \untrailingslashit( $dir_url ) . '/assets'
249 );
250 }
251
252 return self::$cache[ Interface_Constants::class ];
253 }
254 );
255 }
256
257 /**
258 * Get the constants instance.
259 *
260 * @return Interface_Constants
261 * @throws ServiceNotRegisteredException
262 */
263 private static function get_constants() {
264 return Reg::getService( Interface_Constants::class );
265 }
266
267 /**
268 * Initializes services and utilities.
269 */
270 protected static function initServices(): void {
271 parent::initServices();
272
273 // Core Default.
274 Reg::registerService(
275 LoggerConfiguration::class,
276 static function () {
277 if ( ! isset( self::$cache[ LoggerConfiguration::class ] ) ) {
278 $loggerConfig = LoggerConfiguration::getInstance();
279 if ( ! $loggerConfig->isDefaultLoggerEnabled() ) {
280 $loggerConfig->setIsDefaultLoggerEnabled( false );
281 }
282 self::$cache[ LoggerConfiguration::class ] = $loggerConfig;
283 }
284 return self::$cache[ LoggerConfiguration::class ];
285 }
286 );
287
288 // Core Extension.
289 Reg::registerService(
290 Order_Status_Settings_Service::class,
291 static function () {
292 if ( ! isset( self::$cache[ Order_Status_Settings_Service::class ] ) ) {
293 self::$cache[ Order_Status_Settings_Service::class ] = new Order_Status_Settings_Service(
294 Reg::getService( OrderStatusSettingsRepositoryInterface::class ),
295 Reg::getService( ShopOrderStatusesServiceInterface::class )
296 );
297 }
298 return self::$cache[ Order_Status_Settings_Service::class ];
299 }
300 );
301 Reg::registerService(
302 OrderStatusSettingsService::class,
303 static function () {
304 return Reg::getService( Order_Status_Settings_Service::class );
305 }
306 );
307 // Extend Configuration.
308 Reg::registerService(
309 Configuration::class,
310 static function () {
311 if ( ! isset( self::$cache[ Configuration::class ] ) ) {
312 self::$cache[ Configuration::class ] = \SeQura\WC\Core\Extension\Infrastructure\Configuration\Configuration::getInstance();
313 }
314 return self::$cache[ Configuration::class ];
315 }
316 );
317
318 /**
319 * Initialize StoreContext with default store ID so any service that depends on StoreContext
320 * will have the correct store ID set from the beginning. This will reduce the StoreContext::doWithStore
321 * calls to the cases where it's really necessary to set a different store ID.
322 */
323 Reg::registerService(
324 StoreIdProvider::class,
325 static function () {
326 if ( ! isset( self::$cache[ StoreIdProvider::class ] ) ) {
327 self::$cache[ StoreIdProvider::class ] = new Store_Id_Provider();
328 }
329 return self::$cache[ StoreIdProvider::class ];
330 }
331 );
332
333 Reg::registerService(
334 Interface_Create_Order_Request_Builder::class,
335 static function () {
336 if ( ! isset( self::$cache[ Interface_Create_Order_Request_Builder::class ] ) ) {
337 self::$cache[ Interface_Create_Order_Request_Builder::class ] = new Create_Order_Request_Builder(
338 Reg::getService( Interface_Cart_Service::class ),
339 Reg::getService( Interface_Platform_Provider::class ),
340 Reg::getService( Interface_Product_Service::class ),
341 Reg::getService( Interface_Order_Service::class ),
342 Reg::getService( Interface_I18n::class ),
343 Reg::getService( Interface_Shopper_Service::class ),
344 Reg::getService( Interface_Logger_Service::class ),
345 Reg::getService( Interface_Current_Order_Provider::class ),
346 Reg::getService( MerchantOrderRequestBuilder::class ),
347 Reg::getService( Interface_Order_Delivery_Method_Builder::class ),
348 Reg::getService( Interface_Order_Address_Builder::class ),
349 Reg::getService( Interface_Order_Customer_Builder::class ),
350 Reg::getService( CredentialsService::class ),
351 Reg::getService( SeQuraOrderRepositoryInterface::class )
352 );
353 }
354 return self::$cache[ Interface_Create_Order_Request_Builder::class ];
355 }
356 );
357
358 // Core Implementation.
359 Reg::registerService(
360 EncryptorInterface::class,
361 static function () {
362 if ( ! isset( self::$cache[ EncryptorInterface::class ] ) ) {
363 self::$cache[ EncryptorInterface::class ] = new Encryptor();
364 }
365 return self::$cache[ EncryptorInterface::class ];
366 }
367 );
368 Reg::registerService(
369 DisconnectServiceInterface::class,
370 static function () {
371 if ( ! isset( self::$cache[ DisconnectServiceInterface::class ] ) ) {
372 self::$cache[ DisconnectServiceInterface::class ] = new Disconnect_Service(
373 array(
374 RepositoryRegistry::getRepository( ConnectionData::class ),
375 RepositoryRegistry::getRepository( StatisticalData::class ),
376 RepositoryRegistry::getRepository( SendReport::class ),
377 RepositoryRegistry::getRepository( QueueItem::class ),
378 )
379 );
380 }
381 return self::$cache[ DisconnectServiceInterface::class ];
382 }
383 );
384 Reg::registerService(
385 OrderReportServiceInterface::class,
386 static function () {
387 if ( ! isset( self::$cache[ OrderReportServiceInterface::class ] ) ) {
388 self::$cache[ OrderReportServiceInterface::class ] = new Order_Report_Service(
389 Reg::getService( Interface_Platform_Provider::class ),
390 Reg::getService( Interface_Pricing_Service::class ),
391 Reg::getService( Interface_Cart_Service::class ),
392 Reg::getService( Interface_Order_Service::class ),
393 Reg::getService( Interface_I18n::class ),
394 Reg::getService( Interface_Order_Delivery_Method_Builder::class ),
395 Reg::getService( Interface_Order_Address_Builder::class ),
396 Reg::getService( Interface_Order_Customer_Builder::class )
397 );
398 }
399 return self::$cache[ OrderReportServiceInterface::class ];
400 }
401 );
402 Reg::registerService(
403 MerchantDataProviderInterface::class,
404 static function () {
405 if ( ! isset( self::$cache[ MerchantDataProviderInterface::class ] ) ) {
406 self::$cache[ MerchantDataProviderInterface::class ] = new Merchant_Data_Provider(
407 Reg::getService( Interface_Current_Order_Provider::class ),
408 Reg::getService( Interface_Constants::class ),
409 Reg::getService( Interface_Product_Service::class ),
410 Reg::getService( Interface_Cart_Service::class ),
411 Reg::getService( Interface_Shopper_Service::class ),
412 Reg::getService( StoreContext::class )
413 );
414 }
415 return self::$cache[ MerchantDataProviderInterface::class ];
416 }
417 );
418 Reg::registerService(
419 OrderCreationInterface::class,
420 static function () {
421 if ( ! isset( self::$cache[ OrderCreationInterface::class ] ) ) {
422 self::$cache[ OrderCreationInterface::class ] = new Order_Creation();
423 }
424 return self::$cache[ OrderCreationInterface::class ];
425 }
426 );
427
428
429 Reg::registerService(
430 Serializer::class,
431 static function () {
432 if ( ! isset( self::$cache[ Serializer::class ] ) ) {
433 self::$cache[ Serializer::class ] = new JsonSerializer();
434 }
435 return self::$cache[ Serializer::class ];
436 }
437 );
438 Reg::registerService(
439 SellingCountriesServiceInterface::class,
440 static function () {
441 if ( ! isset( self::$cache[ SellingCountriesServiceInterface::class ] ) ) {
442 self::$cache[ SellingCountriesServiceInterface::class ] = new Selling_Countries_Service();
443 }
444 return self::$cache[ SellingCountriesServiceInterface::class ];
445 }
446 );
447 Reg::registerService(
448 StoreServiceInterface::class,
449 static function () {
450 if ( ! isset( self::$cache[ StoreServiceInterface::class ] ) ) {
451 self::$cache[ StoreServiceInterface::class ] = new Store_Service();
452 }
453 return self::$cache[ StoreServiceInterface::class ];
454 }
455 );
456 Reg::registerService(
457 VersionServiceInterface::class,
458 static function () {
459 if ( ! isset( self::$cache[ VersionServiceInterface::class ] ) ) {
460 self::$cache[ VersionServiceInterface::class ] = new Version_Service(
461 self::get_constants()->get_plugin_data()['Version']
462 );
463 }
464 return self::$cache[ VersionServiceInterface::class ];
465 }
466 );
467 Reg::registerService(
468 CategoryServiceInterface::class,
469 static function () {
470 if ( ! isset( self::$cache[ CategoryServiceInterface::class ] ) ) {
471 self::$cache[ CategoryServiceInterface::class ] = new Category_Service();
472 }
473 return self::$cache[ CategoryServiceInterface::class ];
474 }
475 );
476 Reg::registerService(
477 ShopOrderStatusesServiceInterface::class,
478 static function () {
479 if ( ! isset( self::$cache[ ShopOrderStatusesServiceInterface::class ] ) ) {
480 self::$cache[ ShopOrderStatusesServiceInterface::class ] = new Shop_Order_Status_Service();
481 }
482 return self::$cache[ ShopOrderStatusesServiceInterface::class ];
483 }
484 );
485 Reg::registerService(
486 ShopLoggerAdapter::CLASS_NAME,
487 static function () {
488 if ( ! isset( self::$cache[ ShopLoggerAdapter::CLASS_NAME ] ) ) {
489 self::$cache[ ShopLoggerAdapter::CLASS_NAME ] = new Shop_Logger_Adapter();
490 }
491 return self::$cache[ ShopLoggerAdapter::CLASS_NAME ];
492 }
493 );
494 Reg::registerService(
495 DefaultLoggerAdapter::CLASS_NAME,
496 static function () {
497 if ( ! isset( self::$cache[ DefaultLoggerAdapter::CLASS_NAME ] ) ) {
498 self::$cache[ DefaultLoggerAdapter::CLASS_NAME ] = new Default_Logger_Adapter(
499 Reg::getService( Interface_Log_File::class ),
500 Reg::getService( TimeProvider::CLASS_NAME )
501 );
502 }
503 return self::$cache[ DefaultLoggerAdapter::CLASS_NAME ];
504 }
505 );
506
507 // Plugin services.
508 Reg::registerService(
509 Interface_Log_File::class,
510 static function () {
511 if ( ! isset( self::$cache[ Interface_Log_File::class ] ) ) {
512 self::$cache[ Interface_Log_File::class ] = new Log_File(
513 self::get_constants()->get_plugin_log_file_path(),
514 Reg::getService( StoreContext::class )
515 );
516 }
517 return self::$cache[ Interface_Log_File::class ];
518 }
519 );
520 Reg::registerService(
521 Interface_Migration_Manager::class,
522 static function () {
523 if ( ! isset( self::$cache[ Interface_Migration_Manager::class ] ) ) {
524 $configuration = Reg::getService( ConfigurationManager::CLASS_NAME );
525 $wpdb = Reg::getService( \wpdb::class );
526 /**
527 * Order repository.
528 *
529 * @var Repository $order_repository
530 */
531 $order_repository = RepositoryRegistry::getRepository( SeQuraOrder::class );
532 /**
533 * Entity repository.
534 *
535 * @var Repository $entity_repository
536 */
537 $entity_repository = RepositoryRegistry::getRepository( ConfigEntity::class );
538
539 /**
540 * Queue item repository.
541 *
542 * @var Repository $queue_item_repository
543 */
544 $queue_item_repository = RepositoryRegistry::getRepository( QueueItem::class );
545 /**
546 * Encryptor service.
547 *
548 * @var EncryptorInterface $encryptor
549 */
550 $encryptor = Reg::getService( EncryptorInterface::class );
551
552 /**
553 * Store context service.
554 *
555 * @var StoreContext $store_context
556 */
557 $store_context = Reg::getService( StoreContext::class );
558
559 self::$cache[ Interface_Migration_Manager::class ] = new Migration_Manager(
560 self::get_constants()->get_plugin_basename(),
561 $configuration,
562 self::get_constants()->get_plugin_data()['Version'],
563 array(
564 new Migration_Install_300(
565 $wpdb,
566 $order_repository,
567 $entity_repository,
568 $queue_item_repository,
569 $store_context
570 ),
571 new Migration_Install_320(
572 $wpdb,
573 self::get_constants()->get_hook_add_order_indexes(),
574 $entity_repository,
575 $queue_item_repository
576 ),
577 new Migration_Install_400(
578 $wpdb,
579 $encryptor,
580 $store_context,
581 ),
582 )
583 );
584 }
585 return self::$cache[ Interface_Migration_Manager::class ];
586 }
587 );
588 Reg::registerService(
589 Interface_I18n::class,
590 static function () {
591 if ( ! isset( self::$cache[ Interface_I18n::class ] ) ) {
592 self::$cache[ Interface_I18n::class ] = new I18n();
593 }
594 return self::$cache[ Interface_I18n::class ];
595 }
596 );
597 Reg::registerService(
598 Interface_Report_Service::class,
599 static function () {
600 if ( ! isset( self::$cache[ Interface_Report_Service::class ] ) ) {
601 self::$cache[ Interface_Report_Service::class ] = new Report_Service(
602 Reg::getService( ShopOrderService::class ),
603 Reg::getService( StatisticalDataRepositoryInterface::class ),
604 Reg::getService( CountryConfigurationRepositoryInterface::class ),
605 Reg::getService( Interface_Order_Service::class )
606 );
607 }
608 return self::$cache[ Interface_Report_Service::class ];
609 }
610 );
611 Reg::registerService(
612 Interface_Logger_Service::class,
613 static function () {
614 if ( ! isset( self::$cache[ Interface_Logger_Service::class ] ) ) {
615 self::$cache[ Interface_Logger_Service::class ] = new Logger_Service(
616 Reg::getService( LoggerConfiguration::class ),
617 Reg::getService( Interface_Log_File::class )
618 );
619 }
620 return self::$cache[ Interface_Logger_Service::class ];
621 }
622 );
623
624 Reg::registerService(
625 Sequra_Payment_Gateway_Block_Support::class,
626 static function () {
627 if ( ! isset( self::$cache[ Sequra_Payment_Gateway_Block_Support::class ] ) ) {
628 self::$cache[ Sequra_Payment_Gateway_Block_Support::class ] = new Sequra_Payment_Gateway_Block_Support(
629 self::get_constants()->get_plugin_assets_path(),
630 self::get_constants()->get_plugin_assets_url(),
631 self::get_constants()->get_plugin_data()['Version']
632 );
633 }
634 return self::$cache[ Sequra_Payment_Gateway_Block_Support::class ];
635 }
636 );
637 Reg::registerService(
638 Interface_Pricing_Service::class,
639 static function () {
640 if ( ! isset( self::$cache[ Interface_Pricing_Service::class ] ) ) {
641 self::$cache[ Interface_Pricing_Service::class ] = new Pricing_Service();
642 }
643 return self::$cache[ Interface_Pricing_Service::class ];
644 }
645 );
646 Reg::registerService(
647 Interface_Order_Service::class,
648 static function () {
649 if ( ! isset( self::$cache[ Interface_Order_Service::class ] ) ) {
650 /**
651 * This will return SeQura_Order_Repository that implements Interface_Deletable_Repository and Interface_Table_Migration_Repository.
652 *
653 * @var SeQura_Order_Repository $repository
654 */
655 $repository = RepositoryRegistry::getRepository( SeQuraOrder::class );
656
657 self::$cache[ Interface_Order_Service::class ] = new Order_Service(
658 Reg::getService( SeQuraOrderRepositoryInterface::class ),
659 Reg::getService( Interface_Pricing_Service::class ),
660 Reg::getService( OrderStatusSettingsService::class ),
661 Reg::getService( Interface_Cart_Service::class ),
662 Reg::getService( Interface_Logger_Service::class ),
663 Reg::getService( Interface_Time_Checker_Service::class ),
664 $repository,
665 $repository,
666 self::get_constants()->get_payment_gateway_id(),
667 Reg::getService( ConnectionService::class ),
668 Reg::getService( OrderService::class )
669 );
670 }
671 return self::$cache[ Interface_Order_Service::class ];
672 }
673 );
674 Reg::registerService(
675 Interface_Cart_Service::class,
676 static function () {
677 if ( ! isset( self::$cache[ Interface_Cart_Service::class ] ) ) {
678 self::$cache[ Interface_Cart_Service::class ] = new Cart_Service(
679 Reg::getService( Interface_Product_Service::class ),
680 Reg::getService( Interface_Pricing_Service::class ),
681 Reg::getService( Interface_Logger_Service::class ),
682 Reg::getService( Interface_Shopper_Service::class )
683 );
684 }
685 return self::$cache[ Interface_Cart_Service::class ];
686 }
687 );
688 Reg::registerService(
689 Interface_Product_Service::class,
690 static function () {
691 if ( ! isset( self::$cache[ Interface_Product_Service::class ] ) ) {
692 self::$cache[ Interface_Product_Service::class ] = new Product_Service(
693 Reg::getService( Interface_Pricing_Service::class ),
694 Reg::getService( RegexProvider::class ),
695 Reg::getService( StoreContext::class )
696 );
697 }
698 return self::$cache[ Interface_Product_Service::class ];
699 }
700 );
701 Reg::registerService(
702 Interface_Shopper_Service::class,
703 static function () {
704 if ( ! isset( self::$cache[ Interface_Shopper_Service::class ] ) ) {
705 self::$cache[ Interface_Shopper_Service::class ] = new Shopper_Service(
706 Reg::getService( StoreContext::class )
707 );
708 }
709 return self::$cache[ Interface_Shopper_Service::class ];
710 }
711 );
712 Reg::registerService(
713 ShopOrderService::class,
714 static function () {
715 if ( ! isset( self::$cache[ ShopOrderService::class ] ) ) {
716 self::$cache[ ShopOrderService::class ] = new Shop_Order_Service(
717 Reg::getService( SeQuraOrderRepositoryInterface::class ),
718 Reg::getService( Interface_Logger_Service::class ),
719 Reg::getService( Interface_Create_Order_Request_Builder::class ),
720 Reg::getService( Interface_Current_Order_Provider::class ),
721 Reg::getService( OrderService::class )
722 );
723 }
724 return self::$cache[ ShopOrderService::class ];
725 }
726 );
727 Reg::registerService(
728 Interface_Time_Checker_Service::class,
729 static function () {
730 if ( ! isset( self::$cache[ Interface_Time_Checker_Service::class ] ) ) {
731 self::$cache[ Interface_Time_Checker_Service::class ] = new Time_Checker_Service();
732 }
733 return self::$cache[ Interface_Time_Checker_Service::class ];
734 }
735 );
736
737 Reg::registerService(
738 ProductServiceInterface::class,
739 static function () {
740 if ( ! isset( self::$cache[ ProductServiceInterface::class ] ) ) {
741 self::$cache[ ProductServiceInterface::class ] = new Core_Product_Service();
742 }
743 return self::$cache[ ProductServiceInterface::class ];
744 }
745 );
746 Reg::registerService(
747 WidgetConfiguratorInterface::class,
748 static function () {
749 if ( ! isset( self::$cache[ WidgetConfiguratorInterface::class ] ) ) {
750 self::$cache[ WidgetConfiguratorInterface::class ] = new Widget_Configurator(
751 Reg::getService( Interface_I18n::class )
752 );
753 }
754 return self::$cache[ WidgetConfiguratorInterface::class ];
755 }
756 );
757
758 Reg::registerService(
759 MiniWidgetMessagesProviderInterface::class,
760 static function () {
761 if ( ! isset( self::$cache[ MiniWidgetMessagesProviderInterface::class ] ) ) {
762 self::$cache[ MiniWidgetMessagesProviderInterface::class ] = new Mini_Widget_Messages_Provider(
763 Reg::getService( Interface_I18n::class )
764 );
765 }
766 return self::$cache[ MiniWidgetMessagesProviderInterface::class ];
767 }
768 );
769
770 Reg::registerService(
771 Interface_Current_Order_Provider::class,
772 static function () {
773 if ( ! isset( self::$cache[ Interface_Current_Order_Provider::class ] ) ) {
774 self::$cache[ Interface_Current_Order_Provider::class ] = new Current_Order_Provider();
775 }
776 return self::$cache[ Interface_Current_Order_Provider::class ];
777 }
778 );
779
780 Reg::registerService(
781 Interface_Platform_Provider::class,
782 static function () {
783 if ( ! isset( self::$cache[ Interface_Platform_Provider::class ] ) ) {
784 self::$cache[ Interface_Platform_Provider::class ] = new Platform_Provider(
785 Reg::getService( Interface_Constants::class )
786 );
787 }
788 return self::$cache[ Interface_Platform_Provider::class ];
789 }
790 );
791
792 Reg::registerService(
793 Interface_Payment_Method_Service::class,
794 static function () {
795 if ( ! isset( self::$cache[ Interface_Payment_Method_Service::class ] ) ) {
796 self::$cache[ Interface_Payment_Method_Service::class ] = new Payment_Method_Service(
797 Reg::getService( Interface_Create_Order_Request_Builder::class ),
798 Reg::getService( Interface_Order_Service::class ),
799 Reg::getService( Interface_Logger_Service::class ),
800 Reg::getService( Interface_Current_Order_Provider::class ),
801 Reg::getService( StoreContext::class )
802 );
803 }
804 return self::$cache[ Interface_Payment_Method_Service::class ];
805 }
806 );
807
808 Reg::registerService(
809 Interface_Widgets_Service::class,
810 static function () {
811 if ( ! isset( self::$cache[ Interface_Widgets_Service::class ] ) ) {
812 self::$cache[ Interface_Widgets_Service::class ] = new Widgets_Service(
813 Reg::getService( Interface_Logger_Service::class ),
814 Reg::getService( Interface_I18n::class ),
815 Reg::getService( Interface_Shopper_Service::class ),
816 Reg::getService( WidgetConfiguratorInterface::class ),
817 Reg::getService( StoreContext::class )
818 );
819 }
820 return self::$cache[ Interface_Widgets_Service::class ];
821 }
822 );
823 Reg::registerService(
824 Interface_Settings_Service::class,
825 static function () {
826 if ( ! isset( self::$cache[ Interface_Settings_Service::class ] ) ) {
827 self::$cache[ Interface_Settings_Service::class ] = new Settings_Service();
828 }
829 return self::$cache[ Interface_Settings_Service::class ];
830 }
831 );
832 Reg::registerService(
833 Interface_Order_Address_Builder::class,
834 static function () {
835 if ( ! isset( self::$cache[ Interface_Order_Address_Builder::class ] ) ) {
836 self::$cache[ Interface_Order_Address_Builder::class ] = new Order_Address_Builder(
837 Reg::getService( Interface_Shopper_Service::class )
838 );
839 }
840 return self::$cache[ Interface_Order_Address_Builder::class ];
841 }
842 );
843 Reg::registerService(
844 Interface_Order_Customer_Builder::class,
845 static function () {
846 if ( ! isset( self::$cache[ Interface_Order_Customer_Builder::class ] ) ) {
847 self::$cache[ Interface_Order_Customer_Builder::class ] = new Order_Customer_Builder(
848 Reg::getService( Interface_Shopper_Service::class ),
849 Reg::getService( OrderStatusSettingsService::class ),
850 Reg::getService( Interface_Pricing_Service::class )
851 );
852 }
853 return self::$cache[ Interface_Order_Customer_Builder::class ];
854 }
855 );
856 Reg::registerService(
857 Interface_Order_Delivery_Method_Builder::class,
858 static function () {
859 if ( ! isset( self::$cache[ Interface_Order_Delivery_Method_Builder::class ] ) ) {
860 self::$cache[ Interface_Order_Delivery_Method_Builder::class ] = new Order_Delivery_Method_Builder();
861 }
862 return self::$cache[ Interface_Order_Delivery_Method_Builder::class ];
863 }
864 );
865 }
866
867 /**
868 * Initializes repositories.
869 */
870 protected static function initRepositories(): void {
871
872 Reg::registerService(
873 \wpdb::class,
874 static function () {
875 if ( ! isset( self::$cache[ \wpdb::class ] ) ) {
876 global $wpdb;
877 self::$cache[ \wpdb::class ] = $wpdb;
878 }
879 return self::$cache[ \wpdb::class ];
880 }
881 );
882
883 parent::initRepositories();
884
885 RepositoryRegistry::registerRepository( ConfigEntity::class, Entity_Repository::class );
886 RepositoryRegistry::registerRepository( QueueItem::class, Queue_Item_Repository::class );
887 RepositoryRegistry::registerRepository( Process::class, Entity_Repository::class );
888 RepositoryRegistry::registerRepository( ConnectionData::class, Entity_Repository::class );
889 RepositoryRegistry::registerRepository( OrderStatusSettings::class, Entity_Repository::class );
890 RepositoryRegistry::registerRepository( StatisticalData::class, Entity_Repository::class );
891 RepositoryRegistry::registerRepository( CountryConfiguration::class, Entity_Repository::class );
892 RepositoryRegistry::registerRepository( GeneralSettings::class, Entity_Repository::class );
893 RepositoryRegistry::registerRepository( SeQuraOrder::class, SeQura_Order_Repository::class );
894 RepositoryRegistry::registerRepository( WidgetSettings::class, Entity_Repository::class );
895 RepositoryRegistry::registerRepository( SendReport::class, Entity_Repository::class );
896 RepositoryRegistry::registerRepository( TransactionLog::class, Entity_Repository::class );
897 RepositoryRegistry::registerRepository( PaymentMethod::class, Entity_Repository::class );
898 RepositoryRegistry::registerRepository( Credentials::class, Entity_Repository::class );
899 RepositoryRegistry::registerRepository( Deployment::class, Entity_Repository::class );
900 }
901
902 /**
903 * Initializes controllers.
904 */
905 protected static function initControllers(): void {
906 parent::initControllers();
907
908 // Plugin controllers.
909 Reg::registerService(
910 Interface_I18n_Controller::class,
911 static function () {
912 if ( ! isset( self::$cache[ Interface_I18n_Controller::class ] ) ) {
913 $data = self::get_constants()->get_plugin_data();
914 $domain = $data['TextDomain'];
915 self::$cache[ Interface_I18n_Controller::class ] = new I18n_Controller(
916 $domain . $data['DomainPath'],
917 $domain,
918 Reg::getService( Interface_Logger_Service::class ),
919 self::get_constants()->get_plugin_templates_path()
920 );
921 }
922 return self::$cache[ Interface_I18n_Controller::class ];
923 }
924 );
925 Reg::registerService(
926 Interface_Assets_Controller::class,
927 static function () {
928 if ( ! isset( self::$cache[ Interface_Assets_Controller::class ] ) ) {
929 $env_data = self::get_constants()->get_environment_data();
930 self::$cache[ Interface_Assets_Controller::class ] = new Assets_Controller(
931 self::get_constants()->get_plugin_assets_url(),
932 self::get_constants()->get_plugin_assets_path(),
933 self::get_constants()->get_plugin_data()['Version'],
934 $env_data['wp_version'] ?? '',
935 Reg::getService( Interface_I18n::class ),
936 Reg::getService( Interface_Logger_Service::class ),
937 self::get_constants()->get_plugin_templates_path(),
938 Reg::getService( Interface_Settings_Service::class ),
939 Reg::getService( Interface_Payment_Method_Service::class ),
940 Reg::getService( RegexProvider::class ),
941 Reg::getService( Interface_Widgets_Service::class )
942 );
943 }
944 return self::$cache[ Interface_Assets_Controller::class ];
945 }
946 );
947 Reg::registerService(
948 Interface_Settings_Controller::class,
949 static function () {
950 if ( ! isset( self::$cache[ Interface_Settings_Controller::class ] ) ) {
951 self::$cache[ Interface_Settings_Controller::class ] = new Settings_Controller(
952 self::get_constants()->get_plugin_templates_path(),
953 Reg::getService( Interface_Settings_Service::class ),
954 Reg::getService( Interface_Logger_Service::class ),
955 self::get_constants()->get_plugin_basename()
956 );
957 }
958 return self::$cache[ Interface_Settings_Controller::class ];
959 }
960 );
961 Reg::registerService(
962 Interface_Payment_Controller::class,
963 static function () {
964 if ( ! isset( self::$cache[ Interface_Payment_Controller::class ] ) ) {
965 self::$cache[ Interface_Payment_Controller::class ] = new Payment_Controller(
966 Reg::getService( Interface_Logger_Service::class ),
967 self::get_constants()->get_plugin_templates_path(),
968 Reg::getService( Interface_Order_Service::class )
969 );
970 }
971 return self::$cache[ Interface_Payment_Controller::class ];
972 }
973 );
974 Reg::registerService(
975 Interface_Product_Controller::class,
976 static function () {
977 if ( ! isset( self::$cache[ Interface_Product_Controller::class ] ) ) {
978 self::$cache[ Interface_Product_Controller::class ] = new Product_Controller(
979 Reg::getService( Interface_Logger_Service::class ),
980 self::get_constants()->get_plugin_templates_path(),
981 Reg::getService( Interface_Product_Service::class ),
982 Reg::getService( RegexProvider::class ),
983 Reg::getService( Interface_Widgets_Service::class )
984 );
985 }
986 return self::$cache[ Interface_Product_Controller::class ];
987 }
988 );
989 Reg::registerService(
990 Interface_Async_Process_Controller::class,
991 static function () {
992 if ( ! isset( self::$cache[ Interface_Async_Process_Controller::class ] ) ) {
993 self::$cache[ Interface_Async_Process_Controller::class ] = new Async_Process_Controller(
994 Reg::getService( Interface_Logger_Service::class ),
995 self::get_constants()->get_plugin_templates_path(),
996 Reg::getService( Interface_Report_Service::class )
997 );
998 }
999 return self::$cache[ Interface_Async_Process_Controller::class ];
1000 }
1001 );
1002 Reg::registerService(
1003 Interface_Order_Controller::class,
1004 static function () {
1005 if ( ! isset( self::$cache[ Interface_Order_Controller::class ] ) ) {
1006 self::$cache[ Interface_Order_Controller::class ] = new Order_Controller(
1007 Reg::getService( Interface_Logger_Service::class ),
1008 self::get_constants()->get_plugin_templates_path(),
1009 Reg::getService( Interface_Order_Service::class )
1010 );
1011 }
1012 return self::$cache[ Interface_Order_Controller::class ];
1013 }
1014 );
1015 Reg::registerService(
1016 Onboarding_REST_Controller::class,
1017 static function () {
1018 if ( ! isset( self::$cache[ Onboarding_REST_Controller::class ] ) ) {
1019 self::$cache[ Onboarding_REST_Controller::class ] = new Onboarding_REST_Controller(
1020 self::get_constants()->get_plugin_rest_namespace(),
1021 Reg::getService( Interface_Logger_Service::class ),
1022 Reg::getService( RegexProvider::class )
1023 );
1024 }
1025 return self::$cache[ Onboarding_REST_Controller::class ];
1026 }
1027 );
1028 Reg::registerService(
1029 Payment_REST_Controller::class,
1030 static function () {
1031 if ( ! isset( self::$cache[ Payment_REST_Controller::class ] ) ) {
1032 self::$cache[ Payment_REST_Controller::class ] = new Payment_REST_Controller(
1033 self::get_constants()->get_plugin_rest_namespace(),
1034 Reg::getService( Interface_Logger_Service::class ),
1035 Reg::getService( RegexProvider::class )
1036 );
1037 }
1038 return self::$cache[ Payment_REST_Controller::class ];
1039 }
1040 );
1041 Reg::registerService(
1042 General_Settings_REST_Controller::class,
1043 static function () {
1044 if ( ! isset( self::$cache[ General_Settings_REST_Controller::class ] ) ) {
1045 self::$cache[ General_Settings_REST_Controller::class ] = new General_Settings_REST_Controller(
1046 self::get_constants()->get_plugin_rest_namespace(),
1047 Reg::getService( Interface_Logger_Service::class ),
1048 Reg::getService( RegexProvider::class ),
1049 Reg::getService( StoreContext::class )
1050 );
1051 }
1052 return self::$cache[ General_Settings_REST_Controller::class ];
1053 }
1054 );
1055 Reg::registerService(
1056 Log_REST_Controller::class,
1057 static function () {
1058 if ( ! isset( self::$cache[ Log_REST_Controller::class ] ) ) {
1059 self::$cache[ Log_REST_Controller::class ] = new Log_REST_Controller(
1060 self::get_constants()->get_plugin_rest_namespace(),
1061 Reg::getService( Interface_Logger_Service::class ),
1062 Reg::getService( RegexProvider::class )
1063 );
1064 }
1065 return self::$cache[ Log_REST_Controller::class ];
1066 }
1067 );
1068 }
1069 }
1070