Skip to content

Commit

Permalink
Replace CRM_Core_DAO_Base with (mostly) static alias CRM_*_DAO_Base
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
totten committed Jun 28, 2024
1 parent 42e6dd3 commit 50297da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/CRM/CivixBundle/Resources/views/Code/entity-dao.php.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <?php echo $daoClassName ?> extends CRM_Core_DAO_Base {
class <?php echo $daoClassName ?> extends <?php echo $_namespace . '_DAO_Base'; ?> {

// Required by some versions of CiviCRM.
public static $_tableName = <?php var_export($tableName); ?>;

}
16 changes: 15 additions & 1 deletion src/CRM/CivixBundle/Resources/views/Code/module.civix.php.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,22 @@ public static function schema() {
spl_autoload_register('_<?php echo $mainFile ?>_civix_class_loader', TRUE, TRUE);

function _<?php echo $mainFile ?>_civix_class_loader($class) {
// This allows us to tap-in to the installation process (without incurring real file-reads on typical requests).
<?php $_clPrefix = 'CiviMix\\Schema\\' . \CRM\CivixBundle\Utils\Naming::createCamelName($mainFile) . '\\' ?>
<?php $_localBase = $_namespace . '_DAO_Base'; ?>
if ($class === <?php var_export($_localBase); ?>) {
if (version_compare(CRM_Utils_System::version(), '5.74.beta', '>=')) {
class_alias('CRM_Core_DAO_Base', <?php var_export($_localBase); ?>);
// ^^ Materialize concrete names -- encourage IDE's to pick up on this association.
}
else {
$realClass = <?php var_export($_clPrefix . "DAO") ?>;
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, <?php var_export($_clPrefix) ?>) === 0) {
// civimix-schema@5 is designed for backported use in download/activation workflows,
// where new revisions may become dynamically available.
Expand Down

0 comments on commit 50297da

Please sign in to comment.