@@ -15,42 +15,42 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class EE_Psr4AutoloaderInit |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @type Psr4Autoloader |
|
| 20 | - */ |
|
| 21 | - protected static $psr4_loader; |
|
| 18 | + /** |
|
| 19 | + * @type Psr4Autoloader |
|
| 20 | + */ |
|
| 21 | + protected static $psr4_loader; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @return void |
|
| 26 | - * @throws EE_Error |
|
| 27 | - */ |
|
| 28 | - public function initializeAutoloader() |
|
| 29 | - { |
|
| 30 | - static $initialized = false; |
|
| 31 | - if (! $initialized) { |
|
| 32 | - // register the base directories for the namespace prefix |
|
| 33 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
| 34 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
| 35 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoVendor', EE_THIRD_PARTY); |
|
| 36 | - $initialized = true; |
|
| 37 | - } |
|
| 38 | - } |
|
| 24 | + /** |
|
| 25 | + * @return void |
|
| 26 | + * @throws EE_Error |
|
| 27 | + */ |
|
| 28 | + public function initializeAutoloader() |
|
| 29 | + { |
|
| 30 | + static $initialized = false; |
|
| 31 | + if (! $initialized) { |
|
| 32 | + // register the base directories for the namespace prefix |
|
| 33 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
| 34 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
| 35 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoVendor', EE_THIRD_PARTY); |
|
| 36 | + $initialized = true; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return Psr4Autoloader |
|
| 43 | - * @throws EE_Error |
|
| 44 | - */ |
|
| 45 | - public static function psr4_loader(): Psr4Autoloader |
|
| 46 | - { |
|
| 47 | - if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) { |
|
| 48 | - // instantiate PSR4 autoloader |
|
| 49 | - espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php'); |
|
| 50 | - EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
|
| 51 | - // register the autoloader |
|
| 52 | - EE_Psr4AutoloaderInit::psr4_loader()->register(); |
|
| 53 | - } |
|
| 54 | - return EE_Psr4AutoloaderInit::$psr4_loader; |
|
| 55 | - } |
|
| 41 | + /** |
|
| 42 | + * @return Psr4Autoloader |
|
| 43 | + * @throws EE_Error |
|
| 44 | + */ |
|
| 45 | + public static function psr4_loader(): Psr4Autoloader |
|
| 46 | + { |
|
| 47 | + if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) { |
|
| 48 | + // instantiate PSR4 autoloader |
|
| 49 | + espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php'); |
|
| 50 | + EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
|
| 51 | + // register the autoloader |
|
| 52 | + EE_Psr4AutoloaderInit::psr4_loader()->register(); |
|
| 53 | + } |
|
| 54 | + return EE_Psr4AutoloaderInit::$psr4_loader; |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | public function initializeAutoloader() |
| 29 | 29 | { |
| 30 | 30 | static $initialized = false; |
| 31 | - if (! $initialized) { |
|
| 31 | + if ( ! $initialized) { |
|
| 32 | 32 | // register the base directories for the namespace prefix |
| 33 | 33 | EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
| 34 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch'); |
|
| 34 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch'); |
|
| 35 | 35 | EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoVendor', EE_THIRD_PARTY); |
| 36 | 36 | $initialized = true; |
| 37 | 37 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public static function psr4_loader(): Psr4Autoloader |
| 46 | 46 | { |
| 47 | - if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) { |
|
| 47 | + if ( ! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) { |
|
| 48 | 48 | // instantiate PSR4 autoloader |
| 49 | - espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php'); |
|
| 49 | + espresso_load_required('Psr4Autoloader', __DIR__.'/Psr4Autoloader.php'); |
|
| 50 | 50 | EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
| 51 | 51 | // register the autoloader |
| 52 | 52 | EE_Psr4AutoloaderInit::psr4_loader()->register(); |
@@ -14,33 +14,33 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function espresso_load_error_handling() |
| 16 | 16 | { |
| 17 | - static $error_handling_loaded = false; |
|
| 18 | - if ($error_handling_loaded) { |
|
| 19 | - return; |
|
| 20 | - } |
|
| 21 | - // load debugging tools |
|
| 22 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 23 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
| 24 | - EEH_Debug_Tools::instance(); |
|
| 25 | - } |
|
| 26 | - // load error handling |
|
| 27 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 28 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
| 29 | - // if you're a dev and want to receive all errors via email |
|
| 30 | - // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
|
| 31 | - if ( |
|
| 32 | - defined('WP_DEBUG') |
|
| 33 | - && WP_DEBUG === true |
|
| 34 | - && defined('EE_ERROR_EMAILS') |
|
| 35 | - && EE_ERROR_EMAILS === true |
|
| 36 | - ) { |
|
| 37 | - set_error_handler(['EE_Error', 'error_handler']); |
|
| 38 | - register_shutdown_function(['EE_Error', 'fatal_error_handler']); |
|
| 39 | - } |
|
| 40 | - } else { |
|
| 41 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 42 | - } |
|
| 43 | - $error_handling_loaded = true; |
|
| 17 | + static $error_handling_loaded = false; |
|
| 18 | + if ($error_handling_loaded) { |
|
| 19 | + return; |
|
| 20 | + } |
|
| 21 | + // load debugging tools |
|
| 22 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 23 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
| 24 | + EEH_Debug_Tools::instance(); |
|
| 25 | + } |
|
| 26 | + // load error handling |
|
| 27 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 28 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
| 29 | + // if you're a dev and want to receive all errors via email |
|
| 30 | + // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
|
| 31 | + if ( |
|
| 32 | + defined('WP_DEBUG') |
|
| 33 | + && WP_DEBUG === true |
|
| 34 | + && defined('EE_ERROR_EMAILS') |
|
| 35 | + && EE_ERROR_EMAILS === true |
|
| 36 | + ) { |
|
| 37 | + set_error_handler(['EE_Error', 'error_handler']); |
|
| 38 | + register_shutdown_function(['EE_Error', 'fatal_error_handler']); |
|
| 39 | + } |
|
| 40 | + } else { |
|
| 41 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 42 | + } |
|
| 43 | + $error_handling_loaded = true; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -54,21 +54,21 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function espresso_load_required(string $classname, string $full_path_to_file) |
| 56 | 56 | { |
| 57 | - if (is_readable($full_path_to_file)) { |
|
| 58 | - require_once $full_path_to_file; |
|
| 59 | - } else { |
|
| 60 | - throw new EE_Error( |
|
| 61 | - sprintf( |
|
| 62 | - esc_html__( |
|
| 63 | - 'The %1$s class file could not be located or is not readable due to file permissions. %3$s supplied path: %2$s', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ), |
|
| 66 | - $classname, |
|
| 67 | - $full_path_to_file, |
|
| 68 | - '<br>' |
|
| 69 | - ) |
|
| 70 | - ); |
|
| 71 | - } |
|
| 57 | + if (is_readable($full_path_to_file)) { |
|
| 58 | + require_once $full_path_to_file; |
|
| 59 | + } else { |
|
| 60 | + throw new EE_Error( |
|
| 61 | + sprintf( |
|
| 62 | + esc_html__( |
|
| 63 | + 'The %1$s class file could not be located or is not readable due to file permissions. %3$s supplied path: %2$s', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ), |
|
| 66 | + $classname, |
|
| 67 | + $full_path_to_file, |
|
| 68 | + '<br>' |
|
| 69 | + ) |
|
| 70 | + ); |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -86,52 +86,52 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function bootstrap_espresso() |
| 88 | 88 | { |
| 89 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
| 90 | - try { |
|
| 91 | - espresso_load_error_handling(); |
|
| 92 | - // include WordPress shims for functions introduced in later versions of WordPress |
|
| 93 | - espresso_load_required( |
|
| 94 | - '', |
|
| 95 | - EE_CORE . 'wordpress-shims.php' |
|
| 96 | - ); |
|
| 97 | - espresso_load_required( |
|
| 98 | - '', |
|
| 99 | - EE_CORE . 'third-party-compatibility.php' |
|
| 100 | - ); |
|
| 101 | - espresso_load_required( |
|
| 102 | - 'EEH_Base', |
|
| 103 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
| 104 | - ); |
|
| 105 | - espresso_load_required( |
|
| 106 | - 'EEH_File', |
|
| 107 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
| 108 | - ); |
|
| 109 | - espresso_load_required( |
|
| 110 | - 'EEH_File', |
|
| 111 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
| 112 | - ); |
|
| 113 | - espresso_load_required( |
|
| 114 | - 'EEH_Array', |
|
| 115 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
| 116 | - ); |
|
| 117 | - espresso_load_required( |
|
| 118 | - 'EE_Base', |
|
| 119 | - EE_CORE . 'EE_Base.core.php' |
|
| 120 | - ); |
|
| 121 | - // instantiate and configure PSR4 autoloader |
|
| 122 | - espresso_load_required( |
|
| 123 | - 'Psr4Autoloader', |
|
| 124 | - EE_CORE . 'Psr4Autoloader.php' |
|
| 125 | - ); |
|
| 126 | - espresso_load_required( |
|
| 127 | - 'EE_Psr4AutoloaderInit', |
|
| 128 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
| 129 | - ); |
|
| 130 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
| 131 | - $AutoloaderInit->initializeAutoloader(); |
|
| 132 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
| 133 | - } catch (Exception $e) { |
|
| 134 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
| 135 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
| 136 | - } |
|
| 89 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
| 90 | + try { |
|
| 91 | + espresso_load_error_handling(); |
|
| 92 | + // include WordPress shims for functions introduced in later versions of WordPress |
|
| 93 | + espresso_load_required( |
|
| 94 | + '', |
|
| 95 | + EE_CORE . 'wordpress-shims.php' |
|
| 96 | + ); |
|
| 97 | + espresso_load_required( |
|
| 98 | + '', |
|
| 99 | + EE_CORE . 'third-party-compatibility.php' |
|
| 100 | + ); |
|
| 101 | + espresso_load_required( |
|
| 102 | + 'EEH_Base', |
|
| 103 | + EE_CORE . 'helpers/EEH_Base.helper.php' |
|
| 104 | + ); |
|
| 105 | + espresso_load_required( |
|
| 106 | + 'EEH_File', |
|
| 107 | + EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
| 108 | + ); |
|
| 109 | + espresso_load_required( |
|
| 110 | + 'EEH_File', |
|
| 111 | + EE_CORE . 'helpers/EEH_File.helper.php' |
|
| 112 | + ); |
|
| 113 | + espresso_load_required( |
|
| 114 | + 'EEH_Array', |
|
| 115 | + EE_CORE . 'helpers/EEH_Array.helper.php' |
|
| 116 | + ); |
|
| 117 | + espresso_load_required( |
|
| 118 | + 'EE_Base', |
|
| 119 | + EE_CORE . 'EE_Base.core.php' |
|
| 120 | + ); |
|
| 121 | + // instantiate and configure PSR4 autoloader |
|
| 122 | + espresso_load_required( |
|
| 123 | + 'Psr4Autoloader', |
|
| 124 | + EE_CORE . 'Psr4Autoloader.php' |
|
| 125 | + ); |
|
| 126 | + espresso_load_required( |
|
| 127 | + 'EE_Psr4AutoloaderInit', |
|
| 128 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
| 129 | + ); |
|
| 130 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
| 131 | + $AutoloaderInit->initializeAutoloader(); |
|
| 132 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
| 133 | + } catch (Exception $e) { |
|
| 134 | + require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
| 135 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
| 136 | + } |
|
| 137 | 137 | } |
@@ -44,149 +44,149 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class Psr4Autoloader |
| 46 | 46 | { |
| 47 | - /** |
|
| 48 | - * namespace separator |
|
| 49 | - */ |
|
| 50 | - public const NS = '\\'; |
|
| 47 | + /** |
|
| 48 | + * namespace separator |
|
| 49 | + */ |
|
| 50 | + public const NS = '\\'; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * An associative array where the key is a namespace prefix and the value |
|
| 54 | - * is an array of base directories for classes in that namespace. |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - protected $prefixes = array(); |
|
| 52 | + /** |
|
| 53 | + * An associative array where the key is a namespace prefix and the value |
|
| 54 | + * is an array of base directories for classes in that namespace. |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + protected $prefixes = array(); |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * returns an array of registered namespace prefixes |
|
| 63 | - * |
|
| 64 | - * @param string $prefix |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function prefixes(string $prefix = ''): array |
|
| 68 | - { |
|
| 69 | - if (! empty($prefix)) { |
|
| 70 | - // are there any base directories for this namespace prefix? |
|
| 71 | - return $this->prefixes[ $prefix ] ?? []; |
|
| 72 | - } |
|
| 73 | - return $this->prefixes; |
|
| 74 | - } |
|
| 61 | + /** |
|
| 62 | + * returns an array of registered namespace prefixes |
|
| 63 | + * |
|
| 64 | + * @param string $prefix |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function prefixes(string $prefix = ''): array |
|
| 68 | + { |
|
| 69 | + if (! empty($prefix)) { |
|
| 70 | + // are there any base directories for this namespace prefix? |
|
| 71 | + return $this->prefixes[ $prefix ] ?? []; |
|
| 72 | + } |
|
| 73 | + return $this->prefixes; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Register loader with SPL autoloader stack. |
|
| 79 | - * |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function register() |
|
| 83 | - { |
|
| 84 | - spl_autoload_register(array($this, 'loadClass')); |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Register loader with SPL autoloader stack. |
|
| 79 | + * |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function register() |
|
| 83 | + { |
|
| 84 | + spl_autoload_register(array($this, 'loadClass')); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Adds a base directory for a namespace prefix. |
|
| 90 | - * |
|
| 91 | - * @param string $prefix The namespace prefix. |
|
| 92 | - * @param string $base_dir A base directory for class files in the |
|
| 93 | - * namespace. |
|
| 94 | - * @param bool $prepend If true, prepend the base directory to the stack |
|
| 95 | - * instead of appending it; this causes it to be searched first rather |
|
| 96 | - * than last. |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - public function addNamespace(string $prefix, string $base_dir, bool $prepend = false) |
|
| 100 | - { |
|
| 101 | - // normalize namespace prefix |
|
| 102 | - $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
| 103 | - // normalize the base directory with a trailing separator |
|
| 104 | - $base_dir = str_replace(['\\', '/'], '/', $base_dir); |
|
| 105 | - $base_dir = rtrim($base_dir, '/\\') . '/'; |
|
| 106 | - // initialize the namespace prefix array |
|
| 107 | - if (isset($this->prefixes[ $prefix ]) === false) { |
|
| 108 | - $this->prefixes[ $prefix ] = array(); |
|
| 109 | - } |
|
| 110 | - // retain the base directory for the namespace prefix |
|
| 111 | - if ($prepend) { |
|
| 112 | - array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
| 113 | - } else { |
|
| 114 | - $this->prefixes[ $prefix ][] = $base_dir; |
|
| 115 | - } |
|
| 116 | - } |
|
| 88 | + /** |
|
| 89 | + * Adds a base directory for a namespace prefix. |
|
| 90 | + * |
|
| 91 | + * @param string $prefix The namespace prefix. |
|
| 92 | + * @param string $base_dir A base directory for class files in the |
|
| 93 | + * namespace. |
|
| 94 | + * @param bool $prepend If true, prepend the base directory to the stack |
|
| 95 | + * instead of appending it; this causes it to be searched first rather |
|
| 96 | + * than last. |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + public function addNamespace(string $prefix, string $base_dir, bool $prepend = false) |
|
| 100 | + { |
|
| 101 | + // normalize namespace prefix |
|
| 102 | + $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
| 103 | + // normalize the base directory with a trailing separator |
|
| 104 | + $base_dir = str_replace(['\\', '/'], '/', $base_dir); |
|
| 105 | + $base_dir = rtrim($base_dir, '/\\') . '/'; |
|
| 106 | + // initialize the namespace prefix array |
|
| 107 | + if (isset($this->prefixes[ $prefix ]) === false) { |
|
| 108 | + $this->prefixes[ $prefix ] = array(); |
|
| 109 | + } |
|
| 110 | + // retain the base directory for the namespace prefix |
|
| 111 | + if ($prepend) { |
|
| 112 | + array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
| 113 | + } else { |
|
| 114 | + $this->prefixes[ $prefix ][] = $base_dir; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Loads the class file for a given class name. |
|
| 121 | - * |
|
| 122 | - * @param string $class The fully-qualified class name. |
|
| 123 | - * @return false|string The mapped file name on success or boolean false on failure. |
|
| 124 | - */ |
|
| 125 | - public function loadClass(string $class) |
|
| 126 | - { |
|
| 127 | - // the current namespace prefix |
|
| 128 | - $prefix = $class; |
|
| 129 | - // work backwards through the namespace names of the fully-qualified |
|
| 130 | - // class name to find a mapped file name |
|
| 131 | - while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) { |
|
| 132 | - // retain the trailing namespace separator in the prefix |
|
| 133 | - $prefix = substr($class, 0, $pos + 1); |
|
| 134 | - // the rest is the relative class name |
|
| 135 | - $relative_class = substr($class, $pos + 1); |
|
| 136 | - // try to load a mapped file for the prefix and relative class |
|
| 137 | - $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
| 138 | - if ($mapped_file) { |
|
| 139 | - return $mapped_file; |
|
| 140 | - } |
|
| 141 | - // remove the trailing namespace separator for the next iteration of strrpos() |
|
| 142 | - $prefix = rtrim($prefix, Psr4Autoloader::NS); |
|
| 143 | - } |
|
| 144 | - // never found a mapped file |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 119 | + /** |
|
| 120 | + * Loads the class file for a given class name. |
|
| 121 | + * |
|
| 122 | + * @param string $class The fully-qualified class name. |
|
| 123 | + * @return false|string The mapped file name on success or boolean false on failure. |
|
| 124 | + */ |
|
| 125 | + public function loadClass(string $class) |
|
| 126 | + { |
|
| 127 | + // the current namespace prefix |
|
| 128 | + $prefix = $class; |
|
| 129 | + // work backwards through the namespace names of the fully-qualified |
|
| 130 | + // class name to find a mapped file name |
|
| 131 | + while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) { |
|
| 132 | + // retain the trailing namespace separator in the prefix |
|
| 133 | + $prefix = substr($class, 0, $pos + 1); |
|
| 134 | + // the rest is the relative class name |
|
| 135 | + $relative_class = substr($class, $pos + 1); |
|
| 136 | + // try to load a mapped file for the prefix and relative class |
|
| 137 | + $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
| 138 | + if ($mapped_file) { |
|
| 139 | + return $mapped_file; |
|
| 140 | + } |
|
| 141 | + // remove the trailing namespace separator for the next iteration of strrpos() |
|
| 142 | + $prefix = rtrim($prefix, Psr4Autoloader::NS); |
|
| 143 | + } |
|
| 144 | + // never found a mapped file |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Load the mapped file for a namespace prefix and relative class. |
|
| 151 | - * |
|
| 152 | - * @param string $prefix The namespace prefix. |
|
| 153 | - * @param string $relative_class The relative class name. |
|
| 154 | - * @return string|null null if no mapped file can be loaded, |
|
| 155 | - * or the name of the mapped file that was loaded. |
|
| 156 | - */ |
|
| 157 | - protected function loadMappedFile(string $prefix, string $relative_class): ?string |
|
| 158 | - { |
|
| 159 | - // look through base directories for this namespace prefix |
|
| 160 | - foreach ($this->prefixes($prefix) as $base_dir) { |
|
| 161 | - // replace the namespace prefix with the base directory, |
|
| 162 | - // replace namespace separators with directory separators |
|
| 163 | - // in the relative class name, append with .php |
|
| 164 | - $file = $base_dir |
|
| 165 | - . str_replace(Psr4Autoloader::NS, '/', $relative_class) |
|
| 166 | - . '.php'; |
|
| 167 | - // if the mapped file exists, require it |
|
| 168 | - if ($this->requireFile($file)) { |
|
| 169 | - // yes, we're done |
|
| 170 | - return $file; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - // never found it |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 149 | + /** |
|
| 150 | + * Load the mapped file for a namespace prefix and relative class. |
|
| 151 | + * |
|
| 152 | + * @param string $prefix The namespace prefix. |
|
| 153 | + * @param string $relative_class The relative class name. |
|
| 154 | + * @return string|null null if no mapped file can be loaded, |
|
| 155 | + * or the name of the mapped file that was loaded. |
|
| 156 | + */ |
|
| 157 | + protected function loadMappedFile(string $prefix, string $relative_class): ?string |
|
| 158 | + { |
|
| 159 | + // look through base directories for this namespace prefix |
|
| 160 | + foreach ($this->prefixes($prefix) as $base_dir) { |
|
| 161 | + // replace the namespace prefix with the base directory, |
|
| 162 | + // replace namespace separators with directory separators |
|
| 163 | + // in the relative class name, append with .php |
|
| 164 | + $file = $base_dir |
|
| 165 | + . str_replace(Psr4Autoloader::NS, '/', $relative_class) |
|
| 166 | + . '.php'; |
|
| 167 | + // if the mapped file exists, require it |
|
| 168 | + if ($this->requireFile($file)) { |
|
| 169 | + // yes, we're done |
|
| 170 | + return $file; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + // never found it |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * If a file exists, require it from the file system. |
|
| 180 | - * |
|
| 181 | - * @param string $file The file to require. |
|
| 182 | - * @return bool True if the file exists, false if not. |
|
| 183 | - */ |
|
| 184 | - protected function requireFile(string $file): bool |
|
| 185 | - { |
|
| 186 | - if (file_exists($file)) { |
|
| 187 | - require $file; |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 178 | + /** |
|
| 179 | + * If a file exists, require it from the file system. |
|
| 180 | + * |
|
| 181 | + * @param string $file The file to require. |
|
| 182 | + * @return bool True if the file exists, false if not. |
|
| 183 | + */ |
|
| 184 | + protected function requireFile(string $file): bool |
|
| 185 | + { |
|
| 186 | + if (file_exists($file)) { |
|
| 187 | + require $file; |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | 192 | } |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function prefixes(string $prefix = ''): array |
| 68 | 68 | { |
| 69 | - if (! empty($prefix)) { |
|
| 69 | + if ( ! empty($prefix)) { |
|
| 70 | 70 | // are there any base directories for this namespace prefix? |
| 71 | - return $this->prefixes[ $prefix ] ?? []; |
|
| 71 | + return $this->prefixes[$prefix] ?? []; |
|
| 72 | 72 | } |
| 73 | 73 | return $this->prefixes; |
| 74 | 74 | } |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | public function addNamespace(string $prefix, string $base_dir, bool $prepend = false) |
| 100 | 100 | { |
| 101 | 101 | // normalize namespace prefix |
| 102 | - $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
| 102 | + $prefix = trim($prefix, Psr4Autoloader::NS).Psr4Autoloader::NS; |
|
| 103 | 103 | // normalize the base directory with a trailing separator |
| 104 | 104 | $base_dir = str_replace(['\\', '/'], '/', $base_dir); |
| 105 | - $base_dir = rtrim($base_dir, '/\\') . '/'; |
|
| 105 | + $base_dir = rtrim($base_dir, '/\\').'/'; |
|
| 106 | 106 | // initialize the namespace prefix array |
| 107 | - if (isset($this->prefixes[ $prefix ]) === false) { |
|
| 108 | - $this->prefixes[ $prefix ] = array(); |
|
| 107 | + if (isset($this->prefixes[$prefix]) === false) { |
|
| 108 | + $this->prefixes[$prefix] = array(); |
|
| 109 | 109 | } |
| 110 | 110 | // retain the base directory for the namespace prefix |
| 111 | 111 | if ($prepend) { |
| 112 | - array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
| 112 | + array_unshift($this->prefixes[$prefix], $base_dir); |
|
| 113 | 113 | } else { |
| 114 | - $this->prefixes[ $prefix ][] = $base_dir; |
|
| 114 | + $this->prefixes[$prefix][] = $base_dir; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -11,284 +11,284 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class EEH_Autoloader extends EEH_Base |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * instance of the EE_System object |
|
| 16 | - * |
|
| 17 | - * @var $_instance |
|
| 18 | - */ |
|
| 19 | - private static $_instance = null; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var array $_autoloaders |
|
| 23 | - */ |
|
| 24 | - private static $_autoloaders; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * set to "paths" to display autoloader class => path mappings |
|
| 28 | - * set to "times" to display autoloader loading times |
|
| 29 | - * set to "all" to display both |
|
| 30 | - * |
|
| 31 | - * @var string $debug |
|
| 32 | - */ |
|
| 33 | - public static $debug = false; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @return void |
|
| 38 | - * @throws Exception |
|
| 39 | - */ |
|
| 40 | - private function __construct() |
|
| 41 | - { |
|
| 42 | - if (self::$_autoloaders === null) { |
|
| 43 | - self::$_autoloaders = []; |
|
| 44 | - $this->_register_custom_autoloaders(); |
|
| 45 | - spl_autoload_register([$this, 'espresso_autoloader']); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return EEH_Autoloader |
|
| 52 | - */ |
|
| 53 | - public static function instance(): ?EEH_Autoloader |
|
| 54 | - { |
|
| 55 | - // check if class object is instantiated |
|
| 56 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 57 | - self::$_instance = new self(); |
|
| 58 | - } |
|
| 59 | - return self::$_instance; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * espresso_autoloader |
|
| 65 | - * |
|
| 66 | - * @param $class_name |
|
| 67 | - * @return void |
|
| 68 | - * @internal param string $class_name - simple class name ie: session |
|
| 69 | - * @internal param $className |
|
| 70 | - */ |
|
| 71 | - public static function espresso_autoloader($class_name) |
|
| 72 | - { |
|
| 73 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 74 | - require_once(self::$_autoloaders[ $class_name ]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * register_autoloader |
|
| 81 | - * |
|
| 82 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
| 83 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
| 84 | - * @param bool $debug **deprecated** |
|
| 85 | - * @throws EE_Error |
|
| 86 | - */ |
|
| 87 | - public static function register_autoloader($class_paths, bool $read_check = true, bool $debug = false) |
|
| 88 | - { |
|
| 89 | - $class_paths = is_array($class_paths) ? $class_paths : [$class_paths]; |
|
| 90 | - foreach ($class_paths as $class => $path) { |
|
| 91 | - // skip all files that are not PHP |
|
| 92 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 93 | - continue; |
|
| 94 | - } |
|
| 95 | - // don't give up! you gotta... |
|
| 96 | - // get some class |
|
| 97 | - if (empty($class)) { |
|
| 98 | - throw new EE_Error( |
|
| 99 | - sprintf( |
|
| 100 | - esc_html__( |
|
| 101 | - 'No Class name was specified while registering an autoloader for the following path: %s.', |
|
| 102 | - 'event_espresso' |
|
| 103 | - ), |
|
| 104 | - $path |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - // one day you will find the path young grasshopper |
|
| 109 | - if (empty($path)) { |
|
| 110 | - throw new EE_Error( |
|
| 111 | - sprintf( |
|
| 112 | - esc_html__( |
|
| 113 | - 'No path was specified while registering an autoloader for the %s class.', |
|
| 114 | - 'event_espresso' |
|
| 115 | - ), |
|
| 116 | - $class |
|
| 117 | - ) |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - // is file readable ? |
|
| 121 | - if ($read_check && ! is_readable($path)) { |
|
| 122 | - throw new EE_Error( |
|
| 123 | - sprintf( |
|
| 124 | - esc_html__( |
|
| 125 | - 'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 126 | - 'event_espresso' |
|
| 127 | - ), |
|
| 128 | - $class, |
|
| 129 | - $path |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
| 134 | - self::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path); |
|
| 135 | - if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
| 136 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * get_autoloaders |
|
| 145 | - * |
|
| 146 | - * @return array |
|
| 147 | - */ |
|
| 148 | - public static function get_autoloaders(): array |
|
| 149 | - { |
|
| 150 | - return self::$_autoloaders; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * register core, model and class 'autoloaders' |
|
| 156 | - * |
|
| 157 | - * @return void |
|
| 158 | - * @throws EE_Error |
|
| 159 | - */ |
|
| 160 | - private function _register_custom_autoloaders() |
|
| 161 | - { |
|
| 162 | - EEH_Autoloader::$debug = ''; |
|
| 163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
| 164 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 165 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
| 166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
| 167 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
| 168 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
| 169 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 170 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 171 | - EEH_Debug_Tools::instance()->show_times(); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - public static function register_helpers_autoloaders() |
|
| 177 | - { |
|
| 178 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - public static function register_form_sections_autoloaders() |
|
| 182 | - { |
|
| 183 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * register core, model and class 'autoloaders' |
|
| 189 | - * |
|
| 190 | - * @return void |
|
| 191 | - * @throws EE_Error |
|
| 192 | - */ |
|
| 193 | - public static function register_line_item_display_autoloaders() |
|
| 194 | - { |
|
| 195 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * register core, model and class 'autoloaders' |
|
| 201 | - * |
|
| 202 | - * @return void |
|
| 203 | - * @throws EE_Error |
|
| 204 | - */ |
|
| 205 | - public static function register_line_item_filter_autoloaders() |
|
| 206 | - { |
|
| 207 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * register template part 'autoloaders' |
|
| 213 | - * |
|
| 214 | - * @return void |
|
| 215 | - * @throws EE_Error |
|
| 216 | - */ |
|
| 217 | - public static function register_template_part_autoloaders() |
|
| 218 | - { |
|
| 219 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @return void |
|
| 225 | - * @throws EE_Error |
|
| 226 | - */ |
|
| 227 | - public static function register_business_classes() |
|
| 228 | - { |
|
| 229 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
| 235 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
| 236 | - * If that's not the case, you'll need to improve this function or just use |
|
| 237 | - * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for |
|
| 238 | - * files, but it only does it once -- not on EACH time the autoloader is used |
|
| 239 | - * |
|
| 240 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
| 241 | - * @param bool $recursive |
|
| 242 | - * @param bool $debug **deprecated** |
|
| 243 | - * @throws EE_Error |
|
| 244 | - */ |
|
| 245 | - public static function register_autoloaders_for_each_file_in_folder( |
|
| 246 | - string $folder, |
|
| 247 | - bool $recursive = false, |
|
| 248 | - bool $debug = false |
|
| 249 | - ) { |
|
| 250 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
| 251 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
| 252 | - } |
|
| 253 | - // make sure last char is a / |
|
| 254 | - $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : ''; |
|
| 255 | - $class_to_filepath_map = []; |
|
| 256 | - $exclude = ['index']; |
|
| 257 | - // get all the files in that folder that end in php |
|
| 258 | - $filepaths = glob($folder . '*'); |
|
| 259 | - |
|
| 260 | - if (empty($filepaths)) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - foreach ($filepaths as $filepath) { |
|
| 265 | - if (substr($filepath, -4, 4) === '.php') { |
|
| 266 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
| 267 | - if (! in_array($class_name, $exclude)) { |
|
| 268 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 269 | - } |
|
| 270 | - } elseif ($recursive) { |
|
| 271 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
| 275 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
| 276 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 277 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
| 284 | - * |
|
| 285 | - * @param string $class_name - simple class name ie: EE_Session |
|
| 286 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
| 287 | - */ |
|
| 288 | - public static function add_alias(string $class_name, string $alias) |
|
| 289 | - { |
|
| 290 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 291 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 292 | - } |
|
| 293 | - } |
|
| 14 | + /** |
|
| 15 | + * instance of the EE_System object |
|
| 16 | + * |
|
| 17 | + * @var $_instance |
|
| 18 | + */ |
|
| 19 | + private static $_instance = null; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var array $_autoloaders |
|
| 23 | + */ |
|
| 24 | + private static $_autoloaders; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * set to "paths" to display autoloader class => path mappings |
|
| 28 | + * set to "times" to display autoloader loading times |
|
| 29 | + * set to "all" to display both |
|
| 30 | + * |
|
| 31 | + * @var string $debug |
|
| 32 | + */ |
|
| 33 | + public static $debug = false; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @return void |
|
| 38 | + * @throws Exception |
|
| 39 | + */ |
|
| 40 | + private function __construct() |
|
| 41 | + { |
|
| 42 | + if (self::$_autoloaders === null) { |
|
| 43 | + self::$_autoloaders = []; |
|
| 44 | + $this->_register_custom_autoloaders(); |
|
| 45 | + spl_autoload_register([$this, 'espresso_autoloader']); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return EEH_Autoloader |
|
| 52 | + */ |
|
| 53 | + public static function instance(): ?EEH_Autoloader |
|
| 54 | + { |
|
| 55 | + // check if class object is instantiated |
|
| 56 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 57 | + self::$_instance = new self(); |
|
| 58 | + } |
|
| 59 | + return self::$_instance; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * espresso_autoloader |
|
| 65 | + * |
|
| 66 | + * @param $class_name |
|
| 67 | + * @return void |
|
| 68 | + * @internal param string $class_name - simple class name ie: session |
|
| 69 | + * @internal param $className |
|
| 70 | + */ |
|
| 71 | + public static function espresso_autoloader($class_name) |
|
| 72 | + { |
|
| 73 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 74 | + require_once(self::$_autoloaders[ $class_name ]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * register_autoloader |
|
| 81 | + * |
|
| 82 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
| 83 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
| 84 | + * @param bool $debug **deprecated** |
|
| 85 | + * @throws EE_Error |
|
| 86 | + */ |
|
| 87 | + public static function register_autoloader($class_paths, bool $read_check = true, bool $debug = false) |
|
| 88 | + { |
|
| 89 | + $class_paths = is_array($class_paths) ? $class_paths : [$class_paths]; |
|
| 90 | + foreach ($class_paths as $class => $path) { |
|
| 91 | + // skip all files that are not PHP |
|
| 92 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
| 93 | + continue; |
|
| 94 | + } |
|
| 95 | + // don't give up! you gotta... |
|
| 96 | + // get some class |
|
| 97 | + if (empty($class)) { |
|
| 98 | + throw new EE_Error( |
|
| 99 | + sprintf( |
|
| 100 | + esc_html__( |
|
| 101 | + 'No Class name was specified while registering an autoloader for the following path: %s.', |
|
| 102 | + 'event_espresso' |
|
| 103 | + ), |
|
| 104 | + $path |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + // one day you will find the path young grasshopper |
|
| 109 | + if (empty($path)) { |
|
| 110 | + throw new EE_Error( |
|
| 111 | + sprintf( |
|
| 112 | + esc_html__( |
|
| 113 | + 'No path was specified while registering an autoloader for the %s class.', |
|
| 114 | + 'event_espresso' |
|
| 115 | + ), |
|
| 116 | + $class |
|
| 117 | + ) |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + // is file readable ? |
|
| 121 | + if ($read_check && ! is_readable($path)) { |
|
| 122 | + throw new EE_Error( |
|
| 123 | + sprintf( |
|
| 124 | + esc_html__( |
|
| 125 | + 'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 126 | + 'event_espresso' |
|
| 127 | + ), |
|
| 128 | + $class, |
|
| 129 | + $path |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
| 134 | + self::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path); |
|
| 135 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
| 136 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * get_autoloaders |
|
| 145 | + * |
|
| 146 | + * @return array |
|
| 147 | + */ |
|
| 148 | + public static function get_autoloaders(): array |
|
| 149 | + { |
|
| 150 | + return self::$_autoloaders; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * register core, model and class 'autoloaders' |
|
| 156 | + * |
|
| 157 | + * @return void |
|
| 158 | + * @throws EE_Error |
|
| 159 | + */ |
|
| 160 | + private function _register_custom_autoloaders() |
|
| 161 | + { |
|
| 162 | + EEH_Autoloader::$debug = ''; |
|
| 163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
| 164 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 165 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
| 166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
| 167 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
| 168 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
| 169 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 170 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 171 | + EEH_Debug_Tools::instance()->show_times(); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + public static function register_helpers_autoloaders() |
|
| 177 | + { |
|
| 178 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + public static function register_form_sections_autoloaders() |
|
| 182 | + { |
|
| 183 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * register core, model and class 'autoloaders' |
|
| 189 | + * |
|
| 190 | + * @return void |
|
| 191 | + * @throws EE_Error |
|
| 192 | + */ |
|
| 193 | + public static function register_line_item_display_autoloaders() |
|
| 194 | + { |
|
| 195 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * register core, model and class 'autoloaders' |
|
| 201 | + * |
|
| 202 | + * @return void |
|
| 203 | + * @throws EE_Error |
|
| 204 | + */ |
|
| 205 | + public static function register_line_item_filter_autoloaders() |
|
| 206 | + { |
|
| 207 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * register template part 'autoloaders' |
|
| 213 | + * |
|
| 214 | + * @return void |
|
| 215 | + * @throws EE_Error |
|
| 216 | + */ |
|
| 217 | + public static function register_template_part_autoloaders() |
|
| 218 | + { |
|
| 219 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return void |
|
| 225 | + * @throws EE_Error |
|
| 226 | + */ |
|
| 227 | + public static function register_business_classes() |
|
| 228 | + { |
|
| 229 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
| 235 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
| 236 | + * If that's not the case, you'll need to improve this function or just use |
|
| 237 | + * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for |
|
| 238 | + * files, but it only does it once -- not on EACH time the autoloader is used |
|
| 239 | + * |
|
| 240 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
| 241 | + * @param bool $recursive |
|
| 242 | + * @param bool $debug **deprecated** |
|
| 243 | + * @throws EE_Error |
|
| 244 | + */ |
|
| 245 | + public static function register_autoloaders_for_each_file_in_folder( |
|
| 246 | + string $folder, |
|
| 247 | + bool $recursive = false, |
|
| 248 | + bool $debug = false |
|
| 249 | + ) { |
|
| 250 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
| 251 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
| 252 | + } |
|
| 253 | + // make sure last char is a / |
|
| 254 | + $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : ''; |
|
| 255 | + $class_to_filepath_map = []; |
|
| 256 | + $exclude = ['index']; |
|
| 257 | + // get all the files in that folder that end in php |
|
| 258 | + $filepaths = glob($folder . '*'); |
|
| 259 | + |
|
| 260 | + if (empty($filepaths)) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + foreach ($filepaths as $filepath) { |
|
| 265 | + if (substr($filepath, -4, 4) === '.php') { |
|
| 266 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
| 267 | + if (! in_array($class_name, $exclude)) { |
|
| 268 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 269 | + } |
|
| 270 | + } elseif ($recursive) { |
|
| 271 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
| 275 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
| 276 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
| 277 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
| 284 | + * |
|
| 285 | + * @param string $class_name - simple class name ie: EE_Session |
|
| 286 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
| 287 | + */ |
|
| 288 | + public static function add_alias(string $class_name, string $alias) |
|
| 289 | + { |
|
| 290 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 291 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | public static function instance(): ?EEH_Autoloader |
| 54 | 54 | { |
| 55 | 55 | // check if class object is instantiated |
| 56 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
| 56 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
| 57 | 57 | self::$_instance = new self(); |
| 58 | 58 | } |
| 59 | 59 | return self::$_instance; |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public static function espresso_autoloader($class_name) |
| 72 | 72 | { |
| 73 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 74 | - require_once(self::$_autoloaders[ $class_name ]); |
|
| 73 | + if (isset(self::$_autoloaders[$class_name])) { |
|
| 74 | + require_once(self::$_autoloaders[$class_name]); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | ) |
| 131 | 131 | ); |
| 132 | 132 | } |
| 133 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
| 134 | - self::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path); |
|
| 133 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
| 134 | + self::$_autoloaders[$class] = str_replace(['/', '\\'], '/', $path); |
|
| 135 | 135 | if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
| 136 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
| 136 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
| 167 | 167 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
| 168 | 168 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
| 169 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
| 169 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
| 170 | 170 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
| 171 | 171 | EEH_Debug_Tools::instance()->show_times(); |
| 172 | 172 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public static function register_line_item_display_autoloaders() |
| 194 | 194 | { |
| 195 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
| 195 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public static function register_line_item_filter_autoloaders() |
| 206 | 206 | { |
| 207 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
| 207 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public static function register_template_part_autoloaders() |
| 218 | 218 | { |
| 219 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
| 219 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public static function register_business_classes() |
| 228 | 228 | { |
| 229 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
| 229 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business'); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
| 252 | 252 | } |
| 253 | 253 | // make sure last char is a / |
| 254 | - $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : ''; |
|
| 254 | + $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : ''; |
|
| 255 | 255 | $class_to_filepath_map = []; |
| 256 | 256 | $exclude = ['index']; |
| 257 | 257 | // get all the files in that folder that end in php |
| 258 | - $filepaths = glob($folder . '*'); |
|
| 258 | + $filepaths = glob($folder.'*'); |
|
| 259 | 259 | |
| 260 | 260 | if (empty($filepaths)) { |
| 261 | 261 | return; |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | foreach ($filepaths as $filepath) { |
| 265 | 265 | if (substr($filepath, -4, 4) === '.php') { |
| 266 | 266 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
| 267 | - if (! in_array($class_name, $exclude)) { |
|
| 268 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
| 267 | + if ( ! in_array($class_name, $exclude)) { |
|
| 268 | + $class_to_filepath_map [$class_name] = $filepath; |
|
| 269 | 269 | } |
| 270 | 270 | } elseif ($recursive) { |
| 271 | 271 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public static function add_alias(string $class_name, string $alias) |
| 289 | 289 | { |
| 290 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
| 291 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
| 290 | + if (isset(self::$_autoloaders[$class_name])) { |
|
| 291 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | } |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | <label><?php esc_html_e('Amount Owing: ', 'event_espresso'); ?></label> |
| 31 | 31 | </td> |
| 32 | 32 | <td class="<?php |
| 33 | - echo sanitize_html_class( |
|
| 34 | - $transaction->paid() == $transaction->total() |
|
| 35 | - ? 'ee-transaction-paid' |
|
| 36 | - : 'ee-transaction-unpaid' |
|
| 37 | - ); |
|
| 38 | - ?>" |
|
| 33 | + echo sanitize_html_class( |
|
| 34 | + $transaction->paid() == $transaction->total() |
|
| 35 | + ? 'ee-transaction-paid' |
|
| 36 | + : 'ee-transaction-unpaid' |
|
| 37 | + ); |
|
| 38 | + ?>" |
|
| 39 | 39 | > |
| 40 | 40 | <?php echo wp_kses(EEH_Template::format_currency($transaction->remaining()), AllowedTags::getAllowedTags()); ?> |
| 41 | 41 | </td> |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | </td> |
| 47 | 47 | <td> |
| 48 | 48 | <?php $transaction->e_pretty_status(true); |
| 49 | - if ($show_try_pay_again_link && ! $transaction->is_completed()) { ?> |
|
| 49 | + if ($show_try_pay_again_link && ! $transaction->is_completed()) { ?> |
|
| 50 | 50 | <span class="small-text"> |
| 51 | 51 | <a href='<?php echo esc_url_raw($SPCO_payment_options_url); ?>'> |
| 52 | 52 | <?php esc_html_e('View Payment Options', 'event_espresso'); ?> |
@@ -64,16 +64,16 @@ discard block |
||
| 64 | 64 | </td> |
| 65 | 65 | </tr> |
| 66 | 66 | <?php do_action( |
| 67 | - 'AHEE__thank_you_page_transaction_details_template__after_transaction_table_row', |
|
| 68 | - $transaction |
|
| 69 | - ); ?> |
|
| 67 | + 'AHEE__thank_you_page_transaction_details_template__after_transaction_table_row', |
|
| 68 | + $transaction |
|
| 69 | + ); ?> |
|
| 70 | 70 | </tbody> |
| 71 | 71 | </table> |
| 72 | 72 | |
| 73 | 73 | <?php if ($show_try_pay_again_link && ! $transaction->is_completed()) { ?> |
| 74 | 74 | <p class="small-text jst-rght"> |
| 75 | 75 | <a href='<?php echo esc_url_raw($SPCO_payment_options_url); ?>'><?php |
| 76 | - esc_html_e("Click here to view Payment Options", 'event_espresso'); ?></a> |
|
| 76 | + esc_html_e("Click here to view Payment Options", 'event_espresso'); ?></a> |
|
| 77 | 77 | </p> |
| 78 | 78 | <br /> |
| 79 | 79 | |