0afc814903f9423482a98fc9164a1422ef205071
[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\Console\Command\Command;
13 use Symfony\Component\Finder\Finder;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Console\Core\Utils\TwigRenderer;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 /**
19  * Class ElephpantCommand
20  * @package Drupal\Console\Core\Command\Exclude
21  */
22 class ElephpantCommand extends Command
23 {
24     use CommandTrait;
25
26     /**
27      * @var string
28      */
29     protected $appRoot;
30
31     /**
32      * @var TwigRenderer
33      */
34     protected $renderer;
35
36     /**
37      * DrupliconCommand constructor.
38      * @param string       $appRoot
39      * @param TwigRenderer $renderer
40      */
41     public function __construct(
42         $appRoot,
43         TwigRenderer $renderer
44     ) {
45         $this->appRoot = $appRoot;
46         $this->renderer = $renderer;
47         parent::__construct();
48     }
49
50     /**
51      * {@inheritdoc}
52      */
53     protected function configure()
54     {
55         $this
56             ->setName('elephpant')
57             ->setDescription($this->trans('application.commands.elephpant.description'));
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     protected function execute(InputInterface $input, OutputInterface $output)
64     {
65         $io = new DrupalStyle($input, $output);
66
67         $directory = sprintf(
68             '%stemplates/core/elephpant/',
69             $this->appRoot . DRUPAL_CONSOLE_CORE
70         );
71
72         $finder = new Finder();
73         $finder->files()
74             ->name('*.twig')
75             ->in($directory);
76
77         $templates = [];
78
79         foreach ($finder as $template) {
80             $templates[] = $template->getRelativePathname();
81         }
82
83         $elephpant = $this->renderer->render(
84             sprintf(
85                 'core/elephpant/%s',
86                 $templates[array_rand($templates)]
87             )
88         );
89
90         $io->writeln($elephpant);
91         return 0;
92     }
93 }