CakePHP ãƒãƒƒãƒå‡¦ç†
ãƒãƒƒãƒå‡¦ç†ã®æ©Ÿèƒ½
CakePHP3ã®æ©Ÿèƒ½ã‚’フルã«ä½¿ãˆã‚‹ã€‚
DBã®å–å¾—ã€ãƒã‚°å‡ºåŠ›ã€ä¾‹å¤–ã€å›ºå®šå€¤ãƒ•ァイルç‰
CakePHP4〜ã¯ã‚·ã‚§ãƒ«ã¯éžæŽ¨å¥¨ã€‚→コマンドã¸
ãƒãƒƒãƒå®Ÿè£…方法
※TestShell.php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Log\Log;
use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
use App\Controller\Component\TESTComponent;
「Shellã€ã‚’継承
class TESTShell extends Shell {
  public function initialize() {
    コンãƒãƒ¼ãƒãƒ³ãƒˆã‚’å‚ç…§(コンãƒãƒ¼ãƒãƒ³ãƒˆã‚’利用ã™ã‚‹å ´åˆ)
    $this->TEST = new TESTComponent(new ComponentRegistry());
  }
  シェルã§ã¯mainメソッドãŒè‡ªå‹•実行ã•れる
  public function main() {
    TESTComponent内ã®ãƒ¡ã‚½ãƒƒãƒ‰ã‚’実行
    $this->TEST->check();
  }
}
cake bake command コマンドå
例 cake bake command TestCommand
TestCommand.php
class TestCommand extends Command
{
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser = parent::buildOptionParser($parser);
return $parser;
}
public function execute(Arguments $args, ConsoleIo $io)
{
$io–>out('CakePHP4');
}
}
ファイル構æˆ
â””cake.php
â””logs
 └cli-debug.log
 └cli-error.log
  ↑画é¢ãƒã‚°ã¨ã¯åˆ¥ã«ã‚·ã‚§ãƒ«ãƒã‚°ãŒå‡ºåŠ›ã•れる
â””src
 └Controller
  └Component
   └TESTComponent.php
â””Shell
 └TestShell.php
  ↑末尾ã«ã€ŒShellã€ã‚’付ã‘ã‚‹
â””src
 └Controller
  └〜
 └Shell
  └〜
 └Command
  └〜TestCommand.php
ãƒãƒƒãƒå®Ÿè¡Œæ–¹æ³•
php cake.php TEST
↑TEST=TestShell.php
cake コマンドå