Updated to Drupal 8.5. Core Media not yet in use.
[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             Path::join($this->home(), '.drush/cache'),
43             Path::join($this->tmp(), 'drush-' . $this->user() . '/cache'),
44         ];
45
46         $fs = new Filesystem();
47         foreach ($candidates as $candidate) {
48             try {
49                 $fs->mkdir($candidate);
50                 return $candidate;
51             } catch (IOException $ioException) {
52                 // Do nothing. Jump to the next candidate.
53             }
54         }
55         throw new \Exception('Cannot create the Drush cache directory. Tried next candidates: ' . implode(', ', $candidates));
56     }
57 }