63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
class genTokenOptions
|
|
{
|
|
private $clientHTTP;
|
|
|
|
public function __construct(){
|
|
|
|
//IdentityService?
|
|
// $options['IdentityService'] pas oblige?...
|
|
// creer HttpClient authurl HandlerStack::create()
|
|
// $option['identityService'] = factory httpClient
|
|
//AuthHadler?
|
|
//
|
|
//StockClient?
|
|
// creer $options['httpClient'] instance de ClientInterface
|
|
// token, baseUrl = identity->authenticate
|
|
// stack = getStack authhandler token
|
|
// addDebug??
|
|
// $options['httpClient'] = httpCLient baseurl stack
|
|
|
|
}
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
private function addDebugMiddleware(array $options, HandlerStack &$stack)
|
|
{
|
|
if (!empty($options['debugLog'])
|
|
&& !empty($options['logger'])
|
|
&& !empty($options['messageFormatter'])
|
|
) {
|
|
$stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
|
|
}
|
|
}
|
|
/**
|
|
* @param array $options
|
|
* @codeCoverageIgnore
|
|
*/
|
|
private function stockAuthHandler(array &$options)
|
|
{
|
|
if (!isset($options['authHandler'])) {
|
|
$options['authHandler'] = function () use ($options) {
|
|
return $options['identityService']->generateToken($options);
|
|
};
|
|
}
|
|
}
|
|
|
|
private function getStack(callable $authHandler, Token $token = null)
|
|
{
|
|
$stack = HandlerStack::create();
|
|
$stack->push(Middleware::authHandler($authHandler, $token));
|
|
return $stack;
|
|
}
|
|
|
|
private function httpClient($baseUrl, HandlerStack $stack)
|
|
{
|
|
return new Client([
|
|
'base_uri' => Utils::normalizeUrl($baseUrl),
|
|
'handler' => $stack,
|
|
]);
|
|
}
|
|
}
|