mirror of
https://github.com/getgrav/grav.git
synced 2026-03-01 18:11:25 +01:00
Flex storages: added support for custom key length
This commit is contained in:
@@ -34,6 +34,8 @@ abstract class AbstractFilesystemStorage implements FlexStorageInterface
|
||||
protected $dataFormatter;
|
||||
/** @var string */
|
||||
protected $keyField = 'storage_key';
|
||||
/** @var string */
|
||||
protected $keyLen = '32';
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
@@ -191,7 +193,7 @@ abstract class AbstractFilesystemStorage implements FlexStorageInterface
|
||||
*/
|
||||
protected function generateKey(): string
|
||||
{
|
||||
return substr(hash('sha256', random_bytes(32)), 0, 32);
|
||||
return substr(hash('sha256', random_bytes($this->keyLen)), 0, $this->keyLen);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -641,6 +641,7 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
$this->prefixed = (bool)($options['prefixed'] ?? strpos($pattern, '/{KEY:2}/'));
|
||||
$this->indexed = (bool)($options['indexed'] ?? false);
|
||||
$this->keyField = $options['key'] ?? 'storage_key';
|
||||
$this->keyLen = (int)($options['key_len'] ?? 32);
|
||||
|
||||
$variables = ['FOLDER' => '%1$s', 'KEY' => '%2$s', 'KEY:2' => '%3$s', 'FILE' => '%4$s', 'EXT' => '%5$s'];
|
||||
$pattern = Utils::simpleTemplate($pattern, $variables);
|
||||
|
||||
@@ -54,6 +54,7 @@ class SimpleStorage extends AbstractFilesystemStorage
|
||||
$this->dataPattern = basename($pattern, $extension) . $extension;
|
||||
$this->dataFolder = $filesystem->dirname($options['folder']);
|
||||
$this->keyField = $options['key'] ?? 'storage_key';
|
||||
$this->keyLen = (int)($options['key_len'] ?? 32);
|
||||
$this->prefix = $options['prefix'] ?? null;
|
||||
|
||||
// Make sure that the data folder exists.
|
||||
|
||||
Reference in New Issue
Block a user