少し面倒だったのでまとめ
src/Controller/Component/TestsComponent.php
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
class TestsComponent extends Component {
public function test() {
echo "OK\n";
}
}
src/Shell/SampleShell.php
<?php
namespace App\Shell;
use Cake\Console\ConsoleOptionParser;
use Cake\Console\Shell;
use Cake\Log\Log;
use Psy\Shell as PsyShell;
use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
use App\Controller\Component\TestsComponent;
class SampleShell extends Shell {
public function initialize() {
$this->Tests = new TestsComponent(new ComponentRegistry());
}
public function main() {
$this->Tests->test();
}
}
どうやらオートロードできないみたいなので自分でコンポーネントを初期化する必要があるみたいです。
Abstract化したりしてリフレクション的な感じで簡易化できそうな気もするのでできたら追記予定。