Closed bjuppa closed 5 years ago
Can we solve this by checking any string in config if it's resolvable and if so resolve it? Would that be a scary thing to do?
What if we first check the string if a class exists, then we check if it can be resolved? I mean, we wouldn't want every string to resolve to a class all of a sudden.
Hang on, why don't we reflect parameters on the with-method to see if an instance is required, if so, we resolve the config via the service container.
I guess there's probably already a method on the the service container that can do just that :)
Alright, perhaps this shouldn't be done via configuration? Someone who is swapping in alternative implementations for individual blogs is probably a pretty advanced user...
So, what if we add to the instructions that one can pull out any existing Blog
from the BlogRegistry
within the boot()
method of any Laravel service provider, and manipulate it there.
To use a custom BlogEntryProvider
one can set it on the Blog
using withEntryProvider()
.
To use a custom model one can call getEntryProvider()->withEntryModel()
, if the entry provider is a Bjuppa\LaravelBlog\Eloquent\BlogEntryProvider
.
I think this can be achieved if the service provider replaces
entry_provider
with a resolved instance if string is a classname in the config array before creating theBlog
instance.We could also cheat and resolve the instance from the app service container within
Blog::withEntryProvider()
, but that makesBlog
dependent of the service container... not pretty :)