5 use Consolidation\AnnotatedCommand\Hooks\InitializeHookInterface;
6 use Symfony\Component\Console\Input\InputInterface;
7 use Consolidation\AnnotatedCommand\AnnotationData;
10 * The BootstrapHook is installed as an init hook that runs before
11 * all commands. If there is a `@bootstrap` annotation, then we will
12 * bootstrap Drupal to the requested phase.
14 class BootstrapHook implements InitializeHookInterface
16 protected $bootstrapManager;
18 public function __construct(BootstrapManager $bootstrapManager)
20 $this->bootstrapManager = $bootstrapManager;
23 public function initialize(InputInterface $input, AnnotationData $annotationData)
25 // Get the @bootstrap annotation. If there isn't one, then assume NONE.
26 $phase_long = $annotationData->get('bootstrap', 'none');
27 $phase = current(explode(' ', $phase_long));
28 $bootstrap_successful = $this->bootstrapManager->bootstrapToPhase($phase, $annotationData);
30 if (!$bootstrap_successful) {
31 // TODO: better exception class, better exception method
32 throw new \Exception('Bootstrap failed.');