api
2 days ago
auth-services
1 week ago
general
2 days ago
helpers
1 week ago
logs
1 week ago
messaging-tools
1 week ago
notifications
1 week ago
senders
1 week ago
traits
1 week ago
autoload.php
2 weeks ago
class-wawp-dashboard.php
2 days ago
class-wawp-database-manager.php
1 week ago
class-wawp-global-search.php
1 week ago
class-wawp-menu.php
1 week ago
index.php
1 month ago
wawp-functions.php
1 week ago
autoload.php
98 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Autoloader file. |
| 4 | * |
| 5 | * @package automation-web-platform |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | // Load global helper functions. |
| 13 | require_once __DIR__ . '/wawp-functions.php'; |
| 14 | |
| 15 | // Load Composer-managed vendor libraries (Guzzle, Carbon, libphonenumber, etc.). |
| 16 | $wawp_vendor_autoload = WAWP_PLUGIN_DIR . 'vendor/autoload.php'; |
| 17 | if ( file_exists( $wawp_vendor_autoload ) ) { |
| 18 | require_once $wawp_vendor_autoload; |
| 19 | |
| 20 | // Critical Fix: Namespace aliasing for partially scoped interfaces |
| 21 | // This prevents "Interface not found" errors when some libraries are scoped and others are not. |
| 22 | $wawp_psr_aliases = array( |
| 23 | 'Psr\Clock\ClockInterface' => 'WAWP\Vendor\Psr\Clock\ClockInterface', |
| 24 | 'Psr\Log\LoggerInterface' => 'WAWP\Vendor\Psr\Log\LoggerInterface', |
| 25 | 'libphonenumber\PhoneNumberUtil' => 'WAWP\Vendor\libphonenumber\PhoneNumberUtil', |
| 26 | 'libphonenumber\PhoneNumberToCarrierMapper' => 'WAWP\Vendor\libphonenumber\PhoneNumberToCarrierMapper', |
| 27 | ); |
| 28 | |
| 29 | foreach ( $wawp_psr_aliases as $wawp_original => $wawp_scoped ) { |
| 30 | if ( ( interface_exists( $wawp_original ) && ! interface_exists( $wawp_scoped ) ) || ( class_exists( $wawp_original ) && ! class_exists( $wawp_scoped ) ) ) { |
| 31 | class_alias( $wawp_original, $wawp_scoped ); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | unset( $wawp_vendor_autoload ); |
| 37 | |
| 38 | // Plugin-specific autoloader (WAWP_* classes only). |
| 39 | spl_autoload_register( |
| 40 | function ( $class_name ) { |
| 41 | if ( 0 !== strpos( $class_name, 'WAWP_' ) ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | $clean_class = strtolower( str_replace( '_', '-', $class_name ) ); |
| 46 | $is_trait = ( false !== strpos( $clean_class, '-trait' ) ); |
| 47 | |
| 48 | // Specialized directories based on class name patterns. |
| 49 | $search_map = array(); |
| 50 | |
| 51 | if ( 0 === strpos( $class_name, 'WAWP_Rest_' ) ) { |
| 52 | $search_map[] = 'includes/api/'; |
| 53 | } elseif ( 0 === strpos( $class_name, 'WAWP_Notif_' ) ) { |
| 54 | $search_map[] = 'includes/notifications/'; |
| 55 | $search_map[] = 'includes/notifications/Triggers/'; |
| 56 | } elseif ( $is_trait ) { |
| 57 | $search_map[] = 'includes/traits/'; |
| 58 | } |
| 59 | |
| 60 | // General fallback directories. |
| 61 | $search_map = array_merge( |
| 62 | $search_map, |
| 63 | array( |
| 64 | 'includes/helpers/', |
| 65 | 'includes/general/', |
| 66 | 'includes/messaging-tools/', |
| 67 | 'includes/auth-services/', |
| 68 | 'includes/logs/', |
| 69 | 'includes/senders/', |
| 70 | 'includes/notifications/', |
| 71 | 'includes/notifications/Triggers/', |
| 72 | 'includes/', |
| 73 | ) |
| 74 | ); |
| 75 | |
| 76 | $search_map = array_unique( $search_map ); |
| 77 | |
| 78 | foreach ( $search_map as $dir ) { |
| 79 | $files = array( |
| 80 | 'class-' . $clean_class . '.php', |
| 81 | 'trait-' . $clean_class . '.php', |
| 82 | ); |
| 83 | |
| 84 | if ( $is_trait ) { |
| 85 | $files[] = 'trait-' . str_replace( '-trait', '', $clean_class ) . '.php'; |
| 86 | } |
| 87 | |
| 88 | foreach ( $files as $f ) { |
| 89 | $path = WAWP_PLUGIN_DIR . $dir . $f; |
| 90 | if ( file_exists( $path ) ) { |
| 91 | require_once $path; |
| 92 | return; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | ); |
| 98 |