LoginSignup
13
2

More than 5 years have passed since last update.

【Laravel】Commandクラスのconstructorの罠

Last updated at Posted at 2017-03-29

タイトルは言い過ぎですね。

罠というモノではないのですがphp artisanコマンドを実行したタイミングで、
App\Console\Kernelに登録されているCommandクラス群は、
すべてインスタンス化されて__construct がコールされます。
(コマンドリストが出力されるのは、そういう仕組みなのか)

ですので、__construct内でCommand::handleがコールされた時にしか使用しないような
初期化処理はやめた方が良いです。。。

php artisanするだけでRedisやらDBやらにアクセスする処理が走ってしまうと...

13
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
2