a8650e2d619249afd76c9283f91e67df3577ace8
[yaffs-website] / vendor / drupal / console-core / src / EventSubscriber / ShowGenerateCountCodeLinesListener.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\EventSubscriber\ShowGenerateCountCodeLinesListener.
6  */
7
8 namespace Drupal\Console\Core\EventSubscriber;
9
10 use Symfony\Component\Console\ConsoleEvents;
11 use Symfony\Component\Console\Event\ConsoleTerminateEvent;
12 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Utils\TranslatorManagerInterface;
15 use Drupal\Console\Core\Utils\CountCodeLines;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 /**
19  * Class ShowGenerateCountCodeLinesListener
20  *
21  * @package Drupal\Console\Core\EventSubscriber
22  */
23 class ShowGenerateCountCodeLinesListener implements EventSubscriberInterface
24 {
25
26     /**
27      * @var ShowGenerateChainListener
28      */
29     protected $countCodeLines;
30
31     /**
32      * @var TranslatorManagerInterface
33      */
34     protected $translator;
35
36     /**
37      * ShowGenerateChainListener constructor.
38      *
39      * @param TranslatorManagerInterface $translator
40      *
41      * @param CountCodeLines             $countCodeLines
42      */
43     public function __construct(
44         TranslatorManagerInterface $translator,
45         CountCodeLines $countCodeLines
46     ) {
47         $this->translator = $translator;
48         $this->countCodeLines = $countCodeLines;
49     }
50
51     /**
52      * @param ConsoleTerminateEvent $event
53      */
54     public function showGenerateCountCodeLines(ConsoleTerminateEvent $event)
55     {
56         if ($event->getExitCode() != 0) {
57             return;
58         }
59
60         /* @var DrupalStyle $io */
61         $io = new DrupalStyle($event->getInput(), $event->getOutput());
62
63         $countCodeLines = $this->countCodeLines->getCountCodeLines();
64         if ($countCodeLines > 0) {
65             $io->commentBlock(
66                 sprintf(
67                     $this->translator->trans('application.messages.lines-code'),
68                     $countCodeLines
69                 )
70             );
71         }
72     }
73
74     /**
75      * @{@inheritdoc}
76      */
77     public static function getSubscribedEvents()
78     {
79         return [ConsoleEvents::TERMINATE => 'showGenerateCountCodeLines'];
80     }
81 }