php - Split interface into multiple when using repository pattern in Laravel 5 -
i have eloquentcompanyrepository
class implements companyrepository
interface. interface consist of such methods find
, all
, save
, other common methods. plus has methods saveemail
, savecall
, savesms
. apart eloquentcompanyrepository
there other classes have saveemail
, savecall,
savesms
methods.
i want split companyrepository
interface separate files. basic eloquentrepository
, interfaces emailablecontract
,callablecontract
, smsablecontract
.
however don't understand, binding in service provider? interface should use in controllers? there situation when repository implement eloquentrepository
, emailablecontract
example. , can't use both interfaces in controller, since if want eloquentcompanyrepository
class , implements these 2 interfaces, should use in $app->bind?
i don't repeat these methods find, all, saveemail etc in multiple repositories
in laravel 5 have called contextual binding. can bind given implementations different controllers same requirements this:
$this->app->when('app\handlers\commands\createorderhandler') ->needs('app\contracts\eventpusher') ->give('app\services\pubnubeventpusher');
this way saying "when createorderhandler needs eventpusher give instance of pubnubeventpusher".
Comments
Post a Comment