class PrivateKey in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/PrivateKey.php \Drupal\Core\PrivateKey
Manages the Drupal private key.
Hierarchy
- class \Drupal\Core\PrivateKey
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
File
- core/
lib/ Drupal/ Core/ PrivateKey.php, line 16 - Contains \Drupal\Core\PrivateKey.
Namespace
Drupal\CoreView 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
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:: |
function | Constructs the token generator. |