woocommerce-paypal-payments/inc/autoload.php

67 lines
1.7 KiB
PHP
Raw Normal View History

2020-08-31 12:37:24 +03:00
<?php
2020-08-31 13:27:18 +03:00
/**
* The custom autoloader functionality.
*
* @package Inpsyde\PayPalCommerce
*/
2020-08-31 13:30:15 +03:00
2020-08-31 12:37:24 +03:00
declare( strict_types=1 );
namespace Inpsyde\PayPalCommerce;
2020-08-31 13:27:18 +03:00
/**
* The autoloader.
*/
2020-08-31 12:37:24 +03:00
function autoload() {
/**
* Custom WordPress autoloader.
*/
spl_autoload_register(
function( $class_name ) {
if (
2020-08-31 13:27:18 +03:00
strpos( $class_name, 'Inpsyde\PayPalCommerce' ) === false
&& strpos( $class_name, 'Inpsyde\Woocommerce' ) === false
2020-08-31 12:37:24 +03:00
) {
return;
}
2020-08-31 13:27:18 +03:00
$class_parts = explode( '\\', $class_name );
$module_dir = dirname( __DIR__ ) . '/modules.local/';
$modules = array(
2020-09-01 10:02:47 +03:00
'ApiClient' => $module_dir . 'ppcp-api-client/src/',
2020-08-31 13:27:18 +03:00
'Button' => $module_dir . 'ppcp-button/src/',
2020-09-01 10:02:47 +03:00
'Logging' => $module_dir . 'woocommerce-logging/src/',
2020-08-31 13:27:18 +03:00
'Onboarding' => $module_dir . 'ppcp-onboarding/src/',
2020-09-01 10:12:28 +03:00
'Session' => $module_dir . 'ppcp-session/src/',
2020-08-31 12:37:24 +03:00
'Subscription' => $module_dir . 'ppcp-subscription/src/',
2020-08-31 13:27:18 +03:00
'WcGateway' => $module_dir . 'ppcp-wc-gateway/src/',
'Webhooks' => $module_dir . 'ppcp-webhooks/src/',
);
2020-08-31 12:37:24 +03:00
2020-08-31 13:27:18 +03:00
if ( isset( $class_parts[2] ) && ! isset( $class_parts[3] ) ) {
$file_path = dirname( __DIR__ ) . '/src/class-' . strtolower( $class_parts[2] ) . '.php';
2020-08-31 13:08:27 +03:00
include $file_path;
return;
}
2020-08-31 13:27:18 +03:00
if ( ! isset( $modules[ $class_parts[2] ] ) ) {
2020-08-31 12:37:24 +03:00
return;
}
2020-08-31 13:27:18 +03:00
$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 );
2020-08-31 12:37:24 +03:00
2020-08-31 13:27:18 +03:00
$file_path .= implode( DIRECTORY_SEPARATOR, $class_parts ) . '/' . $file_name;
2020-08-31 12:37:24 +03:00
include $file_path;
}
);
// Load composer autoloader.
2020-08-31 13:27:18 +03:00
include dirname( __DIR__ ) . '/vendor/autoload.php';
2020-08-31 12:37:24 +03:00
2020-08-31 13:27:18 +03:00
}