public function OAuthKey::write in Lightning API 8
Same name and namespace in other branches
- 8.4 src/OAuthKey.php \Drupal\lightning_api\OAuthKey::write()
- 8.2 src/OAuthKey.php \Drupal\lightning_api\OAuthKey::write()
- 8.3 src/OAuthKey.php \Drupal\lightning_api\OAuthKey::write()
Writes a key to the file system.
Parameters
string $destination: The desired destination of the key. Can be a directory or a full path.
string $key: The data to write.
Return value
string The final path of the written key.
Throws
\RuntimeException if an I/O error occurred while writing the key.
File
- src/
OAuthKey.php, line 87
Class
Namespace
Drupal\lightning_apiCode
public function write($destination, $key) {
$destination = rtrim($destination, '/');
if (is_dir($destination)) {
$destination .= '/' . hash('sha256', $key) . '.key';
}
if (file_put_contents($destination, $key)) {
$this->fileSystem
->chmod($destination, static::PERMISSIONS);
return $destination;
}
else {
throw new \RuntimeException('The key could not be written.');
}
}