Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Command / Debug / ChainCommand.php
diff --git a/vendor/drupal/console-core/src/Command/Debug/ChainCommand.php b/vendor/drupal/console-core/src/Command/Debug/ChainCommand.php
new file mode 100644 (file)
index 0000000..d0f0e23
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Console\Core\Command\Debug\ChainCommand.
+ */
+
+namespace Drupal\Console\Core\Command\Debug;
+
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Drupal\Console\Core\Command\Command;
+use Drupal\Console\Core\Utils\ChainDiscovery;
+
+/**
+ * Class ChainCommand
+ *
+ * @package Drupal\Console\Core\Command\Debug
+ */
+class ChainCommand extends Command
+{
+    /**
+     * @var ChainDiscovery
+     */
+    protected $chainDiscovery;
+
+    /**
+     * ChainCommand constructor.
+     *
+     * @param ChainDiscovery $chainDiscovery
+     */
+    public function __construct(
+        ChainDiscovery $chainDiscovery
+    ) {
+        $this->chainDiscovery = $chainDiscovery;
+
+        parent::__construct();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function configure()
+    {
+        $this
+            ->setName('debug:chain')
+            ->setDescription($this->trans('commands.debug.chain.description'))
+            ->setAliases(['dch']);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $files = $this->chainDiscovery->getFiles();
+        $filesPerDirectory = $this->chainDiscovery->getFilesPerDirectory();
+
+        if (!$files || !$filesPerDirectory) {
+            $this->getIo()->warning($this->trans('commands.debug.chain.messages.no-files'));
+
+            return 0;
+        }
+
+        foreach ($filesPerDirectory as $directory => $fileNames) {
+            $this->getIo()->info(' ' . $this->trans('commands.debug.chain.messages.directory'), false);
+            $this->getIo()->comment($directory);
+
+            $tableHeader = [
+                $this->trans('commands.debug.chain.messages.file'),
+                $this->trans('commands.debug.chain.messages.command')
+            ];
+
+            $tableRows = [];
+            foreach ($fileNames as $file) {
+                $commandName = '';
+                if (array_key_exists('command', $files[$directory.$file])) {
+                    $commandName = $files[$directory.$file]['command'];
+                }
+                $tableRows[] = [
+                    'file'  => $file,
+                    'command' => $commandName
+                ];
+            }
+
+            $this->getIo()->table($tableHeader, $tableRows);
+        }
+
+        return 0;
+    }
+}