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