Reputation: 14500
When binding an implementation for given Interface or Abstract class, e. g
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
how laravel determines that given implementation is one of the implementations of the the passed interface/abstract class
Lets assume I have following interfaces
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 {
}
Implementations:
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;
}
}
Back to bind method :
$app->bind(
App\IBicycle::class,
App\Car::class
);
Give the above binding my question is how laravel validates OR not validate that Car is/or not is an implementation of App\IBicycle
interface ? What is the use of passing inteface/abstract class in more general sense if no validation is performed ?
Upvotes: 1
Views: 599
Reputation: 31210
If I understand your question well, I think you are looking for the Laravel Service Providers. There is where you bind the implementation to an Interface. The IoC will look for those bindings (in your ServiceProviders) to determine which implementation it should use.
Upvotes: 0