lundi 19 décembre 2016

Laravel service container is it possible to bind to class AND all it's ancestors

I have base class like this:

class BaseAPI
{

    public function __construct(Client $client, CacheInterface $cache,  $apiBaseUri)
    {
        $this->client = $client;
        $this->apiBaseUri = $apiBaseUri;
        $this->cache = $cache;
    }
}

And then in provider:

class APIServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app
        ->when(BaseAPI::class)
        ->needs('$apiBaseUri')
        ->give(env('DEFAULT_API_URI',''));
    }
}

That is working. But when I'm making ancestor:

class GetLocations extends BaseAPI
{
     protected $apiMethodName = 'locations';
     protected $type = 'get';
}

I'm getting error. Of course I can manually write code for each of ancestors, but there is a lot's of them, so question is: is there any inheritance mechanism for binding?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire