From a52a2a531acacd0b4fa1f0d940b5aba055afb6f1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 24 Aug 2023 16:00:23 -0700 Subject: [PATCH] CRM_Utils_System_* - Add method 'isLoaded()' --- CRM/Utils/System/Base.php | 10 ++++++++++ CRM/Utils/System/DrupalBase.php | 8 ++++++++ CRM/Utils/System/Joomla.php | 8 ++++++++ CRM/Utils/System/Standalone.php | 8 ++++++++ CRM/Utils/System/UnitTests.php | 8 ++++++++ CRM/Utils/System/WordPress.php | 8 ++++++++ 6 files changed, 50 insertions(+) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index c3986180a1..b4ee6eeb15 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -56,6 +56,16 @@ abstract class CRM_Utils_System_Base { } } + /** + * Determine if the UF/CMS has been loaded already. + * + * This is generally TRUE. If using the "extern" boot protocol, then this may initially be false (until loadBootStrap runs). + * + * @internal + * @return bool + */ + abstract public function isLoaded(): bool; + abstract public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL); /** diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index c68a5c01f5..c413c14ed0 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -40,6 +40,14 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { $this->supports_form_extensions = TRUE; } + /** + * @internal + * @return bool + */ + public function isLoaded(): bool { + return function_exists('t'); + } + /** * @inheritdoc */ diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 1f215d2a4b..539428cbba 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -33,6 +33,14 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { $this->is_drupal = FALSE; } + /** + * @internal + * @return bool + */ + public function isLoaded(): bool { + return class_exists('JFactory'); + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/Standalone.php b/CRM/Utils/System/Standalone.php index bf2a4fa853..db6a003975 100644 --- a/CRM/Utils/System/Standalone.php +++ b/CRM/Utils/System/Standalone.php @@ -22,6 +22,14 @@ use Civi\Standalone\Security; */ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { + /** + * @internal + * @return bool + */ + public function isLoaded(): bool { + return TRUE; + } + public function missingStandaloneExtension() { // error_log("sessionStart, " . (class_exists(\Civi\Standalone\Security::class) ? 'exists' : 'no ext')); return !class_exists(\Civi\Standalone\Security::class); diff --git a/CRM/Utils/System/UnitTests.php b/CRM/Utils/System/UnitTests.php index 8aea53af58..adc3ca9bf1 100644 --- a/CRM/Utils/System/UnitTests.php +++ b/CRM/Utils/System/UnitTests.php @@ -37,6 +37,14 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base { \Civi\Test::eventChecker()->addListeners(); } + /** + * @internal + * @return bool + */ + public function isLoaded(): bool { + return TRUE; + } + /** * @param string $name * @param string $value diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index a8ec227893..032e159926 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -707,6 +707,14 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { return TRUE; } + /** + * @internal + * @return bool + */ + public function isLoaded(): bool { + return function_exists('__'); + } + /** * Tries to bootstrap WordPress. * -- 2.25.1