当绑定给定接口或抽象类的实现时,例如
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);laravel如何确定给定的实现是之一,之一,传递的接口/抽象类的实现
假设我有以下接口
IVehicle.php
namespace App;
interface IVehicle {
public function getNumberOfWheels();
}IBicycle.php
namespace App;
interface IBicycle extends IVehicle {
}I4Wheeler.php
namespace App;
interface I4Wheeler extends IVehicle {
}实现:
Bike.php
namespace App;
class Bike implements IBicycle{
public function getNumberOfWheels(){
return 2;
}
}Car.php
namespace App;
class Car implements I4Wheeler{
public function getNumberOfWheels(){
return 4;
}
}回到绑定方法:
$app->bind(
App\IBicycle::class,
App\Car::class
);给上面的绑定我的问题是,laravel如何验证或不验证Car是/或不是App\IBicycle的实现
界面?如果不执行验证,那么传递更一般意义上的整数/抽象类有什么用呢?
发布于 2015-10-28 22:18:12
如果我能很好地理解你的问题,我想你是在找拉拉维尔服务提供者。在这里,可以将实现绑定到接口。IoC将查找那些绑定(在您的ServiceProviders中)以确定它应该使用哪个实现。
https://stackoverflow.com/questions/33390125
复制相似问题