You are here

class BynderConfigHashGenerator in Bynder 8

Same name and namespace in other branches
  1. 8.3 src/EventSubscriber/BynderConfigHashGenerator.php \Drupal\bynder\EventSubscriber\BynderConfigHashGenerator
  2. 8.2 src/EventSubscriber/BynderConfigHashGenerator.php \Drupal\bynder\EventSubscriber\BynderConfigHashGenerator
  3. 4.0.x src/EventSubscriber/BynderConfigHashGenerator.php \Drupal\bynder\EventSubscriber\BynderConfigHashGenerator

A subscriber that generates Bynder config hash.

Hash is used to validate active user sessions.

Hierarchy

  • class \Drupal\bynder\EventSubscriber\BynderConfigHashGenerator implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of BynderConfigHashGenerator

1 string reference to 'BynderConfigHashGenerator'
bynder.services.yml in ./bynder.services.yml
bynder.services.yml
1 service uses BynderConfigHashGenerator
bynder.config_hash_generator in ./bynder.services.yml
Drupal\bynder\EventSubscriber\BynderConfigHashGenerator

File

src/EventSubscriber/BynderConfigHashGenerator.php, line 15

Namespace

Drupal\bynder\EventSubscriber
View source
class BynderConfigHashGenerator implements EventSubscriberInterface {

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * Constructs a BynderConfigHashGenerator object.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /**
   * Generates hash based on active Bynder config and saves it into state.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onChange(ConfigCrudEvent $event) {
    if (strpos($event
      ->getConfig()
      ->getName(), 'bynder.settings') === 0) {
      $hash_source = [];
      foreach ([
        'consumer_key',
        'consumer_secret',
        'token',
        'token_secret',
        'account_domain',
      ] as $key) {
        $hash_source[] = $event
          ->getConfig()
          ->get($key);
      }
      $this->state
        ->set('bynder_config_hash', md5(implode(':', $hash_source)));
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ConfigEvents::SAVE][] = [
      'onChange',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BynderConfigHashGenerator::$state protected property The state service.
BynderConfigHashGenerator::getSubscribedEvents public static function
BynderConfigHashGenerator::onChange public function Generates hash based on active Bynder config and saves it into state.
BynderConfigHashGenerator::__construct public function Constructs a BynderConfigHashGenerator object.