comparison vendor/symfony/console/Command/Command.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children c2387f117808
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
27 * 27 *
28 * @author Fabien Potencier <fabien@symfony.com> 28 * @author Fabien Potencier <fabien@symfony.com>
29 */ 29 */
30 class Command 30 class Command
31 { 31 {
32 /**
33 * @var string|null The default command name
34 */
35 protected static $defaultName;
36
32 private $application; 37 private $application;
33 private $name; 38 private $name;
34 private $processTitle; 39 private $processTitle;
35 private $aliases = array(); 40 private $aliases = array();
36 private $definition; 41 private $definition;
44 private $synopsis = array(); 49 private $synopsis = array();
45 private $usages = array(); 50 private $usages = array();
46 private $helperSet; 51 private $helperSet;
47 52
48 /** 53 /**
49 * Constructor. 54 * @return string|null The default command name or null when no default name is set
50 * 55 */
56 public static function getDefaultName()
57 {
58 $class = get_called_class();
59 $r = new \ReflectionProperty($class, 'defaultName');
60
61 return $class === $r->class ? static::$defaultName : null;
62 }
63
64 /**
51 * @param string|null $name The name of the command; passing null means it must be set in configure() 65 * @param string|null $name The name of the command; passing null means it must be set in configure()
52 * 66 *
53 * @throws LogicException When the command name is empty 67 * @throws LogicException When the command name is empty
54 */ 68 */
55 public function __construct($name = null) 69 public function __construct($name = null)
56 { 70 {
57 $this->definition = new InputDefinition(); 71 $this->definition = new InputDefinition();
58 72
59 if (null !== $name) { 73 if (null !== $name || null !== $name = static::getDefaultName()) {
60 $this->setName($name); 74 $this->setName($name);
61 } 75 }
62 76
63 $this->configure(); 77 $this->configure();
64
65 if (!$this->name) {
66 throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this)));
67 }
68 } 78 }
69 79
70 /** 80 /**
71 * Ignores validation errors. 81 * Ignores validation errors.
72 * 82 *
75 public function ignoreValidationErrors() 85 public function ignoreValidationErrors()
76 { 86 {
77 $this->ignoreValidationErrors = true; 87 $this->ignoreValidationErrors = true;
78 } 88 }
79 89
80 /**
81 * Sets the application instance for this command.
82 *
83 * @param Application $application An Application instance
84 */
85 public function setApplication(Application $application = null) 90 public function setApplication(Application $application = null)
86 { 91 {
87 $this->application = $application; 92 $this->application = $application;
88 if ($application) { 93 if ($application) {
89 $this->setHelperSet($application->getHelperSet()); 94 $this->setHelperSet($application->getHelperSet());
90 } else { 95 } else {
91 $this->helperSet = null; 96 $this->helperSet = null;
92 } 97 }
93 } 98 }
94 99
95 /**
96 * Sets the helper set.
97 *
98 * @param HelperSet $helperSet A HelperSet instance
99 */
100 public function setHelperSet(HelperSet $helperSet) 100 public function setHelperSet(HelperSet $helperSet)
101 { 101 {
102 $this->helperSet = $helperSet; 102 $this->helperSet = $helperSet;
103 } 103 }
104 104
148 * This method is not abstract because you can use this class 148 * This method is not abstract because you can use this class
149 * as a concrete class. In this case, instead of defining the 149 * as a concrete class. In this case, instead of defining the
150 * execute() method, you set the code to execute by passing 150 * execute() method, you set the code to execute by passing
151 * a Closure to the setCode() method. 151 * a Closure to the setCode() method.
152 * 152 *
153 * @param InputInterface $input An InputInterface instance
154 * @param OutputInterface $output An OutputInterface instance
155 *
156 * @return null|int null or 0 if everything went fine, or an error code 153 * @return null|int null or 0 if everything went fine, or an error code
157 * 154 *
158 * @throws LogicException When this abstract method is not implemented 155 * @throws LogicException When this abstract method is not implemented
159 * 156 *
160 * @see setCode() 157 * @see setCode()
168 * Interacts with the user. 165 * Interacts with the user.
169 * 166 *
170 * This method is executed before the InputDefinition is validated. 167 * This method is executed before the InputDefinition is validated.
171 * This means that this is the only place where the command can 168 * This means that this is the only place where the command can
172 * interactively ask for values of missing required arguments. 169 * interactively ask for values of missing required arguments.
173 *
174 * @param InputInterface $input An InputInterface instance
175 * @param OutputInterface $output An OutputInterface instance
176 */ 170 */
177 protected function interact(InputInterface $input, OutputInterface $output) 171 protected function interact(InputInterface $input, OutputInterface $output)
178 { 172 {
179 } 173 }
180 174
181 /** 175 /**
182 * Initializes the command just after the input has been validated. 176 * Initializes the command just after the input has been validated.
183 * 177 *
184 * This is mainly useful when a lot of commands extends one main command 178 * This is mainly useful when a lot of commands extends one main command
185 * where some things need to be initialized based on the input arguments and options. 179 * where some things need to be initialized based on the input arguments and options.
186 *
187 * @param InputInterface $input An InputInterface instance
188 * @param OutputInterface $output An OutputInterface instance
189 */ 180 */
190 protected function initialize(InputInterface $input, OutputInterface $output) 181 protected function initialize(InputInterface $input, OutputInterface $output)
191 { 182 {
192 } 183 }
193 184
195 * Runs the command. 186 * Runs the command.
196 * 187 *
197 * The code to execute is either defined directly with the 188 * The code to execute is either defined directly with the
198 * setCode() method or by overriding the execute() method 189 * setCode() method or by overriding the execute() method
199 * in a sub-class. 190 * in a sub-class.
200 *
201 * @param InputInterface $input An InputInterface instance
202 * @param OutputInterface $output An OutputInterface instance
203 * 191 *
204 * @return int The command exit code 192 * @return int The command exit code
205 * 193 *
206 * @throws \Exception When binding input fails. Bypass this by calling {@link ignoreValidationErrors()}. 194 * @throws \Exception When binding input fails. Bypass this by calling {@link ignoreValidationErrors()}.
207 * 195 *
473 461
474 return $this; 462 return $this;
475 } 463 }
476 464
477 /** 465 /**
478 * @return bool Whether the command should be publicly shown or not. 466 * @return bool whether the command should be publicly shown or not
479 */ 467 */
480 public function isHidden() 468 public function isHidden()
481 { 469 {
482 return $this->hidden; 470 return $this->hidden;
483 } 471 }