PluginProbe
MONEI Payments for WooCommerce / 7.2.0
MONEI Payments for WooCommerce v7.2.0
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / src / Core / container-definitions.php

container-definitions.php in MONEI Payments for WooCommerce 7.2.0, at src/Core/container-definitions.php

121 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Monei\Features\Subscriptions\SubscriptionService;
4 use Monei\Features\Subscriptions\WooCommerceSubscriptionsHandler;
5 use Monei\Features\Subscriptions\YithSubscriptionPluginHandler;
6 use Monei\Helpers\CardBrandHelper;
7 use Monei\Repositories\PaymentMethodsRepository;
8 use Monei\Services\ApiKeyService;
9 use Monei\Services\BlockSupportService;
10 use Monei\Services\express\ExpressCartBackup;
11 use Monei\Services\express\ExpressCheckoutAjaxHandler;
12 use Monei\Services\express\ExpressCheckoutAssets;
13 use Monei\Services\MoneiApplePayVerificationService;
14 use Monei\Services\MoneiStatusCodeHandler;
15 use Monei\Services\payment\MoneiPaymentServices;
16 use Monei\Services\PaymentMethodFormatter;
17 use Monei\Services\PaymentMethodsService;
18 use Monei\Services\sdk\MoneiSdkClientFactory;
19 use Monei\Templates\NoticeAdminDependency;
20 use Monei\Templates\NoticeAdminNewInstall;
21 use Monei\Templates\NoticeGatewayNotAvailable;
22 use Monei\Templates\NoticeGatewayNotAvailableApi;
23 use Monei\Templates\NoticeGatewayNotEnabledMonei;
24 use Monei\Templates\SettingsHeader;
25 use Monei\Templates\TemplateManager;
26 use function DI\autowire;
27 use function DI\create;
28 use function DI\get;
29 use function DI\factory;
30
31 $blocksPath = dirname( __DIR__, 1 ) . '/Gateways/Blocks';
32 $gatewayPath = dirname( __DIR__, 1 ) . '/Gateways/PaymentMethods';
33 $gatewayNamespacePrefix = 'Monei\\Gateways\\PaymentMethods\\';
34 $blockNamespacePrefix = 'Monei\\Gateways\\Blocks\\';
35 $definitions = array(
36 // ========== TEMPLATES ==========
37 // Register each template as an autowired service
38 NoticeAdminNewInstall::class => autowire( NoticeAdminNewInstall::class ),
39 SettingsHeader::class => autowire( SettingsHeader::class ),
40 NoticeAdminDependency::class => autowire( NoticeAdminDependency::class ),
41 NoticeGatewayNotAvailable::class => autowire( NoticeGatewayNotAvailable::class ),
42 NoticeGatewayNotAvailableApi::class => autowire( NoticeGatewayNotAvailableApi::class ),
43 NoticeGatewayNotEnabledMonei::class => autowire( NoticeGatewayNotEnabledMonei::class ),
44
45 // array of [ 'short-template-name' => <template-class-instance> ]
46 TemplateManager::class => create( TemplateManager::class )
47 ->constructor(
48 array(
49 'notice-admin-new-install' => get( NoticeAdminNewInstall::class ),
50 'monei-settings-header' => get( SettingsHeader::class ),
51 'notice-admin-dependency' => get( NoticeAdminDependency::class ),
52 'notice-admin-gateway-not-available' => get( NoticeGatewayNotAvailable::class ),
53 'notice-admin-gateway-not-available-api' => get( NoticeGatewayNotAvailableApi::class ),
54 'notice-admin-gateway-not-enabled-monei' => get( NoticeGatewayNotEnabledMonei::class ),
55 )
56 ),
57 ApiKeyService::class => autowire( ApiKeyService::class ),
58 MoneiSdkClientFactory::class => autowire( MoneiSdkClientFactory::class )
59 ->constructor( get( ApiKeyService::class ) ),
60 PaymentMethodsRepository::class => factory(
61 function ( ApiKeyService $apiKeyService, MoneiSdkClientFactory $sdkClientFactory ) {
62 return new PaymentMethodsRepository( $apiKeyService->get_account_id(), $sdkClientFactory->get_client() );
63 }
64 ),
65 PaymentMethodsService::class => create( PaymentMethodsService::class )
66 ->constructor( get( PaymentMethodsRepository::class ) ),
67 CardBrandHelper::class => create( CardBrandHelper::class )
68 ->constructor( get( PaymentMethodsService::class ) ),
69 MoneiPaymentServices::class => autowire( MoneiPaymentServices::class ),
70 MoneiStatusCodeHandler::class => autowire( MoneiStatusCodeHandler::class ),
71 PaymentMethodFormatter::class => autowire( PaymentMethodFormatter::class ),
72 BlockSupportService::class => create( BlockSupportService::class )
73 ->constructor( $blocksPath, $blockNamespacePrefix ),
74 MoneiApplePayVerificationService::class => autowire( MoneiApplePayVerificationService::class )
75 ->constructor( get( MoneiPaymentServices::class ) ),
76 ExpressCartBackup::class => autowire( ExpressCartBackup::class ),
77 ExpressCheckoutAjaxHandler::class => autowire( ExpressCheckoutAjaxHandler::class ),
78 ExpressCheckoutAssets::class => autowire( ExpressCheckoutAssets::class ),
79 WooCommerceSubscriptionsHandler::class => create(
80 WooCommerceSubscriptionsHandler::class,
81 )->constructor(
82 get( MoneiSdkClientFactory::class )
83 ),
84 YithSubscriptionPluginHandler::class => autowire( YithSubscriptionPluginHandler::class ),
85
86 SubscriptionService::class => autowire( SubscriptionService::class )
87 ->constructorParameter( 'wooHandler', get( WooCommerceSubscriptionsHandler::class ) )
88 ->constructorParameter( 'yithHandler', get( YithSubscriptionPluginHandler::class ) ),
89 );
90
91 // Dynamically load all gateway classes in the folder
92 foreach ( glob( $gatewayPath . '/*.php' ) as $file ) {
93 $className = $gatewayNamespacePrefix . pathinfo( $file, PATHINFO_FILENAME );
94
95 if ( class_exists( $className ) ) {
96 $definitions[ $className ] = autowire();
97 }
98 }
99
100 // Dynamically register block support classes
101 foreach ( glob( $blocksPath . '/*BlocksSupport.php' ) as $file ) {
102 $blockClassName = $blockNamespacePrefix . pathinfo( $file, PATHINFO_FILENAME );
103 $gatewayNamePrefix = 'WCGateway';
104 if ( class_exists( $blockClassName ) ) {
105 // Derive the corresponding gateway class name
106 $gatewayClassName = $gatewayNamespacePrefix . $gatewayNamePrefix . str_replace( 'BlocksSupport', '', pathinfo( $file, PATHINFO_FILENAME ) );
107
108 // Register the block support class with the gateway as a dependency
109 $definitions[ $blockClassName ] = autowire()
110 ->constructorParameter( 'gateway', get( $gatewayClassName ) );
111
112 // Inject CardBrandHelper only for CC blocks support
113 if ( $blockClassName === 'Monei\\Gateways\\Blocks\\MoneiCCBlocksSupport' ) {
114 $definitions[ $blockClassName ] = $definitions[ $blockClassName ]
115 ->constructorParameter( 'cardBrandHelper', get( CardBrandHelper::class ) );
116 }
117 }
118 }
119
120 return $definitions;
121