Skip to content

Commit

Permalink
Merge branch 'master' into fix_test_class_names
Browse files Browse the repository at this point in the history
  • Loading branch information
k0ka authored Jan 7, 2024
2 parents e6562c7 + ac3ca5c commit 3a24b73
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/Common/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware as GuzzleMiddleware;
use OpenStack\Common\Auth\IdentityService;
use OpenStack\Common\Auth\Token;
use OpenStack\Common\Transport\HandlerStack;
use OpenStack\Common\Transport\HandlerStackFactory;
use OpenStack\Common\Transport\Middleware;
use OpenStack\Common\Transport\Utils;

Expand Down Expand Up @@ -79,7 +80,7 @@ public function createService(string $namespace, array $serviceOptions = []): Se
$this->stockAuthHandler($options);
$this->stockHttpClient($options, $namespace);

list($apiClass, $serviceClass) = $this->getClasses($namespace);
[$apiClass, $serviceClass] = $this->getClasses($namespace);

return new $serviceClass($options['httpClient'], new $apiClass());
}
Expand All @@ -91,7 +92,7 @@ private function stockHttpClient(array &$options, string $serviceName)
$baseUrl = $options['authUrl'];
$stack = $this->getStack($options['authHandler']);
} else {
list($token, $baseUrl) = $options['identityService']->authenticate($options);
[$token, $baseUrl] = $options['identityService']->authenticate($options);
$stack = $this->getStack($options['authHandler'], $token);
}

Expand Down Expand Up @@ -130,7 +131,7 @@ private function stockAuthHandler(array &$options)

private function getStack(callable $authHandler, Token $token = null): HandlerStack
{
$stack = HandlerStack::create();
$stack = HandlerStackFactory::create();
$stack->push(Middleware::authHandler($authHandler, $token));

return $stack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace OpenStack\Common\Transport;

use GuzzleHttp\HandlerStack as GuzzleStack;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Utils;

class HandlerStack extends GuzzleStack
class HandlerStackFactory
{
public static function create(callable $handler = null): GuzzleStack
public static function create(callable $handler = null): HandlerStack
{
$stack = new self($handler ?: Utils::chooseHandler());
$stack = new HandlerStack($handler ?: Utils::chooseHandler());
$stack->push(Middleware::httpErrors(), 'http_errors');
$stack->push(Middleware::prepareBody(), 'prepare_body');

Expand Down
4 changes: 2 additions & 2 deletions src/OpenStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Middleware as GuzzleMiddleware;
use OpenStack\Common\Service\Builder;
use OpenStack\Common\Transport\HandlerStack;
use OpenStack\Common\Transport\HandlerStackFactory;
use OpenStack\Common\Transport\Utils;
use OpenStack\Identity\v3\Service;

Expand Down Expand Up @@ -49,7 +49,7 @@ private function getDefaultIdentityService(array $options): Service
throw new \InvalidArgumentException("'authUrl' is a required option");
}

$stack = HandlerStack::create();
$stack = HandlerStackFactory::create();

if (!empty($options['debugLog'])
&& !empty($options['logger'])
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/Common/Transport/HandlerStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace OpenStack\Test\Common\Transport;

use GuzzleHttp\Handler\MockHandler;
use OpenStack\Common\Transport\HandlerStack;
use GuzzleHttp\HandlerStack;
use OpenStack\Common\Transport\HandlerStackFactory;
use OpenStack\Test\TestCase;

class HandlerStackTest extends TestCase
{
public function test_it_is_created()
{
self::assertInstanceOf(HandlerStack::class, HandlerStack::create(new MockHandler()));
self::assertInstanceOf(HandlerStack::class, HandlerStackFactory::create(new MockHandler()));
}
}

0 comments on commit 3a24b73

Please sign in to comment.