Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Bootstrap / DrupalConsoleCore.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\Bootstrap.
6  */
7
8 namespace Drupal\Console\Core\Bootstrap;
9
10 use Drupal\Console\Core\Utils\DrupalFinder;
11 use Symfony\Component\DependencyInjection\ContainerBuilder;
12 use Symfony\Component\Config\FileLocator;
13 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
14
15 /**
16  * Class DrupalConsoleCore
17  *
18  * @package Drupal\Console\Core\Bootstrap
19  */
20 class DrupalConsoleCore
21 {
22     /**
23      * @var string
24      */
25     protected $root;
26
27     /**
28      * @var string
29      */
30     protected $appRoot;
31
32     /**
33      * @var DrupalFinder
34      */
35     protected $drupalFinder;
36
37     /**
38      * DrupalConsole constructor.
39      *
40      * @param string       $root
41      * @param string       $appRoot
42      * @param DrupalFinder $drupalFinder
43      */
44     public function __construct(
45         $root,
46         $appRoot = null,
47         DrupalFinder $drupalFinder
48     ) {
49         $this->root = $root;
50         $this->appRoot = $appRoot;
51         $this->drupalFinder = $drupalFinder;
52     }
53
54     /**
55      * @return ContainerBuilder
56      */
57     public function boot()
58     {
59         $container = new ContainerBuilder();
60         $loader = new YamlFileLoader($container, new FileLocator($this->root));
61
62         if (substr($this->root, -1) === DIRECTORY_SEPARATOR) {
63             $this->root = substr($this->root, 0, -1);
64         }
65
66         $servicesFiles = [
67             $this->root.DRUPAL_CONSOLE_CORE.'services.yml',
68             $this->root.'/services.yml',
69             $this->root.DRUPAL_CONSOLE.'uninstall.services.yml',
70             $this->root.DRUPAL_CONSOLE.'extend.console.uninstall.services.yml'
71         ];
72
73         foreach ($servicesFiles as $servicesFile) {
74             if (file_exists($servicesFile)) {
75                 $loader->load($servicesFile);
76             }
77         }
78
79         $container->get('console.configuration_manager')
80             ->loadConfiguration($this->root)
81             ->getConfiguration();
82
83         $container->get('console.translator_manager')
84             ->loadCoreLanguage('en', $this->root);
85
86         $appRoot = $this->appRoot?$this->appRoot:$this->root;
87         $container->set(
88             'app.root',
89             $appRoot
90         );
91         $consoleRoot = $appRoot;
92         if (stripos($this->root, '/bin/') <= 0) {
93             $consoleRoot = $this->root;
94         }
95         $container->set(
96             'console.root',
97             $consoleRoot
98         );
99
100         $container->set(
101             'console.drupal_finder',
102             $this->drupalFinder
103         );
104
105         $configurationManager = $container->get('console.configuration_manager');
106         $directory = $configurationManager->getConsoleDirectory() . 'extend/';
107         $autoloadFile = $directory . 'vendor/autoload.php';
108         if (is_file($autoloadFile)) {
109             include_once $autoloadFile;
110             $extendServicesFile = $directory . 'extend.console.uninstall.services.yml';
111             if (is_file($extendServicesFile)) {
112                 $loader->load($extendServicesFile);
113             }
114         }
115
116         $container->get('console.renderer')
117             ->setSkeletonDirs(
118                 [
119                     $this->root.'/templates/',
120                     $this->root.DRUPAL_CONSOLE_CORE.'/templates/'
121                 ]
122             );
123
124         return $container;
125     }
126 }