mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
add custom autoloader
This commit is contained in:
parent
cd54a96981
commit
7b25d5bb0c
10 changed files with 52 additions and 69 deletions
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';
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue