-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
civimix-schema - Make it reloadable to work in multi-module/multi-dow…
…nload scenarios
- Loading branch information
Showing
4 changed files
with
65 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,36 @@ | ||
<?php | ||
namespace CiviMix\Schema; | ||
|
||
\pathload()->activatePackage('civicrm-schema@5' , __DIR__, [ | ||
'autoload' => [ | ||
'psr-4' => [ | ||
'CiviMix\\Schema\\' => ['src/'], | ||
] | ||
] | ||
\pathload()->activatePackage('civimix-schema@5', __DIR__, [ | ||
'reloadable' => TRUE, | ||
]); | ||
|
||
// Any classname matching `CiviMix\Schema\Automatic\*` will be aliased to our implementation. | ||
$GLOBALS['CiviMixSchema5']['aliases'] = [ | ||
'CiviMix\\Schema\\Automatic\\' => __DIR__ . '/src/Automatic.php', | ||
'CiviMix\\Schema\\SqlInstaller\\' => __DIR__ . '/src/SqlInstaller.php', | ||
]; | ||
|
||
$GLOBALS['CiviMixSchema5']['loader'] = function(string $class) { | ||
if ('CiviMix\\Schema\\' === substr($class, 0, 15)) { | ||
// This package is designed for backported use in download/activation, | ||
// workflows, where new revisions may become dynamically available. | ||
// Ensure we have the latest revision. | ||
pathload()->loadPackage('civimix-schema@5', TRUE); | ||
foreach ($GLOBALS['CiviMixSchema5']['aliases'] as $prefix => $absPath) { | ||
if (strpos($class, $prefix) === 0) { | ||
class_alias(get_class(require $absPath), $class); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// \CiviMix\Schema\loader() is a facade. It is expected to remain identical across versions. | ||
if (!function_exists(__NAMESPACE__ . '\loader')) { | ||
|
||
function loader(string $class) { | ||
return call_user_func($GLOBALS['CiviMixSchema5']['loader'], $class); | ||
} | ||
|
||
spl_autoload_register(__NAMESPACE__ . '\loader'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters