16ad4f1d5c8ee635d8937424a7a9b3f422d55f2b
[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 Symfony\Component\DependencyInjection\ContainerBuilder;
11 use Symfony\Component\Config\FileLocator;
12 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
13
14 /**
15  * Class DrupalConsoleCore
16  *
17  * @package Drupal\Console\Core\Bootstrap
18  */
19 class DrupalConsoleCore
20 {
21     /**
22      * @var string
23      */
24     protected $root;
25
26     /**
27      * @var string
28      */
29     protected $appRoot;
30
31     /**
32      * DrupalConsole constructor.
33      *
34      * @param $root
35      * @param $appRoot
36      */
37     public function __construct($root, $appRoot = null)
38     {
39         $this->root = $root;
40         $this->appRoot = $appRoot;
41     }
42
43     /**
44      * @return ContainerBuilder
45      */
46     public function boot()
47     {
48         $container = new ContainerBuilder();
49         $loader = new YamlFileLoader($container, new FileLocator($this->root));
50
51         $servicesFiles = [
52             $this->root.DRUPAL_CONSOLE_CORE.'/services.yml',
53             $this->root.'/services.yml',
54             $this->root.DRUPAL_CONSOLE.'/uninstall.services.yml',
55             $this->root.DRUPAL_CONSOLE.'/extend.console.uninstall.services.yml'
56         ];
57
58         foreach ($servicesFiles as $servicesFile) {
59             if (file_exists($servicesFile)) {
60                 $loader->load($servicesFile);
61             }
62         }
63
64         $container->get('console.configuration_manager')
65             ->loadConfiguration($this->root)
66             ->getConfiguration();
67
68         $container->get('console.translator_manager')
69             ->loadCoreLanguage('en', $this->root);
70
71         $appRoot = $this->appRoot?$this->appRoot:$this->root;
72         $container->set(
73             'app.root',
74             $appRoot
75         );
76         $consoleRoot = $appRoot;
77         if (stripos($this->root, '/bin/') <= 0) {
78             $consoleRoot = $this->root;
79         }
80         $container->set(
81             'console.root',
82             $consoleRoot
83         );
84
85         $configurationManager = $container->get('console.configuration_manager');
86         $directory = $configurationManager->getConsoleDirectory() . 'extend/';
87         $autoloadFile = $directory . 'vendor/autoload.php';
88         if (is_file($autoloadFile)) {
89             include_once $autoloadFile;
90             $extendServicesFile = $directory . 'extend.console.uninstall.services.yml';
91             if (is_file($extendServicesFile)) {
92                 $loader->load($extendServicesFile);
93             }
94         }
95
96         $container->get('console.renderer')
97             ->setSkeletonDirs(
98                 [
99                     $this->root.'/templates/',
100                     $this->root.DRUPAL_CONSOLE_CORE.'/templates/'
101                 ]
102             );
103
104         return $container;
105     }
106 }