05501731ebbd6ab57dcf3a7a172bf012e100eb72
[yaffs-website] / vendor / drupal / console / src / Command / Theme / PathCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Theme\PathCommand.
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\Extension\Manager;
16 use Drupal\Core\Extension\ThemeHandler;
17
18 class PathCommand extends Command
19 {
20     /**
21      * @var Manager
22      */
23     protected $extensionManager;
24
25     /**
26      * @var ThemeHandler
27      */
28     protected $themeHandler;
29
30     /**
31      * PathCommand constructor.
32      *
33      * @param Manager      $extensionManager
34      * @param ThemeHandler $themeHandler
35      */
36     public function __construct(Manager $extensionManager, ThemeHandler $themeHandler)
37     {
38         $this->extensionManager = $extensionManager;
39         $this->themeHandler = $themeHandler;
40         parent::__construct();
41     }
42
43     protected function configure()
44     {
45         $this
46             ->setName('theme:path')
47             ->setDescription($this->trans('commands.theme.path.description'))
48             ->addArgument(
49                 'theme',
50                 InputArgument::REQUIRED,
51                 $this->trans('commands.theme.path.arguments.theme')
52             )
53             ->addOption(
54                 'absolute',
55                 null,
56                 InputOption::VALUE_NONE,
57                 $this->trans('commands.theme.path.options.absolute')
58             )->setAliases(['thp']);
59     }
60
61     protected function execute(InputInterface $input, OutputInterface $output)
62     {
63         $theme = $input->getArgument('theme');
64
65         $fullPath = $input->getOption('absolute');
66
67         if (!in_array($theme, $this->getThemeList())) {
68             $this->getIo()->error(
69                 sprintf(
70                     $this->trans('commands.theme.path.messages.invalid-theme-name'),
71                     $theme
72                 )
73             );
74             return;
75         }
76         $theme = $this->extensionManager->getTheme($theme);
77
78         $this->getIo()->info(
79             $theme->getPath($fullPath)
80         );
81     }
82
83     /**
84      * {@inheritdoc}
85      */
86     protected function interact(InputInterface $input, OutputInterface $output)
87     {
88         // --theme argument
89         $theme = $input->getArgument('theme');
90         if (!$theme) {
91             $theme = $this->getIo()->choiceNoList(
92                 $this->trans('commands.theme.path.arguments.theme'),
93                 $this->getThemeList()
94             );
95             $input->setArgument('theme', $theme);
96         }
97     }
98
99     protected function getThemeList()
100     {
101         return array_keys($this->themeHandler->rebuildThemeData());
102     }
103 }