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