Skip to content

Commit

Permalink
extract getPluginPath from plugin class to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Aug 6, 2021
1 parent f390b4e commit a66ada0
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 159 deletions.
4 changes: 3 additions & 1 deletion inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ function mollieWooCommerceIsCheckoutContext()
*/
function mollieWooCommerceComponentsStylesForAvailableGateways()
{
$pluginPath = untrailingslashit(M4W_PLUGIN_DIR) . '/';

$mollieComponentsStyles = new ComponentsStyles(
new SettingsComponents(),
new SettingsComponents($pluginPath),
WC()->payment_gateways()
);

Expand Down
8 changes: 7 additions & 1 deletion src/Gateway/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ abstract class AbstractGateway extends WC_Payment_Gateway
* @var string
*/
protected $pluginUrl;
/**
* @var string
*/
protected $pluginPath;

/**
*
Expand All @@ -112,7 +116,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->logger = $logger;
Expand All @@ -123,6 +128,7 @@ public function __construct(
$this->mollieOrderService = $mollieOrderService;
$this->httpResponse = $httpResponse;
$this->pluginUrl = $pluginUrl;
$this->pluginPath = $pluginPath;

// No plugin id, gateway id is unique enough
$this->plugin_id = '';
Expand Down
11 changes: 6 additions & 5 deletions src/Gateway/ApplePay/Mollie_WC_Gateway_ApplePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -48,7 +49,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}
/**
Expand Down Expand Up @@ -127,9 +129,8 @@ protected function getInstructions(

protected function includeApplePayButton()
{
$fields = include Plugin::getPluginPath(
'/inc/settings/mollie_apple_pay_button_enabler.php'
);
$fields = include $this->pluginPath . '/' .
'/inc/settings/mollie_apple_pay_button_enabler.php';

$this->form_fields = array_merge($this->form_fields, $fields);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/Bancontact/Mollie_WC_Gateway_Bancontact.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -42,7 +43,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/BankTransfer/Mollie_WC_Gateway_BankTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -53,7 +54,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
add_filter('woocommerce_' . $this->id . '_args', [$this, 'addPaymentArguments'], 10, 2);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/Belfius/Mollie_WC_Gateway_Belfius.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -42,7 +43,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
20 changes: 9 additions & 11 deletions src/Gateway/Creditcard/Mollie_WC_Gateway_Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {
parent::__construct(
$iconFactory,
Expand All @@ -38,7 +39,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
$this->supports = [
'products',
Expand Down Expand Up @@ -177,9 +179,7 @@ protected function getInstructions(
*/
protected function includeCreditCardIconSelector()
{
$fields = include Plugin::getPluginPath(
'/inc/settings/mollie_creditcard_icons_selector.php'
);
$fields = include $this->pluginPath . '/' . '/inc/settings/mollie_creditcard_icons_selector.php';

$fields and $this->form_fields = array_merge($this->form_fields, $fields);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public function buildSvgComposed()
$enabledCreditCards = $this->enabledCreditcards();

$assetsImagesPath
= Plugin::getPluginPath('public/images/Creditcard_issuers/');
= $this->pluginPath . '/' . 'public/images/Creditcard_issuers/';
$cardWidth = PaymentMethodsIconUrl::CREDIT_CARD_ICON_WIDTH;
$cardsNumber = count($enabledCreditCards);
$cardsWidth = $cardWidth * $cardsNumber;
Expand Down Expand Up @@ -286,9 +286,7 @@ protected function hasFieldsIfMollieComponentsIsEnabled()

protected function includeMollieComponentsFields()
{
$fields = include Plugin::getPluginPath(
'/inc/settings/mollie_components_enabler.php'
);
$fields = include $this->pluginPath . '/' . '/inc/settings/mollie_components_enabler.php';

$this->form_fields = array_merge($this->form_fields, $fields);
}
Expand Down Expand Up @@ -328,14 +326,14 @@ protected function isMollieComponentsEnabled(): bool
protected function lockIcon()
{
return file_get_contents(
Plugin::getPluginPath('public/images/lock-icon.svg')
$this->pluginPath . '/' . 'public/images/lock-icon.svg'
);
}

protected function mollieLogo()
{
return file_get_contents(
Plugin::getPluginPath('public/images/mollie-logo.svg')
$this->pluginPath . '/' . 'public/images/mollie-logo.svg'
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/DirectDebit/Mollie_WC_Gateway_DirectDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -45,7 +46,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/EPS/Mollie_WC_Gateway_EPS.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -43,7 +44,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ public function gatewaysWithNamespace(ContainerInterface $container): array
$mollieOrderService = $container->get(MollieOrderService::class);
$HttpResponseService = $container->get('SDK.HttpResponse');
$pluginUrl = $container->get('core.plugin_url');
$pluginPath = $container->get('core.plugin_path');
$gatewayClassnames = $this->gatewayClassnames;
$gateways = [];
$gatewayNamespace = 'Mollie\\WooCommerce\\Gateway\\';
Expand All @@ -396,7 +397,8 @@ public function gatewaysWithNamespace(ContainerInterface $container): array
$logger,
$notice,
$HttpResponseService,
$pluginUrl
$pluginUrl,
$pluginPath
);
}
return $gateways;
Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/Giftcard/Mollie_WC_Gateway_Giftcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -46,7 +47,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/Giropay/Mollie_WC_Gateway_Giropay.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -43,7 +44,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/Ideal/Mollie_WC_Gateway_Ideal.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -50,7 +51,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/Kbc/Mollie_WC_Gateway_Kbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -47,7 +48,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -43,7 +44,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/KlarnaSliceIt/Mollie_WC_Gateway_KlarnaSliceIt.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -43,7 +44,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gateway/MyBank/Mollie_WC_Gateway_MyBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function __construct(
Logger $logger,
NoticeInterface $notice,
HttpResponse $httpResponse,
string $pluginUrl
string $pluginUrl,
string $pluginPath
) {

$this->supports = [
Expand All @@ -47,7 +48,8 @@ public function __construct(
$logger,
$notice,
$httpResponse,
$pluginUrl
$pluginUrl,
$pluginPath
);
}

Expand Down
Loading

0 comments on commit a66ada0

Please sign in to comment.