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