9e77211e99492473f54c283256741952c6720b62
[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 Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
16 use Drupal\Console\Utils\DrupalApi;
17 use GuzzleHttp\Client;
18
19 class DownloadCommand extends Command
20 {
21     use ProjectDownloadTrait;
22
23     /**
24      * @var DrupalApi
25      */
26     protected $drupalApi;
27
28     /**
29      * @var Client
30      */
31     protected $httpClient;
32
33     /**
34      * @var string
35      */
36     protected $appRoot;
37
38
39     /**
40      * DownloadCommand constructor.
41      *
42      * @param DrupalApi $drupalApi
43      * @param Client    $httpClient
44      * @param $appRoot
45      */
46     public function __construct(
47         DrupalApi $drupalApi,
48         Client $httpClient,
49         $appRoot
50     ) {
51         $this->drupalApi = $drupalApi;
52         $this->httpClient = $httpClient;
53         $this->appRoot = $appRoot;
54         parent::__construct();
55     }
56
57
58     /**
59      * {@inheritdoc}
60      */
61     protected function configure()
62     {
63         $this
64             ->setName('theme:download')
65             ->setDescription($this->trans('commands.theme.download.description'))
66             ->addArgument(
67                 'theme',
68                 InputArgument::REQUIRED,
69                 $this->trans('commands.theme.download.arguments.theme')
70             )
71             ->addArgument(
72                 'version',
73                 InputArgument::OPTIONAL,
74                 $this->trans('commands.theme.download.arguments.version')
75             )
76             ->addOption(
77                 'composer',
78                 null,
79                 InputOption::VALUE_NONE,
80                 $this->trans('commands.theme.download.options.composer')
81             )->setAliases(['thd']);
82     }
83
84     /**
85      * {@inheritdoc}
86      */
87     protected function execute(InputInterface $input, OutputInterface $output)
88     {
89         $theme = $input->getArgument('theme');
90         $version = $input->getArgument('version');
91         $composer = $input->getOption('composer');
92
93         if ($composer) {
94             if (!is_array($theme)) {
95                 $theme = [$theme];
96             }
97             $this->get('chain_queue')->addCommand(
98                 'module:download',
99                 [
100                 'module' => $theme,
101                 '--composer' => true
102                 ],
103                 true,
104                 true
105             );
106         } else {
107             $this->downloadProject($theme, $version, 'theme');
108         }
109     }
110
111     /**
112      * {@inheritdoc}
113      */
114     protected function interact(InputInterface $input, OutputInterface $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($theme);
122             $input->setArgument('version', $version);
123         }
124     }
125 }