You are here

class InstagramPostCollectorFactory in Social Feed 8

Class InstagramPostCollectorFactory.

@package Drupal\socialfeed

Hierarchy

Expanded class hierarchy of InstagramPostCollectorFactory

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

File

src/Services/InstagramPostCollectorFactory.php, line 12

Namespace

Drupal\socialfeed\Services
View source
class InstagramPostCollectorFactory {

  /**
   * Default Instagram application api key.
   *
   * @var string
   */
  protected $defaultApiKey;

  /**
   * Default Instagram application api secret.
   *
   * @var string
   */
  protected $defaultApiSecret;

  /**
   * Default Instagram redirect URI.
   *
   * @var string
   */
  protected $defaultRedirectUri;

  /**
   * Default Instagram application access token.
   *
   * @var string
   */
  protected $defaultAccessToken;

  /**
   * InstagramPostCollectorFactory constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   Config factory.
   */
  public function __construct(ConfigFactoryInterface $configFactory) {
    $config = $configFactory
      ->get('socialfeed.instagramsettings');
    $this->defaultApiKey = $config
      ->get('client_id');
    $this->defaultApiSecret = $config
      ->get('api_secret');
    $this->defaultRedirectUri = $config
      ->get('redirect_uri');
    $this->defaultAccessToken = $config
      ->get('access_token');
  }

  /**
   * Creates a pre-configured instance.
   *
   * @param string $apiKey
   *   The API Key.
   * @param string $apiSecret
   *   The API Secret.
   * @param string $redirectUri
   *   The Redirect URI.
   * @param string $accessToken
   *   The access token.
   *
   * @return \Drupal\socialfeed\Services\InstagramPostCollector
   *   A fully configured instance from InstagramPostCollector.
   *
   * @throws \Exception
   *   If the instance cannot be created, such as if the ID is invalid.
   */
  public function createInstance(string $apiKey, string $apiSecret, string $redirectUri, string $accessToken) {
    return new InstagramPostCollector($apiKey ?: $this->defaultApiKey, $apiSecret ?: $this->defaultApiSecret, $redirectUri ?: $this->defaultRedirectUri, $accessToken ?: $this->defaultAccessToken);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InstagramPostCollectorFactory::$defaultAccessToken protected property Default Instagram application access token.
InstagramPostCollectorFactory::$defaultApiKey protected property Default Instagram application api key.
InstagramPostCollectorFactory::$defaultApiSecret protected property Default Instagram application api secret.
InstagramPostCollectorFactory::$defaultRedirectUri protected property Default Instagram redirect URI.
InstagramPostCollectorFactory::createInstance public function Creates a pre-configured instance.
InstagramPostCollectorFactory::__construct public function InstagramPostCollectorFactory constructor.