Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active March 25, 2019 17:34
Show Gist options
  • Save ger86/8422c5712f8848049e65776f3dffa1d7 to your computer and use it in GitHub Desktop.
Save ger86/8422c5712f8848049e65776f3dffa1d7 to your computer and use it in GitHub Desktop.
<?php
...
use Symfony\Component\HttpFoundation\RequestStack;
use GuzzleHttp\Cookie\CookieJar;
...
class GuzzleApiRequest implements ApiRequestInterface {
/**
* Constructor
*
* @param RequestStack $requestStack
* @param string $cookieDomain
* @param string $backendUrl
* @param string $apiPath
*/
public function __construct(RequestStack $requestStack, string $cookieDomain, string $backendUrl, string $apiPath) {
$request = $requestStack->getCurrentRequest();
$jar = CookieJar::fromArray($request->cookies->all(), $cookieDomain);
$this->client = new Client([
'base_uri' => sprintf('%s/%s/', $backendUrl, $apiPath),
'cookies' => $jar,
'defaults' => [
'exceptions' => false,
'allow_redirects' => false
]
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment