I am working on an API application that will be run in different domains: http://example.com/, http://sub.example.com/, http://example-another.com/. Part of the API responses needs to send out its base_url. So I am trying to find a way to dynamically collect the base_url and add it to my response.
I have a factory to initiate the action handler as follows:
class TestHandlerFactory
{
public function __invoke(ContainerInterface $container) : TestHandler
{
return new TestHandler();
}
}
Then my action handler is as follows:
class TestHandler implements RequestHandlerInterface
{
public function __construct()
{
...
}
public function handle(ServerRequestInterface $request) : ResponseInterface
{
...
}
}
I am new to Zend world and I found the https://github.com/zendframework/zend-http/blob/master/src/PhpEnvironment/Request.php probably a potential solution of my problem. However, I do not how to get that PHP-Environment object (or any other object that help me grab the base url) in the factory or handler class.