apiKey = $apiKey; } /** * @param User $entity */ public function afterSave(Entity $entity): void { if (!$entity->isApi()) { return; } if ( $entity->get('apiKey') && $entity->get('secretKey') && ( $entity->isAttributeChanged('apiKey') || $entity->isAttributeChanged('authMethod') ) ) { $this->apiKey->storeSecretKeyForUserId($entity->getId(), $entity->get('secretKey')); } if ( $entity->isAttributeChanged('authMethod') && $entity->get('authMethod') !== 'Hmac' ) { $this->apiKey->removeSecretKeyForUserId($entity->getId()); } } /** * @param User $entity */ public function afterRemove(Entity $entity): void { if (!$entity->isApi()) { return; } if ($entity->get('authMethod') === 'Hmac') { $this->apiKey->removeSecretKeyForUserId($entity->getId()); } } }