Thanks to Symfony HttpFoundation component , we can retrieve the server params like the following script :
// retrieves SERVER variables
$request->server->get('HTTP_HOST')
So, i have the following construct and i'd like to have the server parameters :
public function __construct(RequestStack $requestStack)
{
$request = $requestStack->getCurrentRequest();
$this->country = self::DEFAULT_COUNTRY;
$this->lang = self::DEFAULT_LANG;
$this->brand = self::DEFAULT_BRAND;
$this->jobBrand = $this->brand;
if ($request) {
if (!empty($request->server->get(self::ENV_COUNTRY_CODE))) {
$this->country = $request->server->get(self::ENV_COUNTRY_CODE);
}
if (!empty($request->server->get(self::ENV_LANG_CODE))) {
$this->lang = $request->server->get(self::ENV_LANG_CODE);
}
if (!empty($request->server->get(self::ENV_BRAND))) {
$this->jobBrand = $request->server->get(self::ENV_BRAND);
$this->brand = str_replace('pro', '', $this->jobBrand);
}
if (empty($this->country) || empty($this->lang)) {
throw new NoApacheLocaleException();
}
}
}
For information, during the testing phase, I used Postman as an http client.
So my question is: how can I send my parameters via Postman in order to get it through $request->server->get('param') ?
According to @Cerad and I'm convinced by his answer :
$_SERVER is initialized by PHP based on server side information. Does not use anything from the HTTP request. I suppose you could fake it for testing by using variable names like _server_http_host and adjust your code accordingly. But if you are using the Symfony framework then you might be better off using Symfony's functional testing approach.