Skip to content

Commit

Permalink
generate:entity - Conditional files? Conditional folders!
Browse files Browse the repository at this point in the history
If you're not making the file, then you don't need to make the folder...
  • Loading branch information
totten committed Sep 16, 2024
1 parent 23dd0a2 commit e459b65
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/CRM/CivixBundle/Command/AddEntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,21 @@ protected function execute(InputInterface $input, OutputInterface $output) {

$ext = new Collection();
$ext->builders['dirs'] = new Dirs([
dirname($ctx['apiFile']),
dirname($ctx['api4File']),
dirname($ctx['daoClassFile']),
dirname($ctx['baoClassFile']),
dirname($ctx['testApi3ClassFile']),
]);
$ext->builders['dirs']->save($ctx, $output);

$hasPhpUnit = FALSE;
if (in_array('3', $apiVersions)) {
$ext->builders['dirs']->addPath(dirname($ctx['apiFile']));
$ext->builders['api.php'] = new Template('entity-api.php.php', $ctx['apiFile'], FALSE, Civix::templating());
$ext->builders['dirs']->addPath(dirname($ctx['testApi3ClassFile']));
$ext->builders['test.php'] = new Template('entity-api3-test.php.php', $ctx['testApi3ClassFile'], FALSE, Civix::templating());
$hasPhpUnit = TRUE;
}
if (in_array('4', $apiVersions)) {
$ext->builders['dirs']->addPath(dirname($ctx['api4File']));
$ext->builders['api4.php'] = new Template('entity-api4.php.php', $ctx['api4File'], FALSE, Civix::templating());
}
$ext->builders['dao.php'] = new Template('entity-dao.php.php', $ctx['daoClassFile'], FALSE, Civix::templating());
Expand All @@ -124,11 +126,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$ext->builders['entityType.php']->set($entityDefn);
}

Civix::generator()->addPhpunit();

$ext->init($ctx);
$ext->save($ctx, $output);

if ($hasPhpUnit) {
Civix::generator()->addPhpunit();
}

Civix::generator()->updateModuleCivixPhp();

if (count($apiVersions) >= 2) {
Expand Down

0 comments on commit e459b65

Please sign in to comment.