2020use Monei \Templates \NoticeGatewayNotEnabledMonei ;
2121use Monei \Templates \SettingsHeader ;
2222use Monei \Templates \TemplateManager ;
23+ use function DI \autowire ;
24+ use function DI \create ;
25+ use function DI \get ;
26+ use function DI \factory ;
2327
2428$ blocksPath = dirname ( __DIR__ , 1 ) . '/Gateways/Blocks ' ;
2529$ gatewayPath = dirname ( __DIR__ , 1 ) . '/Gateways/PaymentMethods ' ;
2832$ definitions = array (
2933 // ========== TEMPLATES ==========
3034 // Register each template as an autowired service
31- NoticeAdminNewInstall::class => DI \ autowire ( NoticeAdminNewInstall::class ),
32- SettingsHeader::class => DI \ autowire ( SettingsHeader::class ),
33- NoticeAdminDependency::class => DI \ autowire ( NoticeAdminDependency::class ),
34- NoticeGatewayNotAvailable::class => DI \ autowire ( NoticeGatewayNotAvailable::class ),
35- NoticeGatewayNotAvailableApi::class => DI \ autowire ( NoticeGatewayNotAvailableApi::class ),
36- NoticeGatewayNotEnabledMonei::class => DI \ autowire ( NoticeGatewayNotEnabledMonei::class ),
35+ NoticeAdminNewInstall::class => autowire ( NoticeAdminNewInstall::class ),
36+ SettingsHeader::class => autowire ( SettingsHeader::class ),
37+ NoticeAdminDependency::class => autowire ( NoticeAdminDependency::class ),
38+ NoticeGatewayNotAvailable::class => autowire ( NoticeGatewayNotAvailable::class ),
39+ NoticeGatewayNotAvailableApi::class => autowire ( NoticeGatewayNotAvailableApi::class ),
40+ NoticeGatewayNotEnabledMonei::class => autowire ( NoticeGatewayNotEnabledMonei::class ),
3741
3842 // array of [ 'short-template-name' => <template-class-instance> ]
39- TemplateManager::class => DI \ create ( TemplateManager::class )
43+ TemplateManager::class => create ( TemplateManager::class )
4044 ->constructor (
4145 array (
42- 'notice-admin-new-install ' => DI \ get ( NoticeAdminNewInstall::class ),
43- 'monei-settings-header ' => DI \ get ( SettingsHeader::class ),
44- 'notice-admin-dependency ' => DI \ get ( NoticeAdminDependency::class ),
45- 'notice-admin-gateway-not-available ' => DI \ get ( NoticeGatewayNotAvailable::class ),
46- 'notice-admin-gateway-not-available-api ' => DI \ get ( NoticeGatewayNotAvailableApi::class ),
47- 'notice-admin-gateway-not-enabled-monei ' => DI \ get ( NoticeGatewayNotEnabledMonei::class ),
46+ 'notice-admin-new-install ' => get ( NoticeAdminNewInstall::class ),
47+ 'monei-settings-header ' => get ( SettingsHeader::class ),
48+ 'notice-admin-dependency ' => get ( NoticeAdminDependency::class ),
49+ 'notice-admin-gateway-not-available ' => get ( NoticeGatewayNotAvailable::class ),
50+ 'notice-admin-gateway-not-available-api ' => get ( NoticeGatewayNotAvailableApi::class ),
51+ 'notice-admin-gateway-not-enabled-monei ' => get ( NoticeGatewayNotEnabledMonei::class ),
4852 )
4953 ),
50- ApiKeyService::class => DI \ autowire ( ApiKeyService::class ),
51- MoneiSdkClientFactory::class => DI \ autowire ( MoneiSdkClientFactory::class )
52- ->constructor ( DI \ get ( ApiKeyService::class ) ),
53- PaymentMethodsRepository::class => DI \ factory (
54+ ApiKeyService::class => autowire ( ApiKeyService::class ),
55+ MoneiSdkClientFactory::class => autowire ( MoneiSdkClientFactory::class )
56+ ->constructor ( get ( ApiKeyService::class ) ),
57+ PaymentMethodsRepository::class => factory (
5458 function ( ApiKeyService $ apiKeyService , MoneiSdkClientFactory $ sdkClientFactory ) {
55- return new Monei \ Repositories \ PaymentMethodsRepository ( $ apiKeyService ->get_account_id (), $ sdkClientFactory ->get_client () );
59+ return new PaymentMethodsRepository ( $ apiKeyService ->get_account_id (), $ sdkClientFactory ->get_client () );
5660 }
5761 ),
58- PaymentMethodsService::class => DI \ create ( PaymentMethodsService::class )
59- ->constructor ( DI \ get ( PaymentMethodsRepository::class ) ),
60- CardBrandHelper::class => DI \ create ( CardBrandHelper::class )
61- ->constructor ( DI \ get ( PaymentMethodsService::class ) ),
62- MoneiPaymentServices::class => DI \ autowire ( MoneiPaymentServices::class ),
63- MoneiStatusCodeHandler::class => DI \ autowire ( MoneiStatusCodeHandler::class ),
64- PaymentMethodFormatter::class => DI \ autowire ( PaymentMethodFormatter::class ),
65- BlockSupportService::class => DI \ create ( BlockSupportService::class )
62+ PaymentMethodsService::class => create ( PaymentMethodsService::class )
63+ ->constructor ( get ( PaymentMethodsRepository::class ) ),
64+ CardBrandHelper::class => create ( CardBrandHelper::class )
65+ ->constructor ( get ( PaymentMethodsService::class ) ),
66+ MoneiPaymentServices::class => autowire ( MoneiPaymentServices::class ),
67+ MoneiStatusCodeHandler::class => autowire ( MoneiStatusCodeHandler::class ),
68+ PaymentMethodFormatter::class => autowire ( PaymentMethodFormatter::class ),
69+ BlockSupportService::class => create ( BlockSupportService::class )
6670 ->constructor ( $ blocksPath , $ blockNamespacePrefix ),
67- MoneiApplePayVerificationService::class => DI \ autowire ( MoneiApplePayVerificationService::class )
68- ->constructor ( DI \ get ( MoneiPaymentServices::class ) ),
69- WooCommerceSubscriptionsHandler::class => \ DI \ create (
71+ MoneiApplePayVerificationService::class => autowire ( MoneiApplePayVerificationService::class )
72+ ->constructor ( get ( MoneiPaymentServices::class ) ),
73+ WooCommerceSubscriptionsHandler::class => create (
7074 WooCommerceSubscriptionsHandler::class,
7175 )->constructor (
72- DI \ get ( MoneiSdkClientFactory::class )
76+ get ( MoneiSdkClientFactory::class )
7377 ),
74- YithSubscriptionPluginHandler::class => \ DI \ autowire ( YithSubscriptionPluginHandler::class ),
78+ YithSubscriptionPluginHandler::class => autowire ( YithSubscriptionPluginHandler::class ),
7579
76- SubscriptionService::class => \ DI \ autowire ( SubscriptionService::class )
77- ->constructorParameter ( 'wooHandler ' , \ DI \ get ( WooCommerceSubscriptionsHandler::class ) )
78- ->constructorParameter ( 'yithHandler ' , \ DI \ get ( YithSubscriptionPluginHandler::class ) ),
80+ SubscriptionService::class => autowire ( SubscriptionService::class )
81+ ->constructorParameter ( 'wooHandler ' , get ( WooCommerceSubscriptionsHandler::class ) )
82+ ->constructorParameter ( 'yithHandler ' , get ( YithSubscriptionPluginHandler::class ) ),
7983);
8084
8185// Dynamically load all gateway classes in the folder
8286foreach ( glob ( $ gatewayPath . '/*.php ' ) as $ file ) {
8387 $ className = $ gatewayNamespacePrefix . pathinfo ( $ file , PATHINFO_FILENAME );
8488
8589 if ( class_exists ( $ className ) ) {
86- $ definitions [ $ className ] = DI \ autowire ();
90+ $ definitions [ $ className ] = autowire ();
8791 }
8892}
8993
@@ -96,13 +100,13 @@ function ( ApiKeyService $apiKeyService, MoneiSdkClientFactory $sdkClientFactory
96100 $ gatewayClassName = $ gatewayNamespacePrefix . $ gatewayNamePrefix . str_replace ( 'BlocksSupport ' , '' , pathinfo ( $ file , PATHINFO_FILENAME ) );
97101
98102 // Register the block support class with the gateway as a dependency
99- $ definitions [ $ blockClassName ] = DI \ autowire ()
100- ->constructorParameter ( 'gateway ' , DI \ get ( $ gatewayClassName ) );
103+ $ definitions [ $ blockClassName ] = autowire ()
104+ ->constructorParameter ( 'gateway ' , get ( $ gatewayClassName ) );
101105
102106 // Inject CardBrandHelper only for CC blocks support
103107 if ( $ blockClassName === 'Monei \\Gateways \\Blocks \\MoneiCCBlocksSupport ' ) {
104108 $ definitions [ $ blockClassName ] = $ definitions [ $ blockClassName ]
105- ->constructorParameter ( 'cardBrandHelper ' , DI \ get ( CardBrandHelper::class ) );
109+ ->constructorParameter ( 'cardBrandHelper ' , get ( CardBrandHelper::class ) );
106110 }
107111 }
108112}
0 commit comments