diff --git a/src/Google/Client.php b/src/Google/Client.php index c62cd0d0e..1648971de 100644 --- a/src/Google/Client.php +++ b/src/Google/Client.php @@ -27,9 +27,10 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Collection; +use GuzzleHttp\Ring\Client\StreamHandler; use Psr\Log\LoggerInterface; use Monolog\Logger; -use Monolog\Handler\StreamHandler; +use Monolog\Handler\StreamHandler as MonologStreamHandler; /** * The Google API Client @@ -1004,7 +1005,7 @@ public function getLogger() protected function createDefaultLogger() { $logger = new Logger('google-api-php-client'); - $logger->pushHandler(new StreamHandler('php://stderr', Logger::NOTICE)); + $logger->pushHandler(new MonologStreamHandler('php://stderr', Logger::NOTICE)); return $logger; } @@ -1034,9 +1035,14 @@ protected function createDefaultHttpClient() { $options = [ 'base_url' => $this->config->get('base_path'), - 'defaults' => ['exceptions' => false] + 'defaults' => ['exceptions' => false], ]; + // set StreamHandler on AppEngine by default + if ($this->isAppEngine()) { + $options['handler'] = new StreamHandler(); + } + return new Client($options); } diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index d335ea24f..8b65d9e18 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -216,6 +216,21 @@ public function testAppEngineAutoConfig() $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine'; $client = new Google_Client(); $this->assertInstanceOf('Google_Cache_Memcache', $client->getCache()); + + // check Stream Handler is used + $http = $client->getHttpClient(); + $class = new ReflectionClass(get_class($http)); + $property = $class->getProperty('fsm'); + $property->setAccessible(true); + $fsm = $property->getValue($http); + + $class = new ReflectionClass(get_class($fsm)); + $property = $class->getProperty('handler'); + $property->setAccessible(true); + $handler = $property->getValue($fsm); + + $this->assertInstanceOf('GuzzleHttp\Ring\Client\StreamHandler', $handler); + unset($_SERVER['SERVER_SOFTWARE']); }