Created
March 25, 2019 17:55
-
-
Save ger86/a515ac877de9cf2572206861b2e585ae 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\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