private function applyDefaultRequestHeaders(Request $request) { $headers = $request->getHeaders(); $headers['Accept'] = 'application/json'; $userAgentBuilder = new UserAgentBuilder(); $headers['User-Agent'] = $userAgentBuilder->setOsName(php_uname('s'))->setOsVersion(php_uname('r'))->setPhpVersion(phpversion())->build(); if ($request->getBody()) { $headers['Content-Type'] = 'application/json'; } $request->setHeaders($headers); }
/** * @test * @expectedException \InvalidArgumentException */ public function it_throws_exception_if_properties_are_not_set() { $userAgent = new UserAgentBuilder(); $userAgent->build(); }
private function applyDefaultRequestHeaders(Request $request) { $headers = $request->getHeaders(); $headers['Accept'] = 'application/json'; $userAgentBuilder = new UserAgentBuilder(); $headers['User-Agent'] = $userAgentBuilder->setOsName(php_uname('s'))->setOsVersion(php_uname('r'))->setPhpVersion(phpversion())->build(); if ($body = $request->getBody()) { $headers['Content-Type'] = 'application/json'; if (strpos($request->getResourceUrl(), '/oauth/token')) { $arr = json_decode($body); $arr = (array) $arr; ksort($arr); $body = http_build_query($arr); $request->setBody($body, strlen($body)); $headers['Content-Type'] = 'application/x-www-form-urlencoded'; $headers['Content-Length'] = $request->getContentLength(); } } $request->setHeaders($headers); }