Skip to content

Commit 05fbb9c

Browse files
committed
minor #9969 Explained some issues about command constructors and configure (javiereguiluz)
This PR was merged into the 3.4 branch. Discussion ---------- Explained some issues about command constructors and configure This fixes #9863 differently. Commits ------- 27beba5 Explained some issues about command constructors and configure
2 parents 177c84a + 27beba5 commit 05fbb9c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

console.rst

+28
Original file line numberDiff line numberDiff 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+
6492
Registering the Command
6593
-----------------------
6694

0 commit comments

Comments
 (0)