diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index fbd75b372440..05aa38691941 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -42,6 +42,7 @@ class Autoload extends AutoloadConfig public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', + 'Local' => ROOTPATH . 'local/src', ]; /** diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index 8a74697c835b..57feb12b26c9 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -50,6 +50,14 @@ class AutoloadConfig */ public $classmap = []; + /** + * Path to Composer's autoload for the Local namespace. + * E.g. ROOTPATH . 'local/vendor/autoload.php' + * + * @var string|null + */ + public $local; + /** * ------------------------------------------------------------------- * Namespaces @@ -111,5 +119,13 @@ public function __construct() $this->psr4 = array_merge($this->corePsr4, $this->psr4); $this->classmap = array_merge($this->coreClassmap, $this->classmap); + + if (isset($this->psr4['Local'])) + { + $this->local = $this->psr4['Local'] + . DIRECTORY_SEPARATOR . '..' + . DIRECTORY_SEPARATOR . 'vendor' + . DIRECTORY_SEPARATOR . 'autoload.php'; + } } } diff --git a/system/bootstrap.php b/system/bootstrap.php index e892ed25aa85..3820d37390a0 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -117,7 +117,8 @@ class_alias('Config\Services', 'CodeIgniter\Services'); } // Initialize and register the loader with the SPL autoloader stack. -Services::autoloader()->initialize(new Autoload(), new Modules())->register(); +$autoload = new Autoload(); +Services::autoloader()->initialize($autoload, new Modules())->register(); // Now load Composer's if it's available if (is_file(COMPOSER_PATH)) @@ -135,6 +136,13 @@ class_alias('Config\Services', 'CodeIgniter\Services'); require_once COMPOSER_PATH; } +// Check for an additional Composer autoload for Local namespace +if ($autoload->local && is_file($autoload->local)) +{ + require_once $autoload->local; +} +unset($autoload); + // Load environment settings from .env files into $_SERVER and $_ENV require_once SYSTEMPATH . 'Config/DotEnv.php';