-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a9aa99
commit 0877591
Showing
245 changed files
with
22,374 additions
and
21,380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
declare(strict_types=1); | ||
|
||
namespace Acquia\Cli\AcsfApi; | ||
|
||
use AcquiaCloudApi\Connector\Client; | ||
use AcquiaCloudApi\Exception\ApiErrorException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class AcsfClient extends Client { | ||
|
||
public function processResponse(ResponseInterface $response): mixed { | ||
$bodyJson = $response->getBody(); | ||
$body = json_decode((string) $bodyJson, FALSE, 512, JSON_THROW_ON_ERROR); | ||
|
||
// ACSF sometimes returns an array rather than an object. | ||
if (is_array($body)) { | ||
return $body; | ||
class AcsfClient extends Client | ||
{ | ||
public function processResponse(ResponseInterface $response): mixed | ||
{ | ||
$bodyJson = $response->getBody(); | ||
$body = json_decode((string) $bodyJson, false, 512, JSON_THROW_ON_ERROR); | ||
|
||
// ACSF sometimes returns an array rather than an object. | ||
if (is_array($body)) { | ||
return $body; | ||
} | ||
|
||
if (property_exists($body, '_embedded') && property_exists($body->_embedded, 'items')) { | ||
return $body->_embedded->items; | ||
} | ||
|
||
if (property_exists($body, 'error') && property_exists($body, 'message')) { | ||
throw new ApiErrorException($body); | ||
} | ||
// Throw error for 4xx and 5xx responses. | ||
if (property_exists($body, 'message') && in_array(substr((string) $response->getStatusCode(), 0, 1), ['4', '5'], true)) { | ||
$body->error = $response->getStatusCode(); | ||
throw new ApiErrorException($body); | ||
} | ||
|
||
return $body; | ||
} | ||
|
||
if (property_exists($body, '_embedded') && property_exists($body->_embedded, 'items')) { | ||
return $body->_embedded->items; | ||
} | ||
|
||
if (property_exists($body, 'error') && property_exists($body, 'message')) { | ||
throw new ApiErrorException($body); | ||
} | ||
// Throw error for 4xx and 5xx responses. | ||
if (property_exists($body, 'message') && in_array(substr((string) $response->getStatusCode(), 0, 1), ['4', '5'], TRUE)) { | ||
$body->error = $response->getStatusCode(); | ||
throw new ApiErrorException($body); | ||
} | ||
|
||
return $body; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
declare(strict_types=1); | ||
|
||
namespace Acquia\Cli\AcsfApi; | ||
|
||
use Acquia\Cli\Application; | ||
use Acquia\Cli\CloudApi\ClientService; | ||
|
||
class AcsfClientService extends ClientService { | ||
|
||
public function __construct(AcsfConnectorFactory $connectorFactory, Application $application, AcsfCredentials $cloudCredentials) { | ||
parent::__construct($connectorFactory, $application, $cloudCredentials); | ||
} | ||
|
||
public function getClient(): AcsfClient { | ||
$client = AcsfClient::factory($this->connector); | ||
$this->configureClient($client); | ||
|
||
return $client; | ||
} | ||
|
||
protected function checkAuthentication(): bool { | ||
return ($this->credentials->getCloudKey() && $this->credentials->getCloudSecret()); | ||
} | ||
|
||
class AcsfClientService extends ClientService | ||
{ | ||
public function __construct(AcsfConnectorFactory $connectorFactory, Application $application, AcsfCredentials $cloudCredentials) | ||
{ | ||
parent::__construct($connectorFactory, $application, $cloudCredentials); | ||
} | ||
|
||
public function getClient(): AcsfClient | ||
{ | ||
$client = AcsfClient::factory($this->connector); | ||
$this->configureClient($client); | ||
|
||
return $client; | ||
} | ||
|
||
protected function checkAuthentication(): bool | ||
{ | ||
return ($this->credentials->getCloudKey() && $this->credentials->getCloudSecret()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
declare(strict_types=1); | ||
|
||
namespace Acquia\Cli\AcsfApi; | ||
|
||
use AcquiaCloudApi\Connector\Connector; | ||
use GuzzleHttp\Client as GuzzleClient; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class AcsfConnector extends Connector { | ||
|
||
/** | ||
* @param array<string> $config | ||
* @param string|null $baseUri | ||
* @param string|null $urlAccessToken | ||
*/ | ||
public function __construct(array $config, string $baseUri = NULL, string $urlAccessToken = NULL) { | ||
parent::__construct($config, $baseUri, $urlAccessToken); | ||
|
||
$this->client = new GuzzleClient([ | ||
'auth' => [ | ||
class AcsfConnector extends Connector | ||
{ | ||
/** | ||
* @param array<string> $config | ||
* @param string|null $baseUri | ||
* @param string|null $urlAccessToken | ||
*/ | ||
public function __construct(array $config, string $baseUri = null, string $urlAccessToken = null) | ||
{ | ||
parent::__construct($config, $baseUri, $urlAccessToken); | ||
|
||
$this->client = new GuzzleClient([ | ||
'auth' => [ | ||
$config['key'], | ||
$config['secret'], | ||
], | ||
'base_uri' => $this->getBaseUri(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param array<string> $options | ||
*/ | ||
public function sendRequest(string $verb, string $path, array $options): ResponseInterface { | ||
return $this->client->request($verb, $path, $options); | ||
} | ||
|
||
], | ||
'base_uri' => $this->getBaseUri(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param array<string> $options | ||
*/ | ||
public function sendRequest(string $verb, string $path, array $options): ResponseInterface | ||
{ | ||
return $this->client->request($verb, $path, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
declare(strict_types=1); | ||
|
||
namespace Acquia\Cli\AcsfApi; | ||
|
||
use Acquia\Cli\ConnectorFactoryInterface; | ||
|
||
class AcsfConnectorFactory implements ConnectorFactoryInterface { | ||
|
||
/** | ||
* @param array<string> $config | ||
*/ | ||
public function __construct(protected array $config, protected ?string $baseUri = NULL) { | ||
} | ||
|
||
public function createConnector(): AcsfConnector { | ||
return new AcsfConnector($this->config, $this->baseUri); | ||
} | ||
class AcsfConnectorFactory implements ConnectorFactoryInterface | ||
{ | ||
/** | ||
* @param array<string> $config | ||
*/ | ||
public function __construct(protected array $config, protected ?string $baseUri = null) | ||
{ | ||
} | ||
|
||
public function createConnector(): AcsfConnector | ||
{ | ||
return new AcsfConnector($this->config, $this->baseUri); | ||
} | ||
} |
Oops, something went wrong.