I moved all the public images of my website to a folder out of the web folder of symfony so it can be shared with other web applications. I created a symbolic link to this folder so it can be accessed from the web folder of the symfony application.
ln -s /absolute/path/to/images /path/to/symfony/application_01/web/images
ln -s /absolute/path/to/images /path/to/symfony/application_02/web/images
Etc... for all applications.
I'm looking for a method that would allow me to retrieve the images URI in my development environment on localhost as well as in my production environment on the remote web server.
I would like to be able to retrieve this URI from the twig template AND from the controller.
Basically (for my application_01 for instance):
In the development environment it would return:
http://localhost/images/my_image.jpg
In the production environment, it would return:
http://www.application_01.com/images/my_image.jpg
My problem is that I found lots of different ways to get URIs but I'm not totally clear about how Symfony manages them and what functions to use to have a global solution working in all cases.
What is the best way to achieve my goal?
EDIT
Specifically I found some SO answers to quite similar questions proposing to use the following functions:
$request->getScheme(); $request->getHttpHost();
That seems to correspond to the values or superglobals $_SERVER['REQUEST_SCHEME'] and $_SERVER['HTTP_HOST']
And I don't know if this is the proper way to get this information since this is linked to the current request received by the server.
Isn't there another way to get this info independently from the request currently processed by the server?