class FormAssemblyKeyService in FormAssembly 8
This service retrieves the appropriate api key from the configured provider.
Uses the Key module repository if it is available.
Hierarchy
- class \Drupal\formassembly\FormAssemblyKeyService
Expanded class hierarchy of FormAssemblyKeyService
1 string reference to 'FormAssemblyKeyService'
1 service uses FormAssemblyKeyService
File
- src/
FormAssemblyKeyService.php, line 14
Namespace
Drupal\formassemblyView source
class FormAssemblyKeyService {
/**
* Config for the oauth credentials.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $oauthConfig;
/**
* Key module service conditionally injected.
*
* @var \Drupal\key\KeyRepositoryInterface
*/
protected $keyRepository;
/**
* KeyService constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Injected service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->oauthConfig = $config_factory
->get('formassembly.api.oauth')
->get('credentials');
}
/**
* Provides a means to our services.yml file to conditionally inject service.
*
* @param \Drupal\key\KeyRepositoryInterface $repository
* The injected service, if it exists.
*
* @see maw_luminate.services.yml
*/
public function setKeyRepository(KeyRepositoryInterface $repository) {
$this->keyRepository = $repository;
}
/**
* Detects if key module service was injected.
*
* @return bool
* True if the KeyRepository is present.
*/
public function additionalProviders() {
return $this->keyRepository instanceof KeyRepositoryInterface;
}
/**
* Get the oauth credentials.
*
* @return string
* The value of the configured key.
*/
public function getOauthKeys() {
switch ($this->oauthConfig['provider']) {
case 'key':
$credentials = [];
$keyId = $this->oauthConfig['data']['id'];
$keyEntity = $this->keyRepository
->getKey($keyId);
if ($keyEntity instanceof Key) {
// A key was found in the repository.
$credentials = $keyEntity
->getKeyValues();
}
break;
default:
$credentials = $this->oauthConfig['data'];
}
return $credentials;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormAssemblyKeyService:: |
protected | property | Key module service conditionally injected. | |
FormAssemblyKeyService:: |
protected | property | Config for the oauth credentials. | |
FormAssemblyKeyService:: |
public | function | Detects if key module service was injected. | |
FormAssemblyKeyService:: |
public | function | Get the oauth credentials. | |
FormAssemblyKeyService:: |
public | function | Provides a means to our services.yml file to conditionally inject service. | |
FormAssemblyKeyService:: |
public | function | KeyService constructor. |