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