2aa7af27c8a419f352613d4c06f67702bd8907f5
[yaffs-website] / vendor / drupal / console-core / src / Utils / DrupalFinder.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Core\Utils\DrupalFinder.
6  */
7
8 namespace Drupal\Console\Core\Utils;
9
10 use DrupalFinder\DrupalFinder as DrupalFinderBase;
11 use Webmozart\PathUtil\Path;
12
13 /**
14  * Class DrupalFinder
15  *
16  * @package Drupal\Console\Core\Utils
17  */
18 class DrupalFinder extends DrupalFinderBase
19 {
20
21     /**
22      * @var string
23      */
24     protected $consoleCorePath;
25
26     /**
27      * @var string
28      */
29     protected $consolePath;
30
31     /**
32      * @var string
33      */
34     protected $consoleLanguagePath;
35
36     public function locateRoot($start_path)
37     {
38         $vendorDir = 'vendor';
39         if (parent::locateRoot($start_path)) {
40             $vendorDir = Path::makeRelative(
41                 $this->getVendorDir(),
42                 $this->getComposerRoot()
43             );
44
45             $this->definePaths($vendorDir);
46             $this->defineConstants($vendorDir);
47
48             return true;
49         }
50
51         $this->definePaths($vendorDir);
52         $this->defineConstants($vendorDir);
53
54         return false;
55     }
56
57     protected function definePaths($vendorDir)
58     {
59         $this->consoleCorePath = "/{$vendorDir}/drupal/console-core/";
60         $this->consolePath = "/{$vendorDir}/drupal/console/";
61         $this->consoleLanguagePath = "/{$vendorDir}/drupal/console-%s/translations/";
62     }
63
64     protected function defineConstants($vendorDir)
65     {
66         if (!defined("DRUPAL_CONSOLE_CORE")) {
67             define(
68                 "DRUPAL_CONSOLE_CORE",
69                 "/{$vendorDir}/drupal/console-core/"
70             );
71         }
72         if (!defined("DRUPAL_CONSOLE")) {
73             define("DRUPAL_CONSOLE", "/{$vendorDir}/drupal/console/");
74         }
75         if (!defined("DRUPAL_CONSOLE_LANGUAGE")) {
76             define(
77                 "DRUPAL_CONSOLE_LANGUAGE",
78                 "/{$vendorDir}/drupal/console-%s/translations/"
79             );
80         }
81
82         if (!defined("DRUPAL_CONSOLE_LIBRARY")) {
83             define(
84                 "DRUPAL_CONSOLE_LIBRARY",
85                 "/{$vendorDir}/drupal/%s/console/translations/%s"
86             );
87         }
88     }
89
90     /**
91      * @return string
92      */
93     public function getConsoleCorePath()
94     {
95         return $this->consoleCorePath;
96     }
97
98     /**
99      * @return string
100      */
101     public function getConsolePath()
102     {
103         return $this->consolePath;
104     }
105
106     /**
107      * @return string
108      */
109     public function getConsoleLanguagePath()
110     {
111         return $this->consoleLanguagePath;
112     }
113
114     public function isValidDrupal() {
115         return ($this->getComposerRoot() && $this->getDrupalRoot());
116     }
117 }