Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Breakpoints / DebugCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Breakpoints\DebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Breakpoints;
9
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\breakpoint\BreakpointManagerInterface;
15 use Symfony\Component\Yaml\Yaml;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Annotations\DrupalCommand;
18 use Drupal\Console\Core\Style\DrupalStyle;
19
20 /**
21  * @DrupalCommand(
22  *     extension = "breakpoint",
23  *     extensionType = "module"
24  * )
25  */
26 class DebugCommand extends Command
27 {
28     use CommandTrait;
29
30     /**
31      * @var BreakpointManagerInterface
32      */
33     protected $breakpointManager;
34
35     /**
36      * @var string
37      */
38     protected $appRoot;
39
40     /**
41      * DebugCommand constructor.
42      *
43      * @param BreakpointManagerInterface $breakpointManager
44      * @param string                     $appRoot
45      */
46     public function __construct(
47         BreakpointManagerInterface $breakpointManager,
48         $appRoot
49     ) {
50         $this->breakpointManager = $breakpointManager;
51         $this->appRoot = $appRoot;
52         parent::__construct();
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     protected function configure()
59     {
60         $this
61             ->setName('breakpoints:debug')
62             ->setDescription($this->trans('commands.breakpoints.debug.description'))
63             ->addArgument(
64                 'group',
65                 InputArgument::OPTIONAL,
66                 $this->trans('commands.breakpoints.debug.options.group-name')
67             );
68     }
69
70     /**
71      * {@inheritdoc}
72      */
73     protected function execute(InputInterface $input, OutputInterface $output)
74     {
75         $io = new DrupalStyle($input, $output);
76
77         $group = $input->getArgument('group');
78         if ($group) {
79             $breakPointData = $this->getBreakpointByName($group);
80             foreach ($breakPointData as $key => $breakPoint) {
81                 $io->comment($key, false);
82                 $io->block(Yaml::dump($breakPoint));
83             }
84
85             return 0;
86         }
87         $groups = array_keys($this->breakpointManager->getGroups());
88
89         $tableHeader = [
90             $this->trans('commands.breakpoints.debug.messages.name'),
91         ];
92
93         $io->table($tableHeader, $groups, 'compact');
94
95         return 0;
96     }
97
98     /**
99      * @param $group    String
100      * @return mixed
101      */
102     private function getBreakpointByName($group)
103     {
104         $typeExtension = implode(
105             ',',
106             array_values($this->breakpointManager->getGroupProviders($group))
107         );
108
109         $projectPath = drupal_get_path($typeExtension, $group);
110
111         $extensionFile = sprintf(
112             '%s/%s/%s.breakpoints.yml',
113             $this->appRoot,
114             $projectPath,
115             $group
116         );
117
118         return Yaml::parse(
119             file_get_contents($extensionFile)
120         );
121     }
122 }