bjuppa / laravel-blog

Flexible blog functionality for your Laravel project
MIT License
48 stars 8 forks source link

Configure entry provider (and model?) per blog #6

Closed bjuppa closed 5 years ago

bjuppa commented 6 years ago

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 the Blog instance.

We could also cheat and resolve the instance from the app service container within Blog::withEntryProvider(), but that makes Blog dependent of the service container... not pretty :)

bjuppa commented 6 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?

bjuppa commented 6 years ago

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.

bjuppa commented 6 years ago

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 :)

bjuppa commented 6 years ago

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.