Skip to content

Commit

Permalink
(REF) Rename various methods/variables to follow "generator" terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Dec 13, 2023
1 parent d30cb6a commit 0256e69
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 66 deletions.
8 changes: 4 additions & 4 deletions src/CRM/CivixBundle/Command/AddManagedEntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
// Boot CiviCRM to use api4
Civix::boot(['output' => $output]);

$upgrader = \Civix::generator();
$upgrader->addMixins(['[email protected]']);
$gen = \Civix::generator();
$gen->addMixins(['[email protected]']);
if ($entityName === 'Afform') {
$upgrader->exportAfform($entityId);
$gen->exportAfform($entityId);
}
else {
$upgrader->exportMgd($entityName, $entityId);
$gen->exportMgd($entityName, $entityId);
}

return 0;
Expand Down
10 changes: 5 additions & 5 deletions src/CRM/CivixBundle/Command/AddServiceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ protected function configure() {
}

protected function execute(InputInterface $input, OutputInterface $output) {
$up = \Civix::generator();
$up->addMixins(['[email protected]']);
$gen = \Civix::generator();
$gen->addMixins(['[email protected]']);

$servicePrefix = $up->infoXml->getFile();
$namespace = Naming::coerceNamespace($up->infoXml->getNamespace(), $input->getOption('naming'));
$servicePrefix = $gen->infoXml->getFile();
$namespace = Naming::coerceNamespace($gen->infoXml->getNamespace(), $input->getOption('naming'));

if ($input->isInteractive()) {
$defaultName = $input->getArgument('name') ?? Naming::createServiceName($servicePrefix, 'myService');
Expand All @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$baseNameParts = array_map('ucfirst', explode('.', $baseName));
$className = Naming::createClassName($namespace, ...$baseNameParts);

$up->addClass($className, 'service.php.php', [
$gen->addClass($className, 'service.php.php', [
'service' => $serviceName,
]);
}
Expand Down
14 changes: 7 additions & 7 deletions src/CRM/CivixBundle/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ protected function executeIncrementalUpgrades() {
$io->section("Upgrade <info>v{$lastVersion}</info> => <info>v{$upgradeVersion}</info>");
$io->writeln("<info>Executing upgrade script</info> $upgradeFile");

$upgrader = Civix::generator();
$gen = Civix::generator();
$func = require $upgradeFile;
$func($upgrader);
$upgrader->updateFormatVersion($upgradeVersion);
$func($gen);
$gen->updateFormatVersion($upgradeVersion);
$lastVersion = $upgradeVersion;
}
}
Expand All @@ -85,10 +85,10 @@ protected function executeGenericUpgrade(): void {
$io = \Civix::io();
$io->title('General upgrade');

$upgrader = Civix::generator();
$upgrader->cleanEmptyHooks();
$upgrader->cleanEmptyLines();
$upgrader->reconcileMixins();
$gen = Civix::generator();
$gen->cleanEmptyHooks();
$gen->cleanEmptyLines();
$gen->reconcileMixins();

/**
* @var \CRM\CivixBundle\Builder\Info $info
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/CivixProjectTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function civixUpgrade(array $options = []): CommandTester {
*
* @return \CRM\CivixBundle\Generator
*/
public function civixUpgradeHelper(): Generator {
public function civixGeneratorHelper(): Generator {
$input = new ArrayInput([]);
$output = new StreamOutput(fopen('php://memory', 'w', FALSE));
\Civix::ioStack()->push($input, $output);
Expand Down
12 changes: 6 additions & 6 deletions upgrades/16.10.0.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*
* At some point in the future, this step could be removed if we configure `info.xml`'s `<upgrader>` option.
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {
$io = \Civix::io();

if (!empty($upgrader->infoXml->get()->upgrader)) {
if (!empty($gen->infoXml->get()->upgrader)) {
$io->note("Found <upgrader> tag. Skip hook_postInstall.");
return;
}

// Give a notice if the new `CRM/*/Upgrader/Base` has a substantive change.
// Note: The change is actually done in the generic regen. This is just a notice.
$phpBaseClass = \CRM\CivixBundle\Utils\Naming::createClassName($upgrader->infoXml->getNamespace(), 'Upgrader', 'Base');
$phpBaseFile = \CRM\CivixBundle\Utils\Naming::createClassFile($upgrader->infoXml->getNamespace(), 'Upgrader', 'Base');
$phpBaseClass = \CRM\CivixBundle\Utils\Naming::createClassName($gen->infoXml->getNamespace(), 'Upgrader', 'Base');
$phpBaseFile = \CRM\CivixBundle\Utils\Naming::createClassFile($gen->infoXml->getNamespace(), 'Upgrader', 'Base');
if (file_exists($phpBaseFile)) {
$content = file_get_contents($phpBaseFile);
if (preg_match('|CRM_Core_BAO_Setting::setItem\(.revision, *.Extension.|', $content)) {
Expand All @@ -31,11 +31,11 @@
}
}

$upgrader->addHookDelegation('civicrm_postInstall', '',
$gen->addHookDelegation('civicrm_postInstall', '',
"This hook is important for supporting the new version of $phpBaseClass.");
}
else {
$upgrader->addHookDelegation('civicrm_postInstall', '',
$gen->addHookDelegation('civicrm_postInstall', '',
'If you use civix to facilitate database upgrades ("civix generate:upgrader"), then you should enable this stub. Otherwise, it is not needed.');
}

Expand Down
8 changes: 4 additions & 4 deletions upgrades/19.06.2.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
* To be consistent and forward-compatible, you should consider updating your
* existing unit-tests to use the name base-classes.
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();

$testFiles = \CRM\CivixBundle\Utils\Files::findFiles($upgrader->baseDir->string('tests'), '*.php');
$upgrader->updateTextFiles($testFiles, function(string $file, string $content) use ($io, $upgrader) {
$testFiles = \CRM\CivixBundle\Utils\Files::findFiles($gen->baseDir->string('tests'), '*.php');
$gen->updateTextFiles($testFiles, function(string $file, string $content) use ($io, $gen) {
$old = 'PHPUnit_Framework_TestCase';
$new = 'PHPUnit\Framework\TestCase';
$relFile = \CRM\CivixBundle\Utils\Files::relativize($file, $upgrader->baseDir->string() . '/');
$relFile = \CRM\CivixBundle\Utils\Files::relativize($file, $gen->baseDir->string() . '/');

if (strpos($content, $old) === FALSE) {
return $content;
Expand Down
10 changes: 5 additions & 5 deletions upgrades/20.06.0.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* If you have a generated `phpunit.xml` or `phpunit.xml.dist` file, it may include the old option `syntaxCheck="false"`.
* You can remove this. The option has been inert and will raise errors in newer versions of PHPUnit.
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();

$files = array_filter([
$upgrader->baseDir->string('phpunit.xml'),
$upgrader->baseDir->string('phpunit.xml.dist'),
$gen->baseDir->string('phpunit.xml'),
$gen->baseDir->string('phpunit.xml.dist'),
], 'file_exists');
$upgrader->updateTextFiles($files, function(string $file, string $oldContent) use ($io, $upgrader) {
$relFile = \CRM\CivixBundle\Utils\Files::relativize($file, $upgrader->baseDir->string() . '/');
$gen->updateTextFiles($files, function(string $file, string $oldContent) use ($io, $gen) {
$relFile = \CRM\CivixBundle\Utils\Files::relativize($file, $gen->baseDir->string() . '/');

$content = $oldContent;
$content = preg_replace(';(\s+)syntaxCheck="[^\"]+">;', '>', $content);
Expand Down
12 changes: 6 additions & 6 deletions upgrades/22.05.0.up.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();
$prefix = $upgrader->infoXml->getFile();
$prefix = $gen->infoXml->getFile();

$io->note([
"Civix v22.05 converts several functions to mixins. This reduces code-duplication and will enable easier updates in the future.",
Expand Down Expand Up @@ -32,8 +32,8 @@
'glob:*.theme.php' => '[email protected]',
];
$mixins = array_filter($filePatterns,
function (string $mixin, string $pattern) use ($upgrader, $io) {
$flagFiles = $upgrader->baseDir->search($pattern);
function (string $mixin, string $pattern) use ($gen, $io) {
$flagFiles = $gen->baseDir->search($pattern);
$io->note($flagFiles
? "Enable \"$mixin\". There are files matching pattern \"$pattern\"."
: "Skip \"$mixin\". There are no files matching pattern \"$pattern\"."
Expand All @@ -42,9 +42,9 @@ function (string $mixin, string $pattern) use ($upgrader, $io) {
},
ARRAY_FILTER_USE_BOTH
);
$upgrader->addMixins($mixins);
$gen->addMixins($mixins);

$upgrader->removeHookDelegation([
$gen->removeHookDelegation([
"_{$prefix}_civix_civicrm_angularModules",
"_{$prefix}_civix_civicrm_managed",
"_{$prefix}_civix_civicrm_alterSettingsFolders",
Expand Down
16 changes: 8 additions & 8 deletions upgrades/22.05.2.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
use CRM\CivixBundle\Builder\Mixins;
use CRM\CivixBundle\Utils\EvilEx;

return function (\CRM\CivixBundle\Generator $upgrader) {
$mixins = new Mixins($upgrader->infoXml, $upgrader->baseDir->string('mixin'));
return function (\CRM\CivixBundle\Generator $gen) {
$mixins = new Mixins($gen->infoXml, $gen->baseDir->string('mixin'));
$declared = $mixins->getDeclaredMixinConstraints();
$hasSettingMixin = (bool) preg_grep('/^setting-php@/', $declared);
$action = NULL;

$upgrader->updateModulePhp(function (\CRM\CivixBundle\Builder\Info $info, string $content) use ($upgrader, $hasSettingMixin, &$action) {
$prefix = $upgrader->infoXml->getFile();
$gen->updateModulePhp(function (\CRM\CivixBundle\Builder\Info $info, string $content) use ($gen, $hasSettingMixin, &$action) {
$prefix = $gen->infoXml->getFile();
$hookFunc = "{$prefix}_civicrm_alterSettingsFolders";
$hookBody = [
'static $configured = FALSE;',
Expand All @@ -23,7 +23,7 @@
'}',
];

$newContent = EvilEx::rewriteMultilineChunk($content, $hookBody, function(array $matchLines) use ($hookFunc, $content, $upgrader, $hasSettingMixin, &$action) {
$newContent = EvilEx::rewriteMultilineChunk($content, $hookBody, function(array $matchLines) use ($hookFunc, $content, $gen, $hasSettingMixin, &$action) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();
$matchLineKeys = array_keys($matchLines);
Expand All @@ -32,7 +32,7 @@
$focusEnd = max($matchLineKeys);

$io->note("The following chunk resembles an older template for \"{$hookFunc}()\".");
$upgrader->showCode($allLines, $focusStart - 4, $focusEnd + 4, $focusStart, $focusEnd);
$gen->showCode($allLines, $focusStart - 4, $focusEnd + 4, $focusStart, $focusEnd);

if ($hasSettingMixin) {
$io->note([
Expand All @@ -55,12 +55,12 @@
});

if ($action === 'm' && !$hasSettingMixin) {
$upgrader->updateMixins(function (Mixins $mixins) {
$gen->updateMixins(function (Mixins $mixins) {
$mixins->addMixin('[email protected]');
});
}
elseif ($action === 'b' && $hasSettingMixin) {
$upgrader->updateMixins(function (Mixins $mixins) {
$gen->updateMixins(function (Mixins $mixins) {
$mixins->removeMixin('setting-php');
});
}
Expand Down
6 changes: 3 additions & 3 deletions upgrades/22.10.0.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*
* Just add the '<psr0>` bit to everything.
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {

$upgrader->updateInfo(function (\CRM\CivixBundle\Builder\Info $info) use ($upgrader) {
$gen->updateInfo(function (\CRM\CivixBundle\Builder\Info $info) use ($gen) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();

$loaders = $info->getClassloaders();
$prefixes = array_column($loaders, 'prefix');
if (file_exists($upgrader->baseDir->string('CRM')) && !in_array('CRM_', $prefixes)) {
if (file_exists($gen->baseDir->string('CRM')) && !in_array('CRM_', $prefixes)) {
$io->section('"CRM" Class-loader');
$io->note([
'Older templates enabled class-loading via "hook_config" and "include_path".',
Expand Down
12 changes: 6 additions & 6 deletions upgrades/22.12.1.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
* - Use core's base class
* - Remove old base class
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {
$io = \Civix::io();
$io->section('Lifecycle Hooks: Install, Upgrade, etc');

$info = $upgrader->infoXml;
$info = $gen->infoXml;
$MIN_COMPAT = '5.38';
$oldCompat = $info->getCompatibilityVer();
$nameSpace = $info->getNamespace();
$mainFile = $upgrader->baseDir->string($info->getFile() . '.php');
$mainFile = $gen->baseDir->string($info->getFile() . '.php');
$upgraderClass = Naming::createClassName($nameSpace, 'Upgrader');
$upgraderFile = Naming::createClassFile($nameSpace, 'Upgrader');
$upgraderBaseClass = Naming::createClassName($nameSpace, 'Upgrader', 'Base');
Expand Down Expand Up @@ -70,23 +70,23 @@
}

$prefix = $info->getFile();
$upgrader->removeHookDelegation([
$gen->removeHookDelegation([
"_{$prefix}_civix_civicrm_postInstall",
"_{$prefix}_civix_civicrm_uninstall",
"_{$prefix}_civix_civicrm_disable",
"_{$prefix}_civix_civicrm_upgrade",
]);

if ($hasUpgrader) {
$upgrader->updateInfo(function(\CRM\CivixBundle\Builder\Info $info) use ($MIN_COMPAT, $upgraderClass) {
$gen->updateInfo(function(\CRM\CivixBundle\Builder\Info $info) use ($MIN_COMPAT, $upgraderClass) {
$info->raiseCompatibilityMinimum($MIN_COMPAT);
// Add <upgrader> tag
if (!$info->get()->xpath('upgrader')) {
$info->get()->addChild('upgrader', $upgraderClass);
}
});
// Switch base class
$upgrader->updateTextFiles([$upgraderFile], function(string $file, string $content) use ($upgraderBaseClass) {
$gen->updateTextFiles([$upgraderFile], function(string $file, string $content) use ($upgraderBaseClass) {
return str_replace($upgraderBaseClass, 'CRM_Extension_Upgrader_Base', $content);
});
}
Expand Down
8 changes: 4 additions & 4 deletions upgrades/23.01.0.up.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use CRM\CivixBundle\Utils\Formatting;

return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();

Expand All @@ -13,8 +13,8 @@
'find:*.tpl' => '[email protected]',
];
$mixins = array_filter($filePatterns,
function (string $mixin, string $pattern) use ($upgrader, $io, &$previewChanges) {
$flagFiles = $upgrader->baseDir->search($pattern);
function (string $mixin, string $pattern) use ($gen, $io, &$previewChanges) {
$flagFiles = $gen->baseDir->search($pattern);
$previewChanges[] = [
'info.xml',
$flagFiles ? "Enable $mixin" : "Skip $mixin. (No files match \"$pattern\")",
Expand All @@ -40,6 +40,6 @@ function (string $mixin, string $pattern) use ($upgrader, $io, &$previewChanges)
throw new \RuntimeException('User stopped upgrade');
}

$upgrader->addMixins($mixins);
$gen->addMixins($mixins);

};
10 changes: 5 additions & 5 deletions upgrades/23.02.0.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* Upgrade hook_civicrm_entityTypes to use mixin
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {

$prefix = $upgrader->infoXml->getFile();
$prefix = $gen->infoXml->getFile();

if (is_dir($upgrader->baseDir->string('xml/schema/CRM'))) {
if (is_dir($gen->baseDir->string('xml/schema/CRM'))) {
\Civix::io()->note([
'Civix 23.02 removes `*_civix_civicrm_entityTypes` in favor of a mixin `[email protected]`.',
'This reduces code-duplication and will enable easier updates in the future.',
Expand All @@ -17,10 +17,10 @@
throw new \RuntimeException('User stopped upgrade');
}

$upgrader->addMixins(['[email protected]']);
$gen->addMixins(['[email protected]']);
}

$upgrader->removeHookDelegation([
$gen->removeHookDelegation([
"_{$prefix}_civix_civicrm_entityTypes",
]);

Expand Down
4 changes: 2 additions & 2 deletions upgrades/23.02.1.up.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* However, as older extensions adopt newer technologies (like `Civi\Api4`), it helps
* to add a similar to them.
*/
return function (\CRM\CivixBundle\Generator $upgrader) {
return function (\CRM\CivixBundle\Generator $gen) {

$upgrader->updateInfo(function (\CRM\CivixBundle\Builder\Info $info) use ($upgrader) {
$gen->updateInfo(function (\CRM\CivixBundle\Builder\Info $info) use ($gen) {
/* @var \Symfony\Component\Console\Style\SymfonyStyle $io */
$io = \Civix::io();

Expand Down

0 comments on commit 0256e69

Please sign in to comment.