Last active
March 25, 2019 17:34
-
-
Save ger86/8422c5712f8848049e65776f3dffa1d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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