Slide 12
Slide 12 text
• ServiceProvider 内(UserImageRepository は interface)
• 利用箇所(環境に依存しないコードになる)
• DI になっているのでテストも書きやすい!
12
うまくいっている点|Laravel との相性の良さ
if (app()->environment('production') || app()->environment('staging')) {
// 本番環境・ステージング環境のみ、S3 に保存
$this->app->bind(UserImageRepository::class, S3UserImageRepository::class);
} else {
// それ以外はローカルファイルストレージに保存
$this->app->bind(UserImageRepository::class, LocalUserImageRepository::class);
}
public function __construct(UserRepository $userRepository, UserImageRepository $userImageRepository)
{
$this->userRepository = $userRepository;
$this->userImageRepository = $userImageRepository;
}