Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom loader in ViewManager #488

Closed
vladgorenkin opened this issue Jan 21, 2022 · 2 comments · Fixed by #495
Closed

Allow custom loader in ViewManager #488

vladgorenkin opened this issue Jan 21, 2022 · 2 comments · Fixed by #495
Assignees
Labels
Milestone

Comments

@vladgorenkin
Copy link
Contributor

Description

It is impossible to replace default view loader for ViewManager because ViewLoader is hardcoded. I'd suggest replacing ViewLoader with LoaderInterface. My use case is loading templates from database.

...
final class ViewManager implements ViewsInterface
{
    ...
    public function __construct(ViewsConfig $config, FactoryInterface $factory)
    {
        ...
        $this->loader = $factory->make(ViewLoader::class, [
            'namespaces' => $config->getNamespaces(),
        ]);
       ...
    }
@butschster butschster self-assigned this Jan 21, 2022
@butschster
Copy link
Member

butschster commented Jan 21, 2022

As I understand you have an ability to bind ViewLoader with alternative realization

$conatiner->bind(ViewLoader::class, function() {
    return new DatabaseViewLoader(...);
});

@vladgorenkin
Copy link
Contributor Author

This is ok as a temporary solution, but this behavior is confusing at least. Any type check (for example if container did one at the end of get() call) is going to fail because technically DatabaseViewLoader is neither ViewLoader, nor it's child (because ViewLoader is final)

@butschster butschster added this to the 2.9 milestone Jan 27, 2022
butschster added a commit that referenced this issue Jan 27, 2022
@butschster butschster moved this to Todo in Spiral framework Feb 2, 2022
@butschster butschster linked a pull request Feb 2, 2022 that will close this issue
@butschster butschster moved this from Todo to Done in Spiral framework Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants