You are here

class PrivateKey in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/PrivateKey.php \Drupal\Core\PrivateKey

Manages the Drupal private key.

Hierarchy

Expanded class hierarchy of PrivateKey

4 files declare their use of PrivateKey
CsrfTokenGenerator.php in core/lib/Drupal/Core/Access/CsrfTokenGenerator.php
Contains \Drupal\Core\Access\CsrfTokenGenerator.
PermissionsHashGenerator.php in core/lib/Drupal/Core/Session/PermissionsHashGenerator.php
Contains \Drupal\Core\Session\PermissionsHashGenerator.
PrivateKeyTest.php in core/tests/Drupal/Tests/Core/PrivateKeyTest.php
Contains \Drupal\Tests\Core\PrivateKeyTest.
UpdateProcessor.php in core/modules/update/src/UpdateProcessor.php
Contains \Drupal\update\UpdateProcessor.
1 string reference to 'PrivateKey'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PrivateKey
private_key in core/core.services.yml
Drupal\Core\PrivateKey

File

core/lib/Drupal/Core/PrivateKey.php, line 16
Contains \Drupal\Core\PrivateKey.

Namespace

Drupal\Core
View source
class PrivateKey {

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

  /**
   * Constructs the token generator.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /**
   * Gets the private key.
   *
   * @return string
   *   The private key.
   */
  public function get() {
    if (!($key = $this->state
      ->get('system.private_key'))) {
      $key = $this
        ->create();
      $this
        ->set($key);
    }
    return $key;
  }

  /**
   * Sets the private key.
   *
   * @param string $key
   *  The private key to set.
   */
  public function set($key) {
    return $this->state
      ->set('system.private_key', $key);
  }

  /**
   * Creates a new private key.
   *
   * @return string
   *   The private key.
   */
  protected function create() {
    return Crypt::randomBytesBase64(55);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PrivateKey::$state protected property The state service.
PrivateKey::create protected function Creates a new private key.
PrivateKey::get public function Gets the private key.
PrivateKey::set public function Sets the private key.
PrivateKey::__construct function Constructs the token generator.