You are here

class FirebaseConfigManager in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 src/Smartling/ConfigManager/FirebaseConfigManager.php \Drupal\tmgmt_smartling\Smartling\ConfigManager\FirebaseConfigManager

Class FirebaseConfigManager.

Hierarchy

Expanded class hierarchy of FirebaseConfigManager

1 string reference to 'FirebaseConfigManager'
tmgmt_smartling.services.yml in ./tmgmt_smartling.services.yml
tmgmt_smartling.services.yml
1 service uses FirebaseConfigManager
tmgmt_smartling.firebase_config_manager in ./tmgmt_smartling.services.yml
\Drupal\tmgmt_smartling\Smartling\ConfigManager\FirebaseConfigManager

File

src/Smartling/ConfigManager/FirebaseConfigManager.php, line 16
FirebaseConfigManager.

Namespace

Drupal\tmgmt_smartling\Smartling\ConfigManager
View source
class FirebaseConfigManager extends SmartlingConfigManager {

  /**
   * @var \Drupal\tmgmt_smartling\Smartling\SmartlingApiWrapper
   */
  protected $apiWrapper;

  /**
   * @var \Drupal\Core\Cache\CacheBackendInterface $defaultCache
   */
  protected $defaultCache;

  /**
   * @param \Drupal\tmgmt_smartling\Smartling\SmartlingApiWrapper $apiWrapper
   */
  public function setSmartlingApiWrapper(SmartlingApiWrapper $apiWrapper) {
    $this->apiWrapper = $apiWrapper;
  }

  /**
   * @param \Drupal\Core\Cache\CacheBackendInterface $defaultCache
   */
  public function setDefaultCache(CacheBackendInterface $defaultCache) {
    $this->defaultCache = $defaultCache;
  }

  /**
   * Returns array of available smartling providers with enabled notifications.
   *
   * @return array
   */
  public function getAvailableConfigs() {
    $firebaseConfigs = [];
    $configs = parent::getAvailableConfigs();
    foreach ($configs as $config) {
      $provider_settings = $config
        ->get('settings');
      if (empty($provider_settings['enable_notifications'])) {
        continue;
      }
      $cachedData = $this->defaultCache
        ->get("tmgmt_smartling.firebase_config.{$provider_settings["project_id"]}");
      if (empty($cachedData)) {
        try {
          $this->apiWrapper
            ->setSettings($provider_settings);
          $project_details = $this->apiWrapper
            ->getApi("project")
            ->getProjectDetails();
          $data = $this->apiWrapper
            ->getApi("progress")
            ->getToken($project_details["accountUid"]);
          $data["accountUid"] = $project_details["accountUid"];
          $data["projectId"] = $provider_settings["project_id"];
          $firebaseConfigs[] = $data;
          $this->defaultCache
            ->set("tmgmt_smartling.firebase_config.{$provider_settings["project_id"]}", $data, time() + 3600, [
            "tmgmt_smartling:firebase_config:{$provider_settings["project_id"]}",
          ]);
        } catch (\Exception $e) {

          // Empty settings, can't fetch project details.
        }
      }
      else {
        $firebaseConfigs[] = $cachedData->data;
      }
    }
    return $firebaseConfigs;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FirebaseConfigManager::$apiWrapper protected property
FirebaseConfigManager::$defaultCache protected property
FirebaseConfigManager::getAvailableConfigs public function Returns array of available smartling providers with enabled notifications. Overrides SmartlingConfigManager::getAvailableConfigs
FirebaseConfigManager::setDefaultCache public function
FirebaseConfigManager::setSmartlingApiWrapper public function
SmartlingConfigManager::$configFactory protected property
SmartlingConfigManager::getConfigByProjectId public function Returns smartling provider config by project id.
SmartlingConfigManager::__construct public function SmartlingConfigManager constructor.