5 * Contains \Drupal\Console\Command\Libraries\DebugCommand.
8 namespace Drupal\Console\Command\Libraries;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\Extension\ModuleHandlerInterface;
15 use Drupal\Core\Extension\ThemeHandlerInterface;
16 use Drupal\Core\Asset\LibraryDiscoveryInterface;
17 use Drupal\Component\Serialization\Yaml;
18 use Drupal\Console\Core\Command\Shared\CommandTrait;
19 use Drupal\Console\Core\Style\DrupalStyle;
21 class DebugCommand extends Command
26 * @var ModuleHandlerInterface
28 protected $moduleHandler;
31 * @var ThemeHandlerInterface;
33 protected $themeHandler;
36 * @var LibraryDiscoveryInterface
38 protected $libraryDiscovery;
46 * DebugCommand constructor.
48 * @param ModuleHandlerInterface $moduleHandler
49 * @param ThemeHandlerInterface $themeHandler
50 * @param LibraryDiscoveryInterface $libraryDiscovery
51 * @param string $appRoot
53 public function __construct(
54 ModuleHandlerInterface $moduleHandler,
55 ThemeHandlerInterface $themeHandler,
56 LibraryDiscoveryInterface $libraryDiscovery,
59 $this->moduleHandler = $moduleHandler;
60 $this->themeHandler = $themeHandler;
61 $this->libraryDiscovery = $libraryDiscovery;
62 $this->appRoot = $appRoot;
63 parent::__construct();
69 protected function configure()
72 ->setName('libraries:debug')
73 ->setDescription($this->trans('commands.libraries.debug.description'))
76 InputArgument::OPTIONAL,
77 $this->trans('commands.libraries.debug.options.name')
84 protected function execute(InputInterface $input, OutputInterface $output)
86 $io = new DrupalStyle($input, $output);
87 $group = $input->getArgument('group');
90 $groups = $this->getAllLibraries();
93 $this->trans('commands.libraries.debug.messages.name'),
96 $io->table($tableHeader, $groups, 'compact');
98 $librariesData = $this->libraryDiscovery
99 ->getLibrariesByExtension($group);
101 foreach ($librariesData as $key => $libraries) {
103 $io->writeln(Yaml::encode($libraries));
108 private function getAllLibraries()
110 $modules = $this->moduleHandler->getModuleList();
111 $themes = $this->themeHandler->rebuildThemeData();
112 $extensions = array_merge($modules, $themes);
115 foreach ($extensions as $extensionName => $extension) {
116 $libraryFile = $extension->getPath() . '/' . $extensionName . '.libraries.yml';
117 if (is_file($this->appRoot . '/' . $libraryFile)) {
118 $libraries[$extensionName] = $this->libraryDiscovery->getLibrariesByExtension($extensionName);
122 return array_keys($libraries);