Skip to content

Commit

Permalink
(REF) Extract method CmsBootstrap::generate()
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Mar 9, 2023
1 parent 4c95d3d commit e5fc2a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/CmsBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ public function __construct($options = array()) {
$this->addOptions($options);
}

/**
* Export bootstrap logic.
*
* @param array $actions
* List of bootstrap actions to include.
* Ex: ['bootCms', 'bootCivi']
* @return string
* PHP code to `CmsBootstrap` in a new process
*/
public function generate(array $actions = []): string {
$instanceExpr = '\\' . get_class($this) . '::singleton()';
$code = '';
$code .= sprintf("require_once %s;\n", var_export(CV_AUTOLOAD, TRUE));
$code .= sprintf("%s->addOptions(%s);\n", $instanceExpr, var_export($this->getOptions(), TRUE));
foreach ($actions as $action) {
$code .= sprintf("%s->%s()->bootCivi();\n", $instanceExpr, $action);
}
return $code;
}

/**
* Bootstrap the CiviCRM runtime.
*
Expand Down
8 changes: 1 addition & 7 deletions src/Command/BootCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Civi\Cv\Command;

use Civi\Cv\CmsBootstrap;
use Civi\Cv\Util\BootTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -38,12 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
break;

case 'cms-full':
$instance = \Civi\Cv\CmsBootstrap::singleton();
$instanceExpr = '\\' . get_class($instance) . '::singleton()';
$code = '';
$code .= sprintf("require_once %s;\n", var_export(CV_AUTOLOAD, TRUE));
$code .= sprintf("%s->addOptions(%s);\n", $instanceExpr, var_export($instance->getOptions(), TRUE));
$code .= sprintf("%s->bootCms()->bootCivi();\n", $instanceExpr);
$code = \Civi\Cv\CmsBootstrap::singleton()->generate(['bootCms', 'bootCivi']);
break;

case 'none':
Expand Down

0 comments on commit e5fc2a5

Please sign in to comment.