samedi 4 juillet 2015

How to type-hint abstract method parameter with laravel IoC

How would I go about using Laravels IoC in order to avoid PHPs declaration error?

Declaration of # must be compatible with #

I have created an abstract class which would be implemented by numerous packages. Something like the following:

<?php namespace Test\Test;

abstract class Example implements SomeContract
{
    abstract protected function someName(ClassHint $object);
}

So one package will extend and implement someName with SomeClass1, whilst another package will extend and implement someName with SomeClass2 - how can I achieve this with Laravel and it's IoC.

I have looked into using App::make() except I can't see a way to implement this at all. Although I could omit the ClassHint I don't want to, the idea is to enforce a consistent way of implementing that class with a different hinted class each time.





Aucun commentaire:

Enregistrer un commentaire