class AppWarningsChecker in Apigee Edge 8
A service for handling app warnings.
Hierarchy
- class \Drupal\apigee_edge\Entity\AppWarningsChecker implements AppWarningsCheckerInterface uses StringTranslationTrait
Expanded class hierarchy of AppWarningsChecker
1 string reference to 'AppWarningsChecker'
1 service uses AppWarningsChecker
File
- src/
Entity/ AppWarningsChecker.php, line 32
Namespace
Drupal\apigee_edge\EntityView source
class AppWarningsChecker implements AppWarningsCheckerInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* AppWarningsChecker constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TimeInterface $time) {
$this->entityTypeManager = $entity_type_manager;
$this->time = $time;
}
/**
* {@inheritdoc}
*/
public function getWarnings(AppInterface $app) : array {
$warnings = [];
$warnings['revokedCred'] = FALSE;
$warnings['revokedOrPendingCredProduct'] = FALSE;
$warnings['expiredCred'] = FALSE;
$revoked_credentials = [];
$args = [
'@app' => mb_strtolower($app
->getEntityType()
->getSingularLabel()),
];
foreach ($app
->getCredentials() as $credential) {
// Check for revoked credentials.
if ($credential
->getStatus() === AppCredentialInterface::STATUS_REVOKED) {
$revoked_credentials[] = $credential;
continue;
}
// Check for expired credentials.
if (($expired_date = $credential
->getExpiresAt()) && $this->time
->getRequestTime() - $expired_date
->getTimestamp() > 0) {
$warnings['expiredCred'] = $this
->t('At least one of the credentials associated with this @app is expired.', $args);
}
// Check status of API products for credential.
foreach ($credential
->getApiProducts() as $cred_product) {
if ($cred_product
->getStatus() == CredentialProduct::STATUS_REVOKED || $cred_product
->getStatus() == CredentialProduct::STATUS_PENDING) {
$args['@api_product'] = $this->entityTypeManager
->getDefinition('api_product')
->getSingularLabel();
$args['@status'] = $cred_product
->getStatus() == CredentialProduct::STATUS_REVOKED ? $this
->t('revoked') : $this
->t('pending');
if (count($app
->getCredentials()) === 1) {
/** @var \Drupal\apigee_edge\Entity\ApiProductInterface $apiProduct */
$api_product = $this->entityTypeManager
->getStorage('api_product')
->load($cred_product
->getApiproduct());
$args['%name'] = $api_product
->label();
$warnings['revokedOrPendingCredProduct'] = $this
->t('%name @api_product associated with this @app is in @status status.', $args);
}
else {
$warnings['revokedOrPendingCredProduct'] = $this
->t('At least one @api_product associated with one of the credentials of this @app is in @status status.', $args);
}
break;
}
}
}
// If all credentials are revoked, show a warning.
if (count($app
->getCredentials()) === count($revoked_credentials)) {
$warnings['revokedCred'] = $this
->t('No valid credentials associated with this @app.', $args);
}
return $warnings;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AppWarningsChecker:: |
protected | property | The entity type manager. | |
AppWarningsChecker:: |
protected | property | The time service. | |
AppWarningsChecker:: |
public | function |
Checks credentials of an app and returns warnings about them. Overrides AppWarningsCheckerInterface:: |
|
AppWarningsChecker:: |
public | function | AppWarningsChecker constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |