You are here

class SerializableTempstoreFactory in Chaos Tool Suite (ctools) 8.3

A factory for creating SerializableTempStore objects.

Hierarchy

Expanded class hierarchy of SerializableTempstoreFactory

1 string reference to 'SerializableTempstoreFactory'
ctools.services.yml in ./ctools.services.yml
ctools.services.yml
1 service uses SerializableTempstoreFactory
ctools.serializable.tempstore.factory in ./ctools.services.yml
Drupal\ctools\SerializableTempstoreFactory

File

src/SerializableTempstoreFactory.php, line 14

Namespace

Drupal\ctools
View source
class SerializableTempstoreFactory extends SharedTempStoreFactory {

  /**
   * The current logged user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * Constructs a Drupal\Core\TempStore\SharedTempStoreFactory object.
   *
   * @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $storage_factory
   *   The key/value store factory.
   * @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
   *   The lock object used for this data.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   * @param int $expire
   *   The time to live for items, in seconds.
   * @param \Drupal\Core\Session\AccountProxyInterface|null $current_user
   *   The current logged user.
   */
  public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $expire = 604800, AccountProxyInterface $current_user = NULL) {
    parent::__construct($storage_factory, $lock_backend, $request_stack, $expire);
    $this->currentUser = $current_user ?: \Drupal::currentUser();
  }

  /**
   * {@inheritdoc}
   */
  public function get($collection, $owner = NULL) {

    // Use the currently authenticated user ID or the active user ID unless the
    // owner is overridden.
    if (!isset($owner)) {
      $owner = $this->currentUser
        ->id() ?: session_id();
    }

    // Store the data for this collection in the database.
    $storage = $this->storageFactory
      ->get("tempstore.shared.{$collection}");
    return new SerializableTempstore($storage, $this->lockBackend, $owner, $this->requestStack, $this->expire);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SerializableTempstoreFactory::$currentUser protected property The current logged user.
SerializableTempstoreFactory::get public function Creates a SharedTempStore for the current user or anonymous session. Overrides SharedTempStoreFactory::get
SerializableTempstoreFactory::__construct public function Constructs a Drupal\Core\TempStore\SharedTempStoreFactory object. Overrides SharedTempStoreFactory::__construct
SharedTempStoreFactory::$expire protected property The time to live for items in seconds.
SharedTempStoreFactory::$lockBackend protected property The lock object used for this data.
SharedTempStoreFactory::$requestStack protected property The request stack.
SharedTempStoreFactory::$storageFactory protected property The storage factory creating the backend to store the data.