PluginProbe
seQura / 4.0.0
seQura v4.0.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.0.0, at src/class-bootstrap.php

1,069 lines 41.8 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 );
352 }
353 return self::$cache[ Interface_Create_Order_Request_Builder::class ];
354 }
355 );
356
357 // Core Implementation.
358 Reg::registerService(
359 EncryptorInterface::class,
360 static function () {
361 if ( ! isset( self::$cache[ EncryptorInterface::class ] ) ) {
362 self::$cache[ EncryptorInterface::class ] = new Encryptor();
363 }
364 return self::$cache[ EncryptorInterface::class ];
365 }
366 );
367 Reg::registerService(
368 DisconnectServiceInterface::class,
369 static function () {
370 if ( ! isset( self::$cache[ DisconnectServiceInterface::class ] ) ) {
371 self::$cache[ DisconnectServiceInterface::class ] = new Disconnect_Service(
372 array(
373 RepositoryRegistry::getRepository( ConnectionData::class ),
374 RepositoryRegistry::getRepository( StatisticalData::class ),
375 RepositoryRegistry::getRepository( SendReport::class ),
376 RepositoryRegistry::getRepository( QueueItem::class ),
377 )
378 );
379 }
380 return self::$cache[ DisconnectServiceInterface::class ];
381 }
382 );
383 Reg::registerService(
384 OrderReportServiceInterface::class,
385 static function () {
386 if ( ! isset( self::$cache[ OrderReportServiceInterface::class ] ) ) {
387 self::$cache[ OrderReportServiceInterface::class ] = new Order_Report_Service(
388 Reg::getService( Interface_Platform_Provider::class ),
389 Reg::getService( Interface_Pricing_Service::class ),
390 Reg::getService( Interface_Cart_Service::class ),
391 Reg::getService( Interface_Order_Service::class ),
392 Reg::getService( Interface_I18n::class ),
393 Reg::getService( Interface_Order_Delivery_Method_Builder::class ),
394 Reg::getService( Interface_Order_Address_Builder::class ),
395 Reg::getService( Interface_Order_Customer_Builder::class )
396 );
397 }
398 return self::$cache[ OrderReportServiceInterface::class ];
399 }
400 );
401 Reg::registerService(
402 MerchantDataProviderInterface::class,
403 static function () {
404 if ( ! isset( self::$cache[ MerchantDataProviderInterface::class ] ) ) {
405 self::$cache[ MerchantDataProviderInterface::class ] = new Merchant_Data_Provider(
406 Reg::getService( Interface_Current_Order_Provider::class ),
407 Reg::getService( Interface_Constants::class ),
408 Reg::getService( Interface_Product_Service::class ),
409 Reg::getService( Interface_Cart_Service::class ),
410 Reg::getService( Interface_Shopper_Service::class ),
411 Reg::getService( StoreContext::class )
412 );
413 }
414 return self::$cache[ MerchantDataProviderInterface::class ];
415 }
416 );
417 Reg::registerService(
418 OrderCreationInterface::class,
419 static function () {
420 if ( ! isset( self::$cache[ OrderCreationInterface::class ] ) ) {
421 self::$cache[ OrderCreationInterface::class ] = new Order_Creation();
422 }
423 return self::$cache[ OrderCreationInterface::class ];
424 }
425 );
426
427
428 Reg::registerService(
429 Serializer::class,
430 static function () {
431 if ( ! isset( self::$cache[ Serializer::class ] ) ) {
432 self::$cache[ Serializer::class ] = new JsonSerializer();
433 }
434 return self::$cache[ Serializer::class ];
435 }
436 );
437 Reg::registerService(
438 SellingCountriesServiceInterface::class,
439 static function () {
440 if ( ! isset( self::$cache[ SellingCountriesServiceInterface::class ] ) ) {
441 self::$cache[ SellingCountriesServiceInterface::class ] = new Selling_Countries_Service();
442 }
443 return self::$cache[ SellingCountriesServiceInterface::class ];
444 }
445 );
446 Reg::registerService(
447 StoreServiceInterface::class,
448 static function () {
449 if ( ! isset( self::$cache[ StoreServiceInterface::class ] ) ) {
450 self::$cache[ StoreServiceInterface::class ] = new Store_Service();
451 }
452 return self::$cache[ StoreServiceInterface::class ];
453 }
454 );
455 Reg::registerService(
456 VersionServiceInterface::class,
457 static function () {
458 if ( ! isset( self::$cache[ VersionServiceInterface::class ] ) ) {
459 self::$cache[ VersionServiceInterface::class ] = new Version_Service(
460 self::get_constants()->get_plugin_data()['Version']
461 );
462 }
463 return self::$cache[ VersionServiceInterface::class ];
464 }
465 );
466 Reg::registerService(
467 CategoryServiceInterface::class,
468 static function () {
469 if ( ! isset( self::$cache[ CategoryServiceInterface::class ] ) ) {
470 self::$cache[ CategoryServiceInterface::class ] = new Category_Service();
471 }
472 return self::$cache[ CategoryServiceInterface::class ];
473 }
474 );
475 Reg::registerService(
476 ShopOrderStatusesServiceInterface::class,
477 static function () {
478 if ( ! isset( self::$cache[ ShopOrderStatusesServiceInterface::class ] ) ) {
479 self::$cache[ ShopOrderStatusesServiceInterface::class ] = new Shop_Order_Status_Service();
480 }
481 return self::$cache[ ShopOrderStatusesServiceInterface::class ];
482 }
483 );
484 Reg::registerService(
485 ShopLoggerAdapter::CLASS_NAME,
486 static function () {
487 if ( ! isset( self::$cache[ ShopLoggerAdapter::CLASS_NAME ] ) ) {
488 self::$cache[ ShopLoggerAdapter::CLASS_NAME ] = new Shop_Logger_Adapter();
489 }
490 return self::$cache[ ShopLoggerAdapter::CLASS_NAME ];
491 }
492 );
493 Reg::registerService(
494 DefaultLoggerAdapter::CLASS_NAME,
495 static function () {
496 if ( ! isset( self::$cache[ DefaultLoggerAdapter::CLASS_NAME ] ) ) {
497 self::$cache[ DefaultLoggerAdapter::CLASS_NAME ] = new Default_Logger_Adapter(
498 Reg::getService( Interface_Log_File::class ),
499 Reg::getService( TimeProvider::CLASS_NAME )
500 );
501 }
502 return self::$cache[ DefaultLoggerAdapter::CLASS_NAME ];
503 }
504 );
505
506 // Plugin services.
507 Reg::registerService(
508 Interface_Log_File::class,
509 static function () {
510 if ( ! isset( self::$cache[ Interface_Log_File::class ] ) ) {
511 self::$cache[ Interface_Log_File::class ] = new Log_File(
512 self::get_constants()->get_plugin_log_file_path(),
513 Reg::getService( StoreContext::class )
514 );
515 }
516 return self::$cache[ Interface_Log_File::class ];
517 }
518 );
519 Reg::registerService(
520 Interface_Migration_Manager::class,
521 static function () {
522 if ( ! isset( self::$cache[ Interface_Migration_Manager::class ] ) ) {
523 $configuration = Reg::getService( ConfigurationManager::CLASS_NAME );
524 $wpdb = Reg::getService( \wpdb::class );
525 /**
526 * Order repository.
527 *
528 * @var Repository $order_repository
529 */
530 $order_repository = RepositoryRegistry::getRepository( SeQuraOrder::class );
531 /**
532 * Entity repository.
533 *
534 * @var Repository $entity_repository
535 */
536 $entity_repository = RepositoryRegistry::getRepository( ConfigEntity::class );
537
538 /**
539 * Queue item repository.
540 *
541 * @var Repository $queue_item_repository
542 */
543 $queue_item_repository = RepositoryRegistry::getRepository( QueueItem::class );
544 /**
545 * Encryptor service.
546 *
547 * @var EncryptorInterface $encryptor
548 */
549 $encryptor = Reg::getService( EncryptorInterface::class );
550
551 /**
552 * Store context service.
553 *
554 * @var StoreContext $store_context
555 */
556 $store_context = Reg::getService( StoreContext::class );
557
558 self::$cache[ Interface_Migration_Manager::class ] = new Migration_Manager(
559 self::get_constants()->get_plugin_basename(),
560 $configuration,
561 self::get_constants()->get_plugin_data()['Version'],
562 array(
563 new Migration_Install_300(
564 $wpdb,
565 $order_repository,
566 $entity_repository,
567 $queue_item_repository,
568 $store_context
569 ),
570 new Migration_Install_320(
571 $wpdb,
572 self::get_constants()->get_hook_add_order_indexes(),
573 $entity_repository,
574 $queue_item_repository
575 ),
576 new Migration_Install_400(
577 $wpdb,
578 $encryptor,
579 $store_context,
580 ),
581 )
582 );
583 }
584 return self::$cache[ Interface_Migration_Manager::class ];
585 }
586 );
587 Reg::registerService(
588 Interface_I18n::class,
589 static function () {
590 if ( ! isset( self::$cache[ Interface_I18n::class ] ) ) {
591 self::$cache[ Interface_I18n::class ] = new I18n();
592 }
593 return self::$cache[ Interface_I18n::class ];
594 }
595 );
596 Reg::registerService(
597 Interface_Report_Service::class,
598 static function () {
599 if ( ! isset( self::$cache[ Interface_Report_Service::class ] ) ) {
600 self::$cache[ Interface_Report_Service::class ] = new Report_Service(
601 Reg::getService( ShopOrderService::class ),
602 Reg::getService( StatisticalDataRepositoryInterface::class ),
603 Reg::getService( CountryConfigurationRepositoryInterface::class ),
604 Reg::getService( Interface_Order_Service::class )
605 );
606 }
607 return self::$cache[ Interface_Report_Service::class ];
608 }
609 );
610 Reg::registerService(
611 Interface_Logger_Service::class,
612 static function () {
613 if ( ! isset( self::$cache[ Interface_Logger_Service::class ] ) ) {
614 self::$cache[ Interface_Logger_Service::class ] = new Logger_Service(
615 Reg::getService( LoggerConfiguration::class ),
616 Reg::getService( Interface_Log_File::class )
617 );
618 }
619 return self::$cache[ Interface_Logger_Service::class ];
620 }
621 );
622
623 Reg::registerService(
624 Sequra_Payment_Gateway_Block_Support::class,
625 static function () {
626 if ( ! isset( self::$cache[ Sequra_Payment_Gateway_Block_Support::class ] ) ) {
627 self::$cache[ Sequra_Payment_Gateway_Block_Support::class ] = new Sequra_Payment_Gateway_Block_Support(
628 self::get_constants()->get_plugin_assets_path(),
629 self::get_constants()->get_plugin_assets_url(),
630 self::get_constants()->get_plugin_data()['Version']
631 );
632 }
633 return self::$cache[ Sequra_Payment_Gateway_Block_Support::class ];
634 }
635 );
636 Reg::registerService(
637 Interface_Pricing_Service::class,
638 static function () {
639 if ( ! isset( self::$cache[ Interface_Pricing_Service::class ] ) ) {
640 self::$cache[ Interface_Pricing_Service::class ] = new Pricing_Service();
641 }
642 return self::$cache[ Interface_Pricing_Service::class ];
643 }
644 );
645 Reg::registerService(
646 Interface_Order_Service::class,
647 static function () {
648 if ( ! isset( self::$cache[ Interface_Order_Service::class ] ) ) {
649 /**
650 * This will return SeQura_Order_Repository that implements Interface_Deletable_Repository and Interface_Table_Migration_Repository.
651 *
652 * @var SeQura_Order_Repository $repository
653 */
654 $repository = RepositoryRegistry::getRepository( SeQuraOrder::class );
655
656 self::$cache[ Interface_Order_Service::class ] = new Order_Service(
657 Reg::getService( SeQuraOrderRepositoryInterface::class ),
658 Reg::getService( Interface_Pricing_Service::class ),
659 Reg::getService( OrderStatusSettingsService::class ),
660 Reg::getService( Interface_Cart_Service::class ),
661 Reg::getService( Interface_Logger_Service::class ),
662 Reg::getService( Interface_Time_Checker_Service::class ),
663 $repository,
664 $repository,
665 self::get_constants()->get_payment_gateway_id(),
666 Reg::getService( ConnectionService::class ),
667 Reg::getService( OrderService::class )
668 );
669 }
670 return self::$cache[ Interface_Order_Service::class ];
671 }
672 );
673 Reg::registerService(
674 Interface_Cart_Service::class,
675 static function () {
676 if ( ! isset( self::$cache[ Interface_Cart_Service::class ] ) ) {
677 self::$cache[ Interface_Cart_Service::class ] = new Cart_Service(
678 Reg::getService( Interface_Product_Service::class ),
679 Reg::getService( Interface_Pricing_Service::class ),
680 Reg::getService( Interface_Logger_Service::class ),
681 Reg::getService( Interface_Shopper_Service::class )
682 );
683 }
684 return self::$cache[ Interface_Cart_Service::class ];
685 }
686 );
687 Reg::registerService(
688 Interface_Product_Service::class,
689 static function () {
690 if ( ! isset( self::$cache[ Interface_Product_Service::class ] ) ) {
691 self::$cache[ Interface_Product_Service::class ] = new Product_Service(
692 Reg::getService( Interface_Pricing_Service::class ),
693 Reg::getService( RegexProvider::class ),
694 Reg::getService( StoreContext::class )
695 );
696 }
697 return self::$cache[ Interface_Product_Service::class ];
698 }
699 );
700 Reg::registerService(
701 Interface_Shopper_Service::class,
702 static function () {
703 if ( ! isset( self::$cache[ Interface_Shopper_Service::class ] ) ) {
704 self::$cache[ Interface_Shopper_Service::class ] = new Shopper_Service(
705 Reg::getService( StoreContext::class )
706 );
707 }
708 return self::$cache[ Interface_Shopper_Service::class ];
709 }
710 );
711 Reg::registerService(
712 ShopOrderService::class,
713 static function () {
714 if ( ! isset( self::$cache[ ShopOrderService::class ] ) ) {
715 self::$cache[ ShopOrderService::class ] = new Shop_Order_Service(
716 Reg::getService( SeQuraOrderRepositoryInterface::class ),
717 Reg::getService( Interface_Logger_Service::class ),
718 Reg::getService( Interface_Create_Order_Request_Builder::class ),
719 Reg::getService( Interface_Current_Order_Provider::class ),
720 Reg::getService( OrderService::class )
721 );
722 }
723 return self::$cache[ ShopOrderService::class ];
724 }
725 );
726 Reg::registerService(
727 Interface_Time_Checker_Service::class,
728 static function () {
729 if ( ! isset( self::$cache[ Interface_Time_Checker_Service::class ] ) ) {
730 self::$cache[ Interface_Time_Checker_Service::class ] = new Time_Checker_Service();
731 }
732 return self::$cache[ Interface_Time_Checker_Service::class ];
733 }
734 );
735
736 Reg::registerService(
737 ProductServiceInterface::class,
738 static function () {
739 if ( ! isset( self::$cache[ ProductServiceInterface::class ] ) ) {
740 self::$cache[ ProductServiceInterface::class ] = new Core_Product_Service();
741 }
742 return self::$cache[ ProductServiceInterface::class ];
743 }
744 );
745 Reg::registerService(
746 WidgetConfiguratorInterface::class,
747 static function () {
748 if ( ! isset( self::$cache[ WidgetConfiguratorInterface::class ] ) ) {
749 self::$cache[ WidgetConfiguratorInterface::class ] = new Widget_Configurator(
750 Reg::getService( Interface_I18n::class )
751 );
752 }
753 return self::$cache[ WidgetConfiguratorInterface::class ];
754 }
755 );
756
757 Reg::registerService(
758 MiniWidgetMessagesProviderInterface::class,
759 static function () {
760 if ( ! isset( self::$cache[ MiniWidgetMessagesProviderInterface::class ] ) ) {
761 self::$cache[ MiniWidgetMessagesProviderInterface::class ] = new Mini_Widget_Messages_Provider(
762 Reg::getService( Interface_I18n::class )
763 );
764 }
765 return self::$cache[ MiniWidgetMessagesProviderInterface::class ];
766 }
767 );
768
769 Reg::registerService(
770 Interface_Current_Order_Provider::class,
771 static function () {
772 if ( ! isset( self::$cache[ Interface_Current_Order_Provider::class ] ) ) {
773 self::$cache[ Interface_Current_Order_Provider::class ] = new Current_Order_Provider();
774 }
775 return self::$cache[ Interface_Current_Order_Provider::class ];
776 }
777 );
778
779 Reg::registerService(
780 Interface_Platform_Provider::class,
781 static function () {
782 if ( ! isset( self::$cache[ Interface_Platform_Provider::class ] ) ) {
783 self::$cache[ Interface_Platform_Provider::class ] = new Platform_Provider(
784 Reg::getService( Interface_Constants::class )
785 );
786 }
787 return self::$cache[ Interface_Platform_Provider::class ];
788 }
789 );
790
791 Reg::registerService(
792 Interface_Payment_Method_Service::class,
793 static function () {
794 if ( ! isset( self::$cache[ Interface_Payment_Method_Service::class ] ) ) {
795 self::$cache[ Interface_Payment_Method_Service::class ] = new Payment_Method_Service(
796 Reg::getService( Interface_Create_Order_Request_Builder::class ),
797 Reg::getService( Interface_Order_Service::class ),
798 Reg::getService( Interface_Logger_Service::class ),
799 Reg::getService( Interface_Current_Order_Provider::class ),
800 Reg::getService( StoreContext::class )
801 );
802 }
803 return self::$cache[ Interface_Payment_Method_Service::class ];
804 }
805 );
806
807 Reg::registerService(
808 Interface_Widgets_Service::class,
809 static function () {
810 if ( ! isset( self::$cache[ Interface_Widgets_Service::class ] ) ) {
811 self::$cache[ Interface_Widgets_Service::class ] = new Widgets_Service(
812 Reg::getService( Interface_Logger_Service::class ),
813 Reg::getService( Interface_I18n::class ),
814 Reg::getService( Interface_Shopper_Service::class ),
815 Reg::getService( WidgetConfiguratorInterface::class ),
816 Reg::getService( StoreContext::class )
817 );
818 }
819 return self::$cache[ Interface_Widgets_Service::class ];
820 }
821 );
822 Reg::registerService(
823 Interface_Settings_Service::class,
824 static function () {
825 if ( ! isset( self::$cache[ Interface_Settings_Service::class ] ) ) {
826 self::$cache[ Interface_Settings_Service::class ] = new Settings_Service();
827 }
828 return self::$cache[ Interface_Settings_Service::class ];
829 }
830 );
831 Reg::registerService(
832 Interface_Order_Address_Builder::class,
833 static function () {
834 if ( ! isset( self::$cache[ Interface_Order_Address_Builder::class ] ) ) {
835 self::$cache[ Interface_Order_Address_Builder::class ] = new Order_Address_Builder(
836 Reg::getService( Interface_Shopper_Service::class )
837 );
838 }
839 return self::$cache[ Interface_Order_Address_Builder::class ];
840 }
841 );
842 Reg::registerService(
843 Interface_Order_Customer_Builder::class,
844 static function () {
845 if ( ! isset( self::$cache[ Interface_Order_Customer_Builder::class ] ) ) {
846 self::$cache[ Interface_Order_Customer_Builder::class ] = new Order_Customer_Builder(
847 Reg::getService( Interface_Shopper_Service::class ),
848 Reg::getService( OrderStatusSettingsService::class ),
849 Reg::getService( Interface_Pricing_Service::class )
850 );
851 }
852 return self::$cache[ Interface_Order_Customer_Builder::class ];
853 }
854 );
855 Reg::registerService(
856 Interface_Order_Delivery_Method_Builder::class,
857 static function () {
858 if ( ! isset( self::$cache[ Interface_Order_Delivery_Method_Builder::class ] ) ) {
859 self::$cache[ Interface_Order_Delivery_Method_Builder::class ] = new Order_Delivery_Method_Builder();
860 }
861 return self::$cache[ Interface_Order_Delivery_Method_Builder::class ];
862 }
863 );
864 }
865
866 /**
867 * Initializes repositories.
868 */
869 protected static function initRepositories(): void {
870
871 Reg::registerService(
872 \wpdb::class,
873 static function () {
874 if ( ! isset( self::$cache[ \wpdb::class ] ) ) {
875 global $wpdb;
876 self::$cache[ \wpdb::class ] = $wpdb;
877 }
878 return self::$cache[ \wpdb::class ];
879 }
880 );
881
882 parent::initRepositories();
883
884 RepositoryRegistry::registerRepository( ConfigEntity::class, Entity_Repository::class );
885 RepositoryRegistry::registerRepository( QueueItem::class, Queue_Item_Repository::class );
886 RepositoryRegistry::registerRepository( Process::class, Entity_Repository::class );
887 RepositoryRegistry::registerRepository( ConnectionData::class, Entity_Repository::class );
888 RepositoryRegistry::registerRepository( OrderStatusSettings::class, Entity_Repository::class );
889 RepositoryRegistry::registerRepository( StatisticalData::class, Entity_Repository::class );
890 RepositoryRegistry::registerRepository( CountryConfiguration::class, Entity_Repository::class );
891 RepositoryRegistry::registerRepository( GeneralSettings::class, Entity_Repository::class );
892 RepositoryRegistry::registerRepository( SeQuraOrder::class, SeQura_Order_Repository::class );
893 RepositoryRegistry::registerRepository( WidgetSettings::class, Entity_Repository::class );
894 RepositoryRegistry::registerRepository( SendReport::class, Entity_Repository::class );
895 RepositoryRegistry::registerRepository( TransactionLog::class, Entity_Repository::class );
896 RepositoryRegistry::registerRepository( PaymentMethod::class, Entity_Repository::class );
897 RepositoryRegistry::registerRepository( Credentials::class, Entity_Repository::class );
898 RepositoryRegistry::registerRepository( Deployment::class, Entity_Repository::class );
899 }
900
901 /**
902 * Initializes controllers.
903 */
904 protected static function initControllers(): void {
905 parent::initControllers();
906
907 // Plugin controllers.
908 Reg::registerService(
909 Interface_I18n_Controller::class,
910 static function () {
911 if ( ! isset( self::$cache[ Interface_I18n_Controller::class ] ) ) {
912 $data = self::get_constants()->get_plugin_data();
913 $domain = $data['TextDomain'];
914 self::$cache[ Interface_I18n_Controller::class ] = new I18n_Controller(
915 $domain . $data['DomainPath'],
916 $domain,
917 Reg::getService( Interface_Logger_Service::class ),
918 self::get_constants()->get_plugin_templates_path()
919 );
920 }
921 return self::$cache[ Interface_I18n_Controller::class ];
922 }
923 );
924 Reg::registerService(
925 Interface_Assets_Controller::class,
926 static function () {
927 if ( ! isset( self::$cache[ Interface_Assets_Controller::class ] ) ) {
928 $env_data = self::get_constants()->get_environment_data();
929 self::$cache[ Interface_Assets_Controller::class ] = new Assets_Controller(
930 self::get_constants()->get_plugin_assets_url(),
931 self::get_constants()->get_plugin_assets_path(),
932 self::get_constants()->get_plugin_data()['Version'],
933 $env_data['wp_version'] ?? '',
934 Reg::getService( Interface_I18n::class ),
935 Reg::getService( Interface_Logger_Service::class ),
936 self::get_constants()->get_plugin_templates_path(),
937 Reg::getService( Interface_Settings_Service::class ),
938 Reg::getService( Interface_Payment_Method_Service::class ),
939 Reg::getService( RegexProvider::class ),
940 Reg::getService( Interface_Widgets_Service::class )
941 );
942 }
943 return self::$cache[ Interface_Assets_Controller::class ];
944 }
945 );
946 Reg::registerService(
947 Interface_Settings_Controller::class,
948 static function () {
949 if ( ! isset( self::$cache[ Interface_Settings_Controller::class ] ) ) {
950 self::$cache[ Interface_Settings_Controller::class ] = new Settings_Controller(
951 self::get_constants()->get_plugin_templates_path(),
952 Reg::getService( Interface_Settings_Service::class ),
953 Reg::getService( Interface_Logger_Service::class ),
954 self::get_constants()->get_plugin_basename()
955 );
956 }
957 return self::$cache[ Interface_Settings_Controller::class ];
958 }
959 );
960 Reg::registerService(
961 Interface_Payment_Controller::class,
962 static function () {
963 if ( ! isset( self::$cache[ Interface_Payment_Controller::class ] ) ) {
964 self::$cache[ Interface_Payment_Controller::class ] = new Payment_Controller(
965 Reg::getService( Interface_Logger_Service::class ),
966 self::get_constants()->get_plugin_templates_path(),
967 Reg::getService( Interface_Order_Service::class )
968 );
969 }
970 return self::$cache[ Interface_Payment_Controller::class ];
971 }
972 );
973 Reg::registerService(
974 Interface_Product_Controller::class,
975 static function () {
976 if ( ! isset( self::$cache[ Interface_Product_Controller::class ] ) ) {
977 self::$cache[ Interface_Product_Controller::class ] = new Product_Controller(
978 Reg::getService( Interface_Logger_Service::class ),
979 self::get_constants()->get_plugin_templates_path(),
980 Reg::getService( Interface_Product_Service::class ),
981 Reg::getService( RegexProvider::class ),
982 Reg::getService( Interface_Widgets_Service::class )
983 );
984 }
985 return self::$cache[ Interface_Product_Controller::class ];
986 }
987 );
988 Reg::registerService(
989 Interface_Async_Process_Controller::class,
990 static function () {
991 if ( ! isset( self::$cache[ Interface_Async_Process_Controller::class ] ) ) {
992 self::$cache[ Interface_Async_Process_Controller::class ] = new Async_Process_Controller(
993 Reg::getService( Interface_Logger_Service::class ),
994 self::get_constants()->get_plugin_templates_path(),
995 Reg::getService( Interface_Report_Service::class )
996 );
997 }
998 return self::$cache[ Interface_Async_Process_Controller::class ];
999 }
1000 );
1001 Reg::registerService(
1002 Interface_Order_Controller::class,
1003 static function () {
1004 if ( ! isset( self::$cache[ Interface_Order_Controller::class ] ) ) {
1005 self::$cache[ Interface_Order_Controller::class ] = new Order_Controller(
1006 Reg::getService( Interface_Logger_Service::class ),
1007 self::get_constants()->get_plugin_templates_path(),
1008 Reg::getService( Interface_Order_Service::class )
1009 );
1010 }
1011 return self::$cache[ Interface_Order_Controller::class ];
1012 }
1013 );
1014 Reg::registerService(
1015 Onboarding_REST_Controller::class,
1016 static function () {
1017 if ( ! isset( self::$cache[ Onboarding_REST_Controller::class ] ) ) {
1018 self::$cache[ Onboarding_REST_Controller::class ] = new Onboarding_REST_Controller(
1019 self::get_constants()->get_plugin_rest_namespace(),
1020 Reg::getService( Interface_Logger_Service::class ),
1021 Reg::getService( RegexProvider::class )
1022 );
1023 }
1024 return self::$cache[ Onboarding_REST_Controller::class ];
1025 }
1026 );
1027 Reg::registerService(
1028 Payment_REST_Controller::class,
1029 static function () {
1030 if ( ! isset( self::$cache[ Payment_REST_Controller::class ] ) ) {
1031 self::$cache[ Payment_REST_Controller::class ] = new Payment_REST_Controller(
1032 self::get_constants()->get_plugin_rest_namespace(),
1033 Reg::getService( Interface_Logger_Service::class ),
1034 Reg::getService( RegexProvider::class )
1035 );
1036 }
1037 return self::$cache[ Payment_REST_Controller::class ];
1038 }
1039 );
1040 Reg::registerService(
1041 General_Settings_REST_Controller::class,
1042 static function () {
1043 if ( ! isset( self::$cache[ General_Settings_REST_Controller::class ] ) ) {
1044 self::$cache[ General_Settings_REST_Controller::class ] = new General_Settings_REST_Controller(
1045 self::get_constants()->get_plugin_rest_namespace(),
1046 Reg::getService( Interface_Logger_Service::class ),
1047 Reg::getService( RegexProvider::class ),
1048 Reg::getService( StoreContext::class )
1049 );
1050 }
1051 return self::$cache[ General_Settings_REST_Controller::class ];
1052 }
1053 );
1054 Reg::registerService(
1055 Log_REST_Controller::class,
1056 static function () {
1057 if ( ! isset( self::$cache[ Log_REST_Controller::class ] ) ) {
1058 self::$cache[ Log_REST_Controller::class ] = new Log_REST_Controller(
1059 self::get_constants()->get_plugin_rest_namespace(),
1060 Reg::getService( Interface_Logger_Service::class ),
1061 Reg::getService( RegexProvider::class )
1062 );
1063 }
1064 return self::$cache[ Log_REST_Controller::class ];
1065 }
1066 );
1067 }
1068 }
1069