class MockHttpClientFactory in Apigee Edge 8
Class MockHttpClientFactory.
Hierarchy
- class \Drupal\Core\Http\ClientFactory
- class \Drupal\apigee_mock_api_client\MockHttpClientFactory
Expanded class hierarchy of MockHttpClientFactory
1 string reference to 'MockHttpClientFactory'
- apigee_mock_api_client.services.yml in tests/
modules/ apigee_mock_api_client/ apigee_mock_api_client.services.yml - tests/modules/apigee_mock_api_client/apigee_mock_api_client.services.yml
1 service uses MockHttpClientFactory
- apigee_mock_api_client.mock_http_client_factory in tests/
modules/ apigee_mock_api_client/ apigee_mock_api_client.services.yml - Drupal\apigee_mock_api_client\MockHttpClientFactory
File
- tests/
modules/ apigee_mock_api_client/ src/ MockHttpClientFactory.php, line 31
Namespace
Drupal\apigee_mock_api_clientView source
class MockHttpClientFactory extends ClientFactory {
/**
* The handler stack (retained for compatibility).
*
* @var \GuzzleHttp\HandlerStack
*/
protected $stack;
/**
* The mock handler stack (Allows us to queue responses).
*
* @var \GuzzleHttp\HandlerStack
*/
protected $mock_stack;
/**
* Whether or not integration is currently enabled.
*
* @var bool
*/
protected $integration_enabled;
/**
* Constructs a new ClientFactory instance.
*
* @param \GuzzleHttp\HandlerStack $stack
* The handler stack.
* @param \Apigee\MockClient\GuzzleHttp\MockHandler $mock_stack
* The mock handler stack (Allows us to queue responses).
* @param \Drupal\Core\State\StateInterface $state
* Drupal state service, used to determine whether tests should be run
* using the mock handler or against a remote edge instance.
*/
public function __construct(HandlerStack $stack, MockHandler $mock_stack, StateInterface $state) {
$this->stack = $stack;
$this->mock_stack = $mock_stack;
// Check for the integration enabled environment variable.
if ($enabled = getenv('APIGEE_INTEGRATION_ENABLE')) {
$this->integration_enabled = !empty($enabled);
// Callbacks won't have access to the same environment variables so save
// the flag to state.
$state
->set('APIGEE_INTEGRATION_ENABLE', $enabled);
}
else {
$this->integration_enabled = !empty($state
->get('APIGEE_INTEGRATION_ENABLE', FALSE));
}
parent::__construct($stack);
}
/**
* {@inheritdoc}
*/
public function fromOptions(array $config = []) {
$config = [
'handler' => $this->integration_enabled ? $this->stack : $this->mock_stack,
];
return parent::fromOptions($config);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MockHttpClientFactory:: |
protected | property | Whether or not integration is currently enabled. | |
MockHttpClientFactory:: |
protected | property | The mock handler stack (Allows us to queue responses). | |
MockHttpClientFactory:: |
protected | property |
The handler stack (retained for compatibility). Overrides ClientFactory:: |
|
MockHttpClientFactory:: |
public | function |
Constructs a new client object from some configuration. Overrides ClientFactory:: |
|
MockHttpClientFactory:: |
public | function |
Constructs a new ClientFactory instance. Overrides ClientFactory:: |