Skip to content

Commit

Permalink
uses guzzle StreamHandler by default for AppEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Nov 2, 2015
1 parent 1c69c63 commit 4d21613
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Google/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Google/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down

0 comments on commit 4d21613

Please sign in to comment.