Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Command / Exclude / ElephpantCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\Command\Exclude\ElephpantCommand.
6  */
7
8 namespace Drupal\Console\Core\Command\Exclude;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Finder\Finder;
13 use Drupal\Console\Core\Command\Command;
14 use Drupal\Console\Core\Utils\TwigRenderer;
15 use Drupal\Console\Core\Utils\ConfigurationManager;
16
17 /**
18  * Class ElephpantCommand
19  *
20  * @package Drupal\Console\Core\Command\Exclude
21  */
22 class ElephpantCommand extends Command
23 {
24     /**
25      * @var string
26      */
27     protected $appRoot;
28
29     /**
30      * @var TwigRenderer
31      */
32     protected $renderer;
33
34     /**
35      * @var ConfigurationManager
36      */
37     protected $configurationManager;
38
39
40     /**
41      * ElephpantCommand constructor.
42      *
43      * @param string               $appRoot
44      * @param TwigRenderer         $renderer
45      * @param ConfigurationManager $configurationManager
46      */
47     public function __construct(
48         $appRoot,
49         TwigRenderer $renderer,
50         ConfigurationManager $configurationManager
51     ) {
52         $this->appRoot = $appRoot;
53         $this->renderer = $renderer;
54         $this->configurationManager = $configurationManager;
55         parent::__construct();
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     protected function configure()
62     {
63         $this
64             ->setName('elephpant')
65             ->setDescription($this->trans('application.commands.elephpant.description'));
66     }
67
68     /**
69      * {@inheritdoc}
70      */
71     protected function execute(InputInterface $input, OutputInterface $output)
72     {
73         $directory = sprintf(
74             '%stemplates/core/elephpant/',
75             $this->configurationManager->getVendorCoreRoot()
76         );
77
78         $finder = new Finder();
79         $finder->files()
80             ->name('*.twig')
81             ->in($directory);
82
83         $templates = [];
84
85         foreach ($finder as $template) {
86             $templates[] = $template->getRelativePathname();
87         }
88
89         $elephpant = $this->renderer->render(
90             sprintf(
91                 'core/elephpant/%s',
92                 $templates[array_rand($templates)]
93             )
94         );
95
96         $this->getIo()->writeln($elephpant);
97         return 0;
98     }
99 }