Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Utils / DrupalFinder.php
index 1619bf9cf08f20cc5aac97ea2c9eb9ddcbd346c0..2aa7af27c8a419f352613d4c06f67702bd8907f5 100644 (file)
@@ -8,6 +8,7 @@
 namespace Drupal\Console\Core\Utils;
 
 use DrupalFinder\DrupalFinder as DrupalFinderBase;
+use Webmozart\PathUtil\Path;
 
 /**
  * Class DrupalFinder
@@ -16,32 +17,101 @@ use DrupalFinder\DrupalFinder as DrupalFinderBase;
  */
 class DrupalFinder extends DrupalFinderBase
 {
+
+    /**
+     * @var string
+     */
+    protected $consoleCorePath;
+
+    /**
+     * @var string
+     */
+    protected $consolePath;
+
+    /**
+     * @var string
+     */
+    protected $consoleLanguagePath;
+
     public function locateRoot($start_path)
     {
+        $vendorDir = 'vendor';
         if (parent::locateRoot($start_path)) {
-            $composerRoot = $this->getComposerRoot();
-            $vendorDir = str_replace(
-                $composerRoot .'/', '', $this->getVendorDir()
+            $vendorDir = Path::makeRelative(
+                $this->getVendorDir(),
+                $this->getComposerRoot()
             );
-            if (!defined("DRUPAL_CONSOLE_CORE")) {
-                define(
-                    "DRUPAL_CONSOLE_CORE",
-                    "/{$vendorDir}/drupal/console-core/"
-                );
-            }
-            if (!defined("DRUPAL_CONSOLE")) {
-                define("DRUPAL_CONSOLE", "/{$vendorDir}/drupal/console/");
-            }
-            if (!defined("DRUPAL_CONSOLE_LANGUAGE")) {
-                define(
-                    "DRUPAL_CONSOLE_LANGUAGE",
-                    "/{$vendorDir}/drupal/console-%s/translations/"
-                );
-            }
+
+            $this->definePaths($vendorDir);
+            $this->defineConstants($vendorDir);
 
             return true;
         }
 
+        $this->definePaths($vendorDir);
+        $this->defineConstants($vendorDir);
+
         return false;
     }
+
+    protected function definePaths($vendorDir)
+    {
+        $this->consoleCorePath = "/{$vendorDir}/drupal/console-core/";
+        $this->consolePath = "/{$vendorDir}/drupal/console/";
+        $this->consoleLanguagePath = "/{$vendorDir}/drupal/console-%s/translations/";
+    }
+
+    protected function defineConstants($vendorDir)
+    {
+        if (!defined("DRUPAL_CONSOLE_CORE")) {
+            define(
+                "DRUPAL_CONSOLE_CORE",
+                "/{$vendorDir}/drupal/console-core/"
+            );
+        }
+        if (!defined("DRUPAL_CONSOLE")) {
+            define("DRUPAL_CONSOLE", "/{$vendorDir}/drupal/console/");
+        }
+        if (!defined("DRUPAL_CONSOLE_LANGUAGE")) {
+            define(
+                "DRUPAL_CONSOLE_LANGUAGE",
+                "/{$vendorDir}/drupal/console-%s/translations/"
+            );
+        }
+
+        if (!defined("DRUPAL_CONSOLE_LIBRARY")) {
+            define(
+                "DRUPAL_CONSOLE_LIBRARY",
+                "/{$vendorDir}/drupal/%s/console/translations/%s"
+            );
+        }
+    }
+
+    /**
+     * @return string
+     */
+    public function getConsoleCorePath()
+    {
+        return $this->consoleCorePath;
+    }
+
+    /**
+     * @return string
+     */
+    public function getConsolePath()
+    {
+        return $this->consolePath;
+    }
+
+    /**
+     * @return string
+     */
+    public function getConsoleLanguagePath()
+    {
+        return $this->consoleLanguagePath;
+    }
+
+    public function isValidDrupal() {
+        return ($this->getComposerRoot() && $this->getDrupalRoot());
+    }
 }