Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Command / Shared / CommandTrait.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Core\Command\Shared\CommandTrait.
6  */
7
8 namespace Drupal\Console\Core\Command\Shared;
9
10 use Drupal\Console\Core\Utils\TranslatorManagerInterface;
11
12 /**
13  * Class CommandTrait
14  *
15  * @package Drupal\Console\Core\Command
16  */
17 trait CommandTrait
18 {
19     /**
20      * @var TranslatorManagerInterface
21      */
22     protected $translator;
23
24     /**
25      * @param $translator
26      */
27     public function setTranslator($translator)
28     {
29         $this->translator = $translator;
30     }
31
32     /**
33      * @param $key string
34      *
35      * @return string
36      */
37     public function trans($key)
38     {
39         if (!$this->translator) {
40             return $key;
41         }
42
43         return $this->translator->trans($key);
44     }
45
46     /**
47      * @inheritdoc
48      */
49     public function getDescription()
50     {
51         $description = sprintf(
52             'commands.%s.description',
53             str_replace(':', '.', $this->getName())
54         );
55
56         if (parent::getDescription()==$description) {
57             return $this->trans($description);
58         }
59
60         return parent::getDescription();
61     }
62
63     /**
64    * @inheritdoc
65    */
66     public function getHelp()
67     {
68         $help = sprintf(
69             'commands.%s.help',
70             str_replace(':', '.', $this->getName())
71         );
72
73         if (parent::getHelp()==$help) {
74             return $this->trans($help);
75         }
76
77         return parent::getHelp();
78     }
79 }