PluginProbe
MONEI Payments for WooCommerce / trunk
MONEI Payments for WooCommerce vtrunk
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 trunk, at src/Core/container-definitions.php

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