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