mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
add custom autoloader
This commit is contained in:
parent
cd54a96981
commit
7b25d5bb0c
10 changed files with 52 additions and 69 deletions
|
@ -38,17 +38,6 @@
|
|||
"phpunit/phpunit": "^9.1",
|
||||
"brain/monkey": "^2.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\": "src/",
|
||||
"Inpsyde\\PayPalCommerce\\Button\\": "modules.local/ppcp-button/src/",
|
||||
"Inpsyde\\PayPalCommerce\\WcGateway\\": "modules.local/ppcp-wc-gateway/src/",
|
||||
"Inpsyde\\PayPalCommerce\\Onboarding\\": "modules.local/ppcp-onboarding/src/",
|
||||
"Inpsyde\\Woocommerce\\Logging\\": "modules.local/woocommerce-logging/src/",
|
||||
"Inpsyde\\PayPalCommerce\\Webhooks\\": "modules.local/ppcp-webhooks/src/",
|
||||
"Inpsyde\\PayPalCommerce\\Subscription\\": "modules.local/ppcp-subscription/src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\": "tests/PHPUnit/"
|
||||
|
|
49
inc/autoload.php
Normal file
49
inc/autoload.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Inpsyde\PayPalCommerce;
|
||||
|
||||
function autoload() {
|
||||
|
||||
/**
|
||||
* Custom WordPress autoloader.
|
||||
*/
|
||||
spl_autoload_register(
|
||||
function( $class_name ) {
|
||||
if (
|
||||
strpos($class_name, 'Inpsyde\PayPalCommerce') === false
|
||||
&& strpos($class_name, 'Inpsyde\Woocommerce') === false
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$class_parts = explode("\\", $class_name);
|
||||
$module_dir = dirname(__DIR__) . '/modules.local/';
|
||||
$modules = [
|
||||
'Button' => $module_dir . 'ppcp-button/src/',
|
||||
'Onboarding' => $module_dir . 'ppcp-onboarding/src/',
|
||||
'Subscription' => $module_dir . 'ppcp-subscription/src/',
|
||||
'WcGateway' => $module_dir . 'ppcp-wc-gateway/src/',
|
||||
'Webhooks' => $module_dir . 'ppcp-webhooks/src/',
|
||||
'Logging' => $module_dir . 'woocommerce-logging/src/',
|
||||
];
|
||||
|
||||
if (! isset($modules[$class_parts[2]])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file_path = $modules[$class_parts[2]];
|
||||
unset ($class_parts[0]);
|
||||
unset ($class_parts[1]);
|
||||
unset ($class_parts[2]);
|
||||
$file_name = 'class-' . strtolower(end($class_parts)) . '.php';
|
||||
array_pop($class_parts);
|
||||
|
||||
$file_path .= implode(DIRECTORY_SEPARATOR, $class_parts) . '/' . $file_name;
|
||||
include $file_path;
|
||||
}
|
||||
);
|
||||
|
||||
// Load composer autoloader.
|
||||
include dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
}
|
|
@ -4,10 +4,5 @@
|
|||
"require": {
|
||||
"dhii/module-interface": "0.2.x-dev",
|
||||
"inpsyde/ppcp-api-client": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\Button\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,19 +4,6 @@
|
|||
"require": {
|
||||
"dhii/module-interface": "0.2.x-dev"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\Onboarding\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\Onboarding\\": "tests/PHPUnit"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"unit": "./vendor/bin/phpunit --coverage-html build/coverage-report"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.1",
|
||||
"brain/monkey": "^2.4",
|
||||
|
|
|
@ -4,10 +4,5 @@
|
|||
"require": {
|
||||
"dhii/module-interface": "0.2.x-dev",
|
||||
"inpsyde/ppcp-api-client": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\Subscription\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,16 +7,6 @@
|
|||
"inpsyde/ppcp-admin-notices": "dev-master",
|
||||
"inpsyde/ppcp-api-client": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\WcGateway\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\WcGateway\\": "tests/PHPUnit"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"unit": "./vendor/bin/phpunit --coverage-html build/coverage-report"
|
||||
},
|
||||
|
|
|
@ -4,16 +4,6 @@
|
|||
"require": {
|
||||
"dhii/module-interface": "0.2.x-dev"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\Webhooks\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\PayPalCommerce\\Webhooks\\": "tests/PHPUnit"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"unit": "./vendor/bin/phpunit --coverage-html build/coverage-report"
|
||||
},
|
||||
|
|
|
@ -4,10 +4,5 @@
|
|||
"require": {
|
||||
"dhii/module-interface": "0.2.x-dev",
|
||||
"psr/log": "^1.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\Woocommerce\\Logging\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Inpsyde\IZettle\Logging;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
namespace Inpsyde\PayPalCommerce\Logging;
|
||||
|
||||
return array();
|
||||
|
|
|
@ -25,13 +25,8 @@ use Dhii\Modular\Module\ModuleInterface;
|
|||
use Inpsyde\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* ToDo: Check if we always need autoloader. This is a current
|
||||
* workaround because of the wpcust setup
|
||||
**/
|
||||
|
||||
include_once __DIR__.'/vendor/autoload.php';
|
||||
include_once __DIR__.'/inc/autoload.php';
|
||||
autoload();
|
||||
|
||||
function init()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue