You are here

class DrupalApplication in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/SyncCoreInterface/DrupalApplication.php \Drupal\cms_content_sync\SyncCoreInterface\DrupalApplication
  2. 2.0.x src/SyncCoreInterface/DrupalApplication.php \Drupal\cms_content_sync\SyncCoreInterface\DrupalApplication

Class DrupalApplication.

Implement the ApplicationInterface to provide basic information about this site to the Sync Core. Must be provided to all client instances to communicate with the Sync Core.

Hierarchy

  • class \Drupal\cms_content_sync\SyncCoreInterface\DrupalApplication implements \EdgeBox\SyncCore\Interfaces\IApplicationInterface

Expanded class hierarchy of DrupalApplication

3 files declare their use of DrupalApplication
EntityResource.php in src/Plugin/rest/resource/EntityResource.php
ManualPull.php in src/Controller/ManualPull.php
SyncHealth.php in modules/cms_content_sync_health/src/Controller/SyncHealth.php

File

src/SyncCoreInterface/DrupalApplication.php, line 15

Namespace

Drupal\cms_content_sync\SyncCoreInterface
View source
class DrupalApplication implements IApplicationInterface {

  /**
   * @var string APPLICATION_ID Unique ID to identify the kind of application
   */
  public const APPLICATION_ID = 'drupal';

  /**
   * @var \DrupalApplication
   */
  protected static $instance;

  /**
   * @return \DrupalApplication
   */
  public static function get() {
    if (!empty(self::$instance)) {
      return self::$instance;
    }
    return self::$instance = new DrupalApplication();
  }

  /**
   * {@inheritdoc}
   */
  public function getSiteBaseUrl() {
    return ContentSyncSettings::getInstance()
      ->getSiteBaseUrl();
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthentication() {
    $type = ContentSyncSettings::getInstance()
      ->getAuthenticationType();
    $authentication_provider = AuthenticationByUser::getInstance();
    return [
      'type' => $type,
      'username' => $authentication_provider
        ->getUsername(),
      'password' => $authentication_provider
        ->getPassword(),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getRestUrl($pool_id, $type_machine_name, $bundle_machine_name, $version_id, $entity_uuid = null, $manually = null, $as_dependency = null) {
    $export_url = $this
      ->getSiteBaseUrl();
    $url = sprintf('%s/rest/cms-content-sync/%s/%s/%s/%s', $export_url, $pool_id, $type_machine_name, $bundle_machine_name, $version_id);
    if ($entity_uuid) {
      $url .= '/' . $entity_uuid;
    }
    $url .= '?_format=json';
    if ($as_dependency) {
      $url .= '&is_dependency=' . $as_dependency;
    }
    if ($manually) {
      $url .= '&is_manual=' . $manually;
    }
    return $url;
  }

  /**
   * {@inheritdoc}
   */
  public function getSiteName() {
    return ContentSyncSettings::getInstance()
      ->getSiteName();
  }

  /**
   * {@inheritdoc}
   */
  public function setSiteId($set) {
    ContentSyncSettings::getInstance()
      ->setSiteId($set);
  }

  /**
   * {@inheritdoc}
   */
  public function getSiteMachineName() {
    return ContentSyncSettings::getInstance()
      ->getSiteMachineName();
  }

  /**
   * {@inheritdoc}
   */
  public function setSiteMachineName($set) {
    ContentSyncSettings::getInstance()
      ->setSiteMachineName($set);
  }

  /**
   * {@inheritdoc}
   */
  public function getSiteId() {
    return ContentSyncSettings::getInstance()
      ->getSiteMachineName();
  }

  /**
   * {@inheritdoc}
   */
  public function getApplicationId() {
    return self::APPLICATION_ID;
  }

  /**
   * {@inheritdoc}
   */
  public function getApplicationVersion() {
    return '8.x';
  }

  /**
   * {@inheritdoc}
   */
  public function getApplicationModuleVersion() {
    $version = \Drupal::service('extension.list.module')
      ->getExtensionInfo('cms_content_sync')['version'];
    return $version ? $version : 'dev';
  }

  /**
   * {@inheritdoc}
   */
  public function getHttpClient() {
    return \Drupal::httpClient();
  }

  /**
   * {@inheritdoc}
   */
  public function getHttpOptions() {
    $options = [];

    // Allow to set a custom timeout for Sync Core requests.
    global $config;
    $config_name = 'cms_content_sync.sync_core_request_timeout';
    if (!empty($config[$config_name]) && is_int($config[$config_name])) {
      $options['timeout'] = $config[$config_name];
    }
    return $options;
  }

}

Members