f6fc7e44ca6e98a1ce1de2fa93c2cf51271bd762
[yaffs-website] / vendor / drush / drush / src / Boot / BootstrapHook.php
1 <?php
2
3 namespace Drush\Boot;
4
5 use Consolidation\AnnotatedCommand\Hooks\InitializeHookInterface;
6 use Symfony\Component\Console\Input\InputInterface;
7 use Consolidation\AnnotatedCommand\AnnotationData;
8
9 /**
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.
13  */
14 class BootstrapHook implements InitializeHookInterface
15 {
16     protected $bootstrapManager;
17
18     public function __construct(BootstrapManager $bootstrapManager)
19     {
20         $this->bootstrapManager = $bootstrapManager;
21     }
22
23     public function initialize(InputInterface $input, AnnotationData $annotationData)
24     {
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);
29
30         if (!$bootstrap_successful) {
31             // TODO: better exception class, better exception method
32             throw new \Exception('Bootstrap failed.');
33         }
34     }
35 }