The title would be vague due to my English. Hope someone can improve it.
Here is the thing:
I have one abstract class Validator
.
Currently, I have two subclasses, LoginValidator
and SignupValidator
, which extend from Validator
.
I have two services: LoginService
and SignupService
and they have the same
function __construct(Validator $validator)
I wrote two ServiceProvider
s to bind the Validator
.
LoginServiceProvider.php
$this->app->bind('Validators\Validator','Validators\LoginValidator');
SignupServiceProvider.php
$this->app->bind('Validators\Validator','Validators\SignupValidator');
Therefore, the $validator
in __construct(Validator $validator)
is actually always resolved to SignupValidator
. I know the reason.
I wonder if there is any way to make sure that:
class LoginService {
//$validator will be LoginValidator
function __construct(Validator $validator){}
}
class SignupService {
//$validator will be SignupValidator
function __construct(Validator $validator){}
}
OR
I'm simply wrong, I should do __construct(LoginValidator $validator)
?