Added the Search API Synonym module to deal specifically with licence and license...
[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\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 DrupliconCommand
19  *
20  * @package Drupal\Console\Core\Command\Exclude
21  */
22 class DrupliconCommand 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      * DrupliconCommand constructor.
41      *
42      * @param string               $appRoot
43      * @param TwigRenderer         $renderer
44      * @param ConfigurationManager $configurationManager
45      */
46     public function __construct(
47         $appRoot,
48         TwigRenderer $renderer,
49         ConfigurationManager $configurationManager
50     ) {
51         $this->appRoot = $appRoot;
52         $this->renderer = $renderer;
53         $this->configurationManager = $configurationManager;
54         parent::__construct();
55     }
56
57     /**
58      * {@inheritdoc}
59      */
60     protected function configure()
61     {
62         $this
63             ->setName('druplicon')
64             ->setDescription($this->trans('application.commands.druplicon.description'));
65     }
66
67     /**
68      * {@inheritdoc}
69      */
70     protected function execute(InputInterface $input, OutputInterface $output)
71     {
72         $directory = sprintf(
73             '%s/templates/core/druplicon/',
74             $this->configurationManager->getVendorCoreRoot()
75         );
76
77         $finder = new Finder();
78         $finder->files()
79             ->name('*.twig')
80             ->in($directory);
81
82         $templates = [];
83         foreach ($finder as $template) {
84             $templates[] = $template->getRelativePathname();
85         }
86
87         $druplicon = $this->renderer->render(
88             sprintf(
89                 'core/druplicon/%s',
90                 $templates[array_rand($templates)]
91             )
92         );
93
94         $this->getIo()->writeln($druplicon);
95         return 0;
96     }
97 }