File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,34 @@ method. Then you can optionally define a help message and the
6161 ;
6262 }
6363
64+ The ``configure() `` command is called automatically at the end of the command
65+ constructor. If your command defines its own constructor, set the properties
66+ first and then call to the parent constructor, to make those properties
67+ available in the ``configure() `` method::
68+
69+ class CreateUserCommand extends Command
70+ {
71+ // ...
72+
73+ public function __construct(bool $requirePassword = false)
74+ {
75+ // best practices recommend to call the parent constructor first and
76+ // then set your own properties. That wouldn't work in this case
77+ // because configure() needs the properties set in this constructor
78+ $this->requirePassword = $requirePassword;
79+
80+ parent::__construct();
81+ }
82+
83+ public function configure()
84+ {
85+ $this
86+ // ...
87+ ->addArgument('password', $this->requirePassword ? InputArgument::OPTIONAL : InputArgument::REQUIRED, 'User password')
88+ ;
89+ }
90+ }
91+
6492Registering the Command
6593-----------------------
6694
You can’t perform that action at this time.
0 commit comments