Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Theme / DownloadCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Theme\DownloadCommand.
6  */
7
8 namespace Drupal\Console\Command\Theme;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
18 use Drupal\Console\Utils\DrupalApi;
19 use GuzzleHttp\Client;
20
21 class DownloadCommand extends Command
22 {
23     use ProjectDownloadTrait;
24     use CommandTrait;
25
26
27     /**
28      * @var DrupalApi
29      */
30     protected $drupalApi;
31
32     /**
33      * @var Client
34      */
35     protected $httpClient;
36
37     /**
38      * @var string
39      */
40     protected $appRoot;
41
42
43     /**
44      * DownloadCommand constructor.
45      *
46      * @param DrupalApi $drupalApi
47      * @param Client    $httpClient
48      * @param $appRoot
49      */
50     public function __construct(
51         DrupalApi $drupalApi,
52         Client $httpClient,
53         $appRoot
54     ) {
55         $this->drupalApi = $drupalApi;
56         $this->httpClient = $httpClient;
57         $this->appRoot = $appRoot;
58         parent::__construct();
59     }
60
61
62     /**
63      * {@inheritdoc}
64      */
65     protected function configure()
66     {
67         $this
68             ->setName('theme:download')
69             ->setDescription($this->trans('commands.theme.download.description'))
70             ->addArgument('theme', InputArgument::REQUIRED, $this->trans('commands.theme.download.arguments.theme'))
71             ->addArgument('version', InputArgument::OPTIONAL, $this->trans('commands.theme.download.arguments.version'))
72             ->addOption(
73                 'composer',
74                 null,
75                 InputOption::VALUE_NONE,
76                 $this->trans('commands.theme.download.options.composer')
77             );
78     }
79
80     /**
81      * {@inheritdoc}
82      */
83     protected function execute(InputInterface $input, OutputInterface $output)
84     {
85         $io = new DrupalStyle($input, $output);
86
87         $theme = $input->getArgument('theme');
88         $version = $input->getArgument('version');
89         $composer = $input->getOption('composer');
90
91         if ($composer) {
92             if (!is_array($theme)) {
93                 $theme = [$theme];
94             }
95             $this->get('chain_queue')->addCommand(
96                 'module:download',
97                 [
98                 'module' => $theme,
99                 '--composer' => true
100                 ],
101                 true,
102                 true
103             );
104         } else {
105             $this->downloadProject($io, $theme, $version, 'theme');
106         }
107     }
108
109     /**
110      * {@inheritdoc}
111      */
112     protected function interact(InputInterface $input, OutputInterface $output)
113     {
114         $io = new DrupalStyle($input, $output);
115
116         $theme = $input->getArgument('theme');
117         $version = $input->getArgument('version');
118         $composer = $input->getOption('composer');
119
120         if (!$version && !$composer) {
121             $version = $this->releasesQuestion($io, $theme);
122             $input->setArgument('version', $version);
123         }
124     }
125 }