Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / src / Config / DrushConfig.php
1 <?php
2 namespace Drush\Config;
3
4 use Consolidation\Config\Util\ConfigOverlay;
5 use Symfony\Component\Filesystem\Exception\IOException;
6 use Symfony\Component\Filesystem\Filesystem;
7 use Webmozart\PathUtil\Path;
8
9 /**
10  * Accessors for common Drush config keys.
11  */
12 class DrushConfig extends ConfigOverlay
13 {
14     public function cwd()
15     {
16         return $this->get('env.cwd');
17     }
18
19     public function home()
20     {
21         return $this->get('env.home');
22     }
23
24     public function user()
25     {
26         return $this->get('env.user');
27     }
28
29     public function isWindows()
30     {
31         return $this->get('env.is-windows');
32     }
33
34     public function tmp()
35     {
36         return $this->get('env.tmp');
37     }
38
39     public function cache()
40     {
41         $candidates = [
42             $this->get('drush.paths.cache-directory'),
43             Path::join($this->home(), '.drush/cache'),
44             Path::join($this->tmp(), 'drush-' . $this->user() . '/cache'),
45         ];
46
47         $fs = new Filesystem();
48         foreach (array_filter($candidates) as $candidate) {
49             try {
50                 $fs->mkdir($candidate);
51                 return $candidate;
52             } catch (IOException $ioException) {
53                 // Do nothing. Jump to the next candidate.
54             }
55         }
56         throw new \Exception('Cannot create the Drush cache directory. Tried next candidates: ' . implode(', ', $candidates));
57     }
58 }