You are here

class TokenGetter in Access unpublished 8

Service to handle the current token.

Hierarchy

  • class \Drupal\access_unpublished\TokenGetter implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of TokenGetter

3 files declare their use of TokenGetter
AccessUnpublishedRouteLoad.php in src/Plugin/GraphQL/DataProducer/AccessUnpublishedRouteLoad.php
AccessUnpublishedTokenSet.php in src/Plugin/GraphQL/DataProducer/AccessUnpublishedTokenSet.php
AddHttpHeaders.php in src/EventSubscriber/AddHttpHeaders.php
1 string reference to 'TokenGetter'
access_unpublished.services.yml in ./access_unpublished.services.yml
access_unpublished.services.yml
1 service uses TokenGetter
access_unpublished.token_getter in ./access_unpublished.services.yml
Drupal\access_unpublished\TokenGetter

File

src/TokenGetter.php, line 13

Namespace

Drupal\access_unpublished
View source
class TokenGetter implements EventSubscriberInterface {

  /**
   * Access unpublished config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * The current token.
   *
   * @var string
   */
  protected $token;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $configFactory) {
    $this->config = $configFactory
      ->get('access_unpublished.settings');
  }

  /**
   * Get the current token.
   *
   * @return string
   *   The token.
   */
  public function getToken() {
    return $this->token;
  }

  /**
   * Set the current token.
   *
   * @param string $token
   *   The token.
   */
  public function setToken($token) {
    $this->token = $token;
  }

  /**
   * Set the token from the current request.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
   *   The request event.
   */
  public function setTokenFromRequest(GetResponseEvent $event) {
    $tokenKey = $this->config
      ->get('hash_key');
    if ($event
      ->getRequest()->query
      ->has($tokenKey)) {
      $this
        ->setToken($event
        ->getRequest()->query
        ->get($tokenKey));
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = [
      'setTokenFromRequest',
      50,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TokenGetter::$config protected property Access unpublished config.
TokenGetter::$token protected property The current token.
TokenGetter::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
TokenGetter::getToken public function Get the current token.
TokenGetter::setToken public function Set the current token.
TokenGetter::setTokenFromRequest public function Set the token from the current request.
TokenGetter::__construct public function