You are here

abstract class SalesforceCommandsBase in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 src/Commands/SalesforceCommandsBase.php \Drupal\salesforce\Commands\SalesforceCommandsBase
  2. 5.0.x src/Commands/SalesforceCommandsBase.php \Drupal\salesforce\Commands\SalesforceCommandsBase

Shared command base for Salesforce Drush commands.

Hierarchy

Expanded class hierarchy of SalesforceCommandsBase

1 file declares its use of SalesforceCommandsBase
SalesforceMappingCommandsBase.php in modules/salesforce_mapping/src/Commands/SalesforceMappingCommandsBase.php

File

src/Commands/SalesforceCommandsBase.php, line 18

Namespace

Drupal\salesforce\Commands
View source
abstract class SalesforceCommandsBase extends DrushCommands {

  /**
   * The Salesforce client.
   *
   * @var \Drupal\salesforce\Rest\RestClient
   */
  protected $client;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $etm;

  /**
   * Salesforce Auth Provider plugin manager service.
   *
   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
   */
  protected $authMan;

  /**
   * Salesforce Auth Token Storage service.
   *
   * @var \Drupal\salesforce\Storage\SalesforceAuthTokenStorageInterface
   */
  protected $tokenStorage;

  /**
   * SalesforceCommandsBase constructor.
   *
   * @param \Drupal\salesforce\Rest\RestClient $client
   *   SF client.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $etm
   *   Entity type manager.
   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authMan
   *   Auth plugin manager.
   * @param \Drupal\salesforce\Storage\SalesforceAuthTokenStorageInterface $tokenStorage
   *   Token storage.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(RestClient $client, EntityTypeManagerInterface $etm, SalesforceAuthProviderPluginManagerInterface $authMan, SalesforceAuthTokenStorageInterface $tokenStorage) {
    $this->client = $client;
    $this->etm = $etm;
    $this->authMan = $authMan;
    $this->tokenStorage = $tokenStorage;
  }

  /**
   * Collect a salesforce object name, and set it to "object" argument.
   *
   * NB: there's no actual validation done here against Salesforce objects.
   * If there's a way to attach multiple hooks to one method, please patch this.
   */
  protected function interactObject(Input $input, Output $output, $message = 'Choose a Salesforce object name') {
    if (!$input
      ->getArgument('object')) {
      $objects = $this->client
        ->objects();
      if (!($answer = $this
        ->io()
        ->choice($message, array_combine(array_keys($objects), array_keys($objects))))) {
        throw new UserAbortException();
      }
      $input
        ->setArgument('object', $answer);
    }
  }

  /**
   * Pass-through helper to add appropriate formatters for a query result.
   *
   * @param \Drupal\salesforce\Commands\QueryResult $query
   *   The query result.
   *
   * @return \Drupal\salesforce\Commands\QueryResult
   *   The same, unchanged query result.
   */
  protected function returnQueryResult(QueryResult $query) {
    $formatter = new QueryResultTableFormatter();
    $formatterManager = Drush::getContainer()
      ->get('formatterManager');
    $formatterManager
      ->addFormatter('table', $formatter);
    return $query;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SalesforceCommandsBase::$authMan protected property Salesforce Auth Provider plugin manager service. 1
SalesforceCommandsBase::$client protected property The Salesforce client.
SalesforceCommandsBase::$etm protected property The entity type manager.
SalesforceCommandsBase::$tokenStorage protected property Salesforce Auth Token Storage service. 1
SalesforceCommandsBase::interactObject protected function Collect a salesforce object name, and set it to "object" argument.
SalesforceCommandsBase::returnQueryResult protected function Pass-through helper to add appropriate formatters for a query result. 1
SalesforceCommandsBase::__construct public function SalesforceCommandsBase constructor. 1