From 50297da7a74fee0a149bd36dfac56926191d9517 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 27 Jun 2024 00:42:48 -0700 Subject: [PATCH] Replace `CRM_Core_DAO_Base` with (mostly) static alias `CRM_*_DAO_Base` * This approach defines `CRM_*_DAO_Base`. * When deployed on 5.74+, `CRM_*_DAO_Base` will be exactly the same as `CRM_Core_DAO_Base` In other words: class CRM_Foo_DAO_MyData extends CRM_Foo_DAO_Base {} class_alias('CRM_Core_DAO_Base', 'CRM_Foo_DAO_Base'); class CRM_Core_DAO_Base extends CRM_Core_DAO {} * When deployed on <5.74, `CRM_*_DAO_Base` will use the anonymous backport variant from civimix. In other words: class CRM_Foo_DAO_MyData extends CRM_Foo_DAO_Base {} class_alias('CiviMix\Schema\Foo\DAO', 'CRM_Foo_DAO_Base'); ^^ Read anonymous class... which extends CRM_Core_DAO * In this arrangement, the anonymous DAO implementation is -only- used on old versions. Once you get to 5.74+, you use the local base. This should provide better IDE hints and simpler callstacks. You presumptively do not get backports of changes/improvements in the DAO base. --- .../Resources/views/Code/entity-dao.php.php | 5 ++++- .../Resources/views/Code/module.civix.php.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/CRM/CivixBundle/Resources/views/Code/entity-dao.php.php b/src/CRM/CivixBundle/Resources/views/Code/entity-dao.php.php index 48068805..b8724d2d 100644 --- a/src/CRM/CivixBundle/Resources/views/Code/entity-dao.php.php +++ b/src/CRM/CivixBundle/Resources/views/Code/entity-dao.php.php @@ -13,6 +13,9 @@ * This stub provides compatibility. It is not intended to be modified in a * substantive way. However, you may add comments and annotations. */ -class extends CRM_Core_DAO_Base { +class extends { + + // Required by some versions of CiviCRM. + public static $_tableName = ; } diff --git a/src/CRM/CivixBundle/Resources/views/Code/module.civix.php.php b/src/CRM/CivixBundle/Resources/views/Code/module.civix.php.php index bed76eb7..04be9273 100644 --- a/src/CRM/CivixBundle/Resources/views/Code/module.civix.php.php +++ b/src/CRM/CivixBundle/Resources/views/Code/module.civix.php.php @@ -104,8 +104,22 @@ public static function schema() { spl_autoload_register('__civix_class_loader', TRUE, TRUE); function __civix_class_loader($class) { - // This allows us to tap-in to the installation process (without incurring real file-reads on typical requests). + + if ($class === ) { + if (version_compare(CRM_Utils_System::version(), '5.74.beta', '>=')) { + class_alias('CRM_Core_DAO_Base', ); + // ^^ Materialize concrete names -- encourage IDE's to pick up on this association. + } + else { + $realClass = ; + class_alias($realClass, $class); + // ^^ Abstract names -- discourage IDE's from picking up on this association. + } + return; + } + + // This allows us to tap-in to the installation process (without incurring real file-reads on typical requests). if (strpos($class, ) === 0) { // civimix-schema@5 is designed for backported use in download/activation workflows, // where new revisions may become dynamically available.