← All changes
|
includes/sdk/google/google/auth/src/HttpHandler/HttpHandlerFactory.php
+19
-15
1.2.6
→
1.4.1
View file →
| @@ -14,29 +14,32 @@ | ||
| 14 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | 15 | * See the License for the specific language governing permissions and |
| 16 | 16 | * limitations under the License. |
| 17 | 17 | */ |
| 18 | -namespace Dudlewebs\WPMCS\Google\Auth\HttpHandler; | |
| 18 | +namespace Dudlewebs\WPMCS\GCP\Google\Auth\HttpHandler; | |
| 19 | 19 | |
| 20 | -use Dudlewebs\WPMCS\GuzzleHttp\BodySummarizer; | |
| 21 | -use Dudlewebs\WPMCS\GuzzleHttp\Client; | |
| 22 | -use Dudlewebs\WPMCS\GuzzleHttp\ClientInterface; | |
| 23 | -use Dudlewebs\WPMCS\GuzzleHttp\HandlerStack; | |
| 24 | -use Dudlewebs\WPMCS\GuzzleHttp\Middleware; | |
| 20 | +use Dudlewebs\WPMCS\GCP\Google\Auth\ApplicationDefaultCredentials; | |
| 21 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\BodySummarizer; | |
| 22 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Client; | |
| 23 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\ClientInterface; | |
| 24 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\HandlerStack; | |
| 25 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Middleware; | |
| 26 | +use Dudlewebs\WPMCS\GCP\Psr\Log\LoggerInterface; | |
| 25 | 27 | class HttpHandlerFactory |
| 26 | 28 | { |
| 27 | 29 | /** |
| 28 | 30 | * Builds out a default http handler for the installed version of guzzle. |
| 29 | 31 | * |
| 30 | - * @param ClientInterface $client | |
| 32 | + * @param ClientInterface|null $client | |
| 33 | + * @param null|false|LoggerInterface $logger | |
| 31 | 34 | * @return Guzzle6HttpHandler|Guzzle7HttpHandler |
| 32 | 35 | * @throws \Exception |
| 33 | 36 | */ |
| 34 | - public static function build(ClientInterface $client = null) | |
| 37 | + public static function build(?ClientInterface $client = null, null|false|LoggerInterface $logger = null) | |
| 35 | 38 | { |
| 36 | - if (is_null($client)) { | |
| 39 | + if (\is_null($client)) { | |
| 37 | 40 | $stack = null; |
| 38 | - if (class_exists(BodySummarizer::class)) { | |
| 41 | + if (\class_exists(BodySummarizer::class)) { | |
| 39 | 42 | // double the # of characters before truncation by default |
| 40 | 43 | $bodySummarizer = new BodySummarizer(240); |
| 41 | 44 | $stack = HandlerStack::create(); |
| 42 | 45 | $stack->remove('http_errors'); |
| @@ -43,19 +46,20 @@ | ||
| 43 | 46 | $stack->unshift(Middleware::httpErrors($bodySummarizer), 'http_errors'); |
| 44 | 47 | } |
| 45 | 48 | $client = new Client(['handler' => $stack]); |
| 46 | 49 | } |
| 50 | + $logger = $logger === \false ? null : $logger ?? ApplicationDefaultCredentials::getDefaultLogger(); | |
| 47 | 51 | $version = null; |
| 48 | - if (defined('Dudlewebs\WPMCS\GuzzleHttp\ClientInterface::MAJOR_VERSION')) { | |
| 52 | + if (\defined('Dudlewebs\\WPMCS\\GCP\\GuzzleHttp\\ClientInterface::MAJOR_VERSION')) { | |
| 49 | 53 | $version = ClientInterface::MAJOR_VERSION; |
| 50 | - } elseif (defined('Dudlewebs\WPMCS\GuzzleHttp\ClientInterface::VERSION')) { | |
| 51 | - $version = (int) substr(ClientInterface::VERSION, 0, 1); | |
| 54 | + } elseif (\defined('Dudlewebs\\WPMCS\\GCP\\GuzzleHttp\\ClientInterface::VERSION')) { | |
| 55 | + $version = (int) \substr(ClientInterface::VERSION, 0, 1); | |
| 52 | 56 | } |
| 53 | 57 | switch ($version) { |
| 54 | 58 | case 6: |
| 55 | - return new Guzzle6HttpHandler($client); | |
| 59 | + return new Guzzle6HttpHandler($client, $logger); | |
| 56 | 60 | case 7: |
| 57 | - return new Guzzle7HttpHandler($client); | |
| 61 | + return new Guzzle7HttpHandler($client, $logger); | |
| 58 | 62 | default: |
| 59 | 63 | throw new \Exception('Version not supported'); |
| 60 | 64 | } |
| 61 | 65 | } |