Skip to content

Instantly share code, notes, and snippets.

@ger86
Created March 25, 2019 17:55
Show Gist options
  • Save ger86/a515ac877de9cf2572206861b2e585ae to your computer and use it in GitHub Desktop.
Save ger86/a515ac877de9cf2572206861b2e585ae to your computer and use it in GitHub Desktop.
<?php
...
use Symfony\Component\HttpFoundation\Session\SessionInterface;
...
class GuzzleApiRequest implements ApiRequestInterface {
/**
* Constructor
*
* @param SessionInterface $session
* @param RequestStack $requestStack
* @param string $cookieDomain
* @param string $backendUrl
* @param string $apiPath
*/
public function __construct(SessionInterface $session, RequestStack $requestStack, string $cookieDomain, string $backendUrl, string $apiPath) {
$this->session = $session;
$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