You are here

class TwitterPostCollectorFactory in Social Feed 8

Class TwitterPostCollectorFactory.

@package Drupal\socialfeed\Services

Hierarchy

Expanded class hierarchy of TwitterPostCollectorFactory

1 file declares its use of TwitterPostCollectorFactory
TwitterPostBlock.php in src/Plugin/Block/TwitterPostBlock.php
1 string reference to 'TwitterPostCollectorFactory'
socialfeed.services.yml in ./socialfeed.services.yml
socialfeed.services.yml
1 service uses TwitterPostCollectorFactory
socialfeed.twitter in ./socialfeed.services.yml
Drupal\socialfeed\Services\TwitterPostCollectorFactory

File

src/Services/TwitterPostCollectorFactory.php, line 12

Namespace

Drupal\socialfeed\Services
View source
class TwitterPostCollectorFactory {

  /**
   * The default consumer key.
   *
   * @var string
   */
  protected $defaultConsumerKey;

  /**
   * The default consumer secret.
   *
   * @var string
   */
  protected $defaultConsumerSecret;

  /**
   * The default access token.
   *
   * @var string
   */
  protected $defaultAccessToken;

  /**
   * The default access token secret.
   *
   * @var string
   */
  protected $defaultAccessTokenSecret;

  /**
   * TwitterPostCollectorFactory constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $configFactory) {
    $config = $configFactory
      ->get('socialfeed.twittersettings');
    $this->defaultConsumerKey = $config
      ->get('consumer_key');
    $this->defaultConsumerSecret = $config
      ->get('consumer_secret');
    $this->defaultAccessToken = $config
      ->get('access_token');
    $this->defaultAccessTokenSecret = $config
      ->get('access_token_secret');
  }

  /**
   * Creates a pre-configured instance.
   *
   * @param string $consumerKey
   *   The consumer key.
   * @param string $consumerSecret
   *   The consumer secret.
   * @param string $accessToken
   *   The access token.
   * @param string $accessTokenSecret
   *   The access token secret.
   *
   * @return \Drupal\socialfeed\Services\TwitterPostCollector
   *   A fully configured instance from TwitterPostCollector.
   *
   * @throws \Exception
   *   If the instance cannot be created, such as if the ID is invalid.
   */
  public function createInstance(string $consumerKey, string $consumerSecret, string $accessToken, string $accessTokenSecret) {
    return new TwitterPostCollector($consumerKey ?: $this->defaultConsumerKey, $consumerSecret ?: $this->defaultConsumerSecret, $accessToken ?: $this->defaultAccessToken, $accessTokenSecret ?: $this->defaultAccessTokenSecret);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TwitterPostCollectorFactory::$defaultAccessToken protected property The default access token.
TwitterPostCollectorFactory::$defaultAccessTokenSecret protected property The default access token secret.
TwitterPostCollectorFactory::$defaultConsumerKey protected property The default consumer key.
TwitterPostCollectorFactory::$defaultConsumerSecret protected property The default consumer secret.
TwitterPostCollectorFactory::createInstance public function Creates a pre-configured instance.
TwitterPostCollectorFactory::__construct public function TwitterPostCollectorFactory constructor.