From 97b6f1e3eeb135c7381564c89b2f672e1973109e Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Thu, 6 Jul 2023 15:03:42 +0200 Subject: [PATCH 1/2] Include the CMS Composer project's autoloader This avoids errors including e. g. PEAR's Log.php while loading CRM_Core_Config when using CiviCRM Core/packages as symlinked dependencies in dev environments --- src/Bootstrap.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index e3c9e1c2..ff730dc5 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -232,6 +232,15 @@ public function boot($options = array()) { require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; \CRM_Core_ClassLoader::singleton()->register(); + // Include the project autoloader. + if (!isset($cmsBasePath)) { + list (, $cmsBasePath) = $this->findCmsRoot($this->getSearchDir()); + } + $project_autoloader = dirname($cmsBasePath) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; + if (file_exists($project_autoloader)) { + require_once($project_autoloader); + } + if (!empty($options['prefetch'])) { $this->writeln("Call core bootstrap", OutputInterface::VERBOSITY_VERBOSE); // I'm not sure why this is called explicitly during bootstrap From fc4a9f6b67f2dc0f5cfdd0f722962e1009e3437f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 9 Jul 2023 22:18:07 -0700 Subject: [PATCH 2/2] Bootstrap - Use same 'autoload.php' step for boot() and generate() --- src/Bootstrap.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index ff730dc5..bfa40d07 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -232,13 +232,13 @@ public function boot($options = array()) { require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; \CRM_Core_ClassLoader::singleton()->register(); - // Include the project autoloader. + // Include the UF's autoloader. Should this be tuned based on UF type? if (!isset($cmsBasePath)) { list (, $cmsBasePath) = $this->findCmsRoot($this->getSearchDir()); } - $project_autoloader = dirname($cmsBasePath) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; - if (file_exists($project_autoloader)) { - require_once($project_autoloader); + $cmsAutoloader = dirname($cmsBasePath) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; + if (file_exists($cmsAutoloader)) { + require_once $cmsAutoloader; } if (!empty($options['prefetch'])) { @@ -295,6 +295,13 @@ public function generate() { $code[] = 'require_once $GLOBALS["civicrm_root"] . "/CRM/Core/ClassLoader.php";'; $code[] = '\CRM_Core_ClassLoader::singleton()->register();'; + // Include the UF's autoloader. Should this be tuned based on UF type? + list (, $cmsBasePath) = $this->findCmsRoot($this->getSearchDir()); + $cmsAutoloader = dirname($cmsBasePath) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; + if (file_exists($cmsAutoloader)) { + $code[] = sprintf('require_once %s;', var_export($cmsAutoloader, 1)); + } + return implode("\n", $code); }