class PrivateKey in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/PrivateKey.php \Drupal\Core\PrivateKey
Manages the Drupal private key.
Hierarchy
- class \Drupal\Core\PrivateKey
Expanded class hierarchy of PrivateKey
7 files declare their use of PrivateKey
- CsrfTokenGenerator.php in core/
lib/ Drupal/ Core/ Access/ CsrfTokenGenerator.php - IFrameUrlHelper.php in core/
modules/ media/ src/ IFrameUrlHelper.php - IFrameUrlHelperTest.php in core/
modules/ media/ tests/ src/ Unit/ IFrameUrlHelperTest.php - PermissionsHashGenerator.php in core/
lib/ Drupal/ Core/ Session/ PermissionsHashGenerator.php - PrivateKeyTest.php in core/
tests/ Drupal/ Tests/ Core/ PrivateKeyTest.php
1 string reference to 'PrivateKey'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses PrivateKey
File
- core/
lib/ Drupal/ Core/ PrivateKey.php, line 11
Namespace
Drupal\CoreView source
class PrivateKey {
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* Constructs the private key object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrivateKey:: |
protected | property | The state service. | |
PrivateKey:: |
protected | function | Creates a new private key. | |
PrivateKey:: |
public | function | Gets the private key. | |
PrivateKey:: |
public | function | Sets the private key. | |
PrivateKey:: |
public | function | Constructs the private key object. |