Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Utils / Site.php
index 46fbc86cf8842b2d2d56d357304212f44c4a98a6..f3baffc058a16ad5cd222d72b794593835238126 100644 (file)
@@ -3,7 +3,6 @@
 namespace Drupal\Console\Utils;
 
 use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\Filesystem\Filesystem;
 use Symfony\Component\Finder\Finder;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Logger\LoggerChannelFactory;
@@ -27,7 +26,7 @@ class Site
     /**
      * @var string
      */
-    protected $cacheDirectory;
+    protected $cacheServicesFile;
 
     /**
      * Site constructor.
@@ -104,7 +103,7 @@ class Site
             if (file_exists($driver_folder->getRealpath() . '/Install/Tasks.php')) {
                 $driver  = $driver_folder->getBasename();
                 $installer = db_installer_object($driver);
-                // Verify is database is installable
+                // Verify if database is installable
                 if ($installer->installable()) {
                     $reflection = new \ReflectionClass($installer);
                     $install_namespace = $reflection->getNamespaceName();
@@ -203,72 +202,40 @@ class Site
         return false;
     }
 
-    public function getCacheDirectory()
+    public function getCachedServicesFile()
     {
-        if ($this->cacheDirectory) {
-            return $this->cacheDirectory;
-        }
-
-        $configFactory = \Drupal::configFactory();
-        $siteId = $configFactory->get('system.site')
-            ->get('uuid');
-        $pathTemporary = $configFactory->get('system.file')
-            ->get('path.temporary');
-        $configuration = $this->configurationManager->getConfiguration();
-        $cacheDirectory = $configuration->get('application.cache.directory')?:'';
-        if ($cacheDirectory) {
-            if (strpos($cacheDirectory, '/') != 0) {
-                $cacheDirectory = $this->configurationManager
-                    ->getApplicationDirectory() . '/' . $cacheDirectory;
-            }
-            $cacheDirectories[] = $cacheDirectory . '/' . $siteId . '/';
-        }
-        $cacheDirectories[] = sprintf(
-            '%s/cache/%s/',
-            $this->configurationManager->getConsoleDirectory(),
-            $siteId
-        );
-        $cacheDirectories[] = $pathTemporary . '/console/cache/' . $siteId . '/';
+        if (!$this->cacheServicesFile) {
+            $configFactory = \Drupal::configFactory();
+            $siteId = $configFactory->get('system.site')
+                ->get('uuid');
 
-        foreach ($cacheDirectories as $cacheDirectory) {
-            if ($this->isValidDirectory($cacheDirectory)) {
-                $this->cacheDirectory = $cacheDirectory;
-                break;
-            }
-        }
-
-        return $this->cacheDirectory;
-    }
-
-    private function isValidDirectory($path)
-    {
-        $fileSystem = new Filesystem();
-        if ($fileSystem->exists($path)) {
-            return true;
-        }
-        try {
-            $fileSystem->mkdir($path);
+            $directory = \Drupal::service('stream_wrapper.temporary')
+                ->getDirectoryPath();
 
-            return true;
-        } catch (\Exception $e) {
-            return false;
+            $this->cacheServicesFile = $directory . '/' . $siteId .
+                '-console.services.yml';
         }
-    }
 
-    public function cachedServicesFile()
-    {
-        return $this->getCacheDirectory().'/console.services.yml';
+        return $this->cacheServicesFile;
     }
 
     public function cachedServicesFileExists()
     {
-        return file_exists($this->cachedServicesFile());
+        return file_exists($this->getCachedServicesFile());
     }
 
     public function removeCachedServicesFile()
     {
         if ($this->cachedServicesFileExists()) {
-            unlink($this->cachedServicesFile());
+            unlink($this->getCachedServicesFile());
         }
     }
+
+    /**
+     * @param string $root
+     */
+    public function setRoot($root)
+    {
+        $this->root = $root;
+    }
 }