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

no issue - just an idea #10

Open
pine3ree opened this issue Jun 1, 2016 · 3 comments
Open

no issue - just an idea #10

pine3ree opened this issue Jun 1, 2016 · 3 comments

Comments

@pine3ree
Copy link
Contributor

pine3ree commented Jun 1, 2016

(...this is in some way related to the discussion about the helper factory)

Since you are using zend-view (which includes its own helper), we could just use the zend-view BasePath view helper and just call setBasePath on it without having a custom view helper which basically does the same.

i tried it and it works just fine (zend-servicemanager3), see following code fragments:

//...
use Zend\View\HelperPluginManager;
use Zend\View\Helper\BasePath;
//...
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
    {
        //...
        if ($this->container->has(HelperPluginManager::class)) {
            $manager = $this->container->get(HelperPluginManager::class);
            if ($manager->has(BasePath::class)) {
                $helper = $manager->get(BasePath::class);
                $helper->setBasePath($this->basePath . '/');
            }
        }
        //...
        return $next($request, $response);
    }

you can close the issue of course since it's not an issue :-)
kind regards

@pine3ree
Copy link
Contributor Author

pine3ree commented Jun 8, 2016

self-comment b4 i forget
the approach used above works but will instantiate the plugin manager and the zend-view base-path helper. Maybe a better solution is to just define the base-path plugin factory to a custom factory extendend from zend-view (which is simply the InvokableFactory) and find a way to inject the detected base url/path in there. Since a factory has no knowledge of the request and therefore of its attributes, maybe we can alter the application configuration via the container so that the detected value (if not empty) can be reflected into a generic 'base_path' or 'base_url' key.

@gbonnema
Copy link

@pine3ree Do you mean to include the code fragment you gave into each action? Or do you insert it somewhere as middleware?

@pine3ree
Copy link
Contributor Author

@gbonnema
Hello. I meant it as a early middleware as the __invoke signature is suggesting.
kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants