0028bb1a565516a6939cd11679c0681298b5cf3e
[yaffs-website] / vendor / drupal / console / src / Command / Develop / ExampleContainerAwareCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Develop\ExampleContainerAwareCommand.
6  */
7
8 namespace Drupal\Console\Command\Develop;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Console\Core\Style\DrupalStyle;
15
16 /**
17  * Class ExampleContainerAwareCommand
18  *
19  * @package Drupal\Console\Command\Develop
20  */
21 class ExampleContainerAwareCommand extends Command
22 {
23     use CommandTrait;
24
25     /**
26      * ExampleContainerAwareCommand constructor.
27      */
28     public function __construct()
29     {
30         parent::__construct();
31     }
32
33     /**
34      * {@inheritdoc}
35      */
36     protected function configure()
37     {
38         $this->setName('develop:example:container:aware');
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     protected function interact(InputInterface $input, OutputInterface $output)
45     {
46     }
47
48     /**
49      * {@inheritdoc}
50      */
51     protected function execute(InputInterface $input, OutputInterface $output)
52     {
53         /* Register your command as a service
54          *
55          * Make sure you register your command class at
56          * config/services/namespace.yml file and add the `drupal.command` tag.
57          *
58          * develop_example_container_aware:
59          *   class: Drupal\Console\Command\Develop\ExampleContainerAwareCommand
60          *   tags:
61          *     - { name: drupal.command }
62          *
63          * NOTE: Make the proper changes on the namespace and class
64          *       according your new command.
65          *
66          * DrupalConsole extends the SymfonyStyle class to provide
67          * an standardized Output Formatting Style.
68          *
69          * Drupal Console provides the DrupalStyle helper class:
70          */
71         $io = new DrupalStyle($input, $output);
72         $io->simple('This text could be translatable by');
73         $io->simple('adding a YAML file at "config/translations/LANGUAGE/command.name.yml"');
74
75         /**
76          *  By using ContainerAwareCommandTrait on your class for the command
77          *  (instead of the more basic CommandTrait), you have access to
78          *  the service container.
79          *
80          *  In other words, you can access to any configured Drupal service
81          *  using the provided get method.
82          *
83          *  $this->get('entity_type.manager');
84          *
85          *  Reading user input argument
86          *  $input->getArgument('ARGUMENT_NAME');
87          *
88          *  Reading user input option
89          *  $input->getOption('OPTION_NAME');
90          */
91     }
92 }