SimpleStorage
extends AbstractFilesystemStorage
in package
Class SimpleStorage
Table of Contents
Properties
- $caseSensitive : bool
- $data : array<string|int, mixed>|null
- $dataFolder : string
- $dataFormatter : FileFormatterInterface
- $dataPattern : string
- $keyField : string
- $keyLen : int
- $modified : int
- $prefix : string|null
Methods
- __construct() : mixed
- StorageInterface constructor.
- buildStorageKey() : string
- buildStorageKeyParams() : string
- clearCache() : void
- copyRow() : bool
- createRows() : array<string|int, mixed>
- Create new rows into the storage.
- deleteRows() : array<string|int, mixed>
- Delete rows from the storage.
- extractKeysFromRow() : array<string|int, mixed>
- extractKeysFromStorageKey() : array<string|int, mixed>
- getExistingKeys() : array<string|int, mixed>
- Returns associated array of all existing storage keys with a timestamp.
- getKeyField() : string
- getMediaPath() : string|null
- Get filesystem path for the collection or object media.
- getMetaData() : array<string|int, mixed>
- getStoragePath() : string|null
- Get filesystem path for the collection or object storage.
- hasKey() : bool
- Check if the key exists in the storage.
- hasKeys() : array<string|int, bool>
- Check if the key exists in the storage.
- isIndexed() : bool
- normalizeKey() : string
- parseKey() : array<string|int, mixed>
- readRows() : array<string|int, mixed>
- Read rows from the storage.
- renameRow() : bool
- replaceRows() : array<string|int, mixed>
- Replace rows regardless if they exist or not.
- updateRows() : array<string|int, mixed>
- Update existing rows in the storage.
- buildIndex() : array<string|int, mixed>
- Returns list of all stored keys in [key => timestamp] pairs.
- detectDataFormatter() : string|null
- generateKey() : string
- Generates a random, unique key for the row.
- getFile() : CompiledJsonFile|CompiledYamlFile|CompiledMarkdownFile
- getKeyFromPath() : string
- Get key from the filesystem path.
- getNewKey() : string
- getObjectMeta() : array<string|int, mixed>
- initDataFormatter() : void
- loadRow() : array<string|int, mixed>
- prepareRow() : void
- Prepares the row for saving and returns the storage key for the record.
- resolvePath() : string
- save() : void
- saveRow() : array<string|int, mixed>
- validateKey() : bool
- Checks if a key is valid.
Properties
$caseSensitive
protected
bool
$caseSensitive
= true
$data
protected
array<string|int, mixed>|null
$data
$dataFolder
protected
string
$dataFolder
$dataFormatter
protected
FileFormatterInterface
$dataFormatter
$dataPattern
protected
string
$dataPattern
$keyField
protected
string
$keyField
= 'storage_key'
$keyLen
protected
int
$keyLen
= 32
$modified
protected
int
$modified
= 0
$prefix
protected
string|null
$prefix
Methods
__construct()
StorageInterface constructor.
public
__construct(array<string|int, mixed> $options) : mixed
Parameters
- $options : array<string|int, mixed>
Tags
buildStorageKey()
public
buildStorageKey(array<string|int, mixed> $keys[, bool $includeParams = true ]) : string
Parameters
- $keys : array<string|int, mixed>
- $includeParams : bool = true
Return values
stringbuildStorageKeyParams()
public
buildStorageKeyParams(array<string|int, mixed> $keys) : string
Parameters
- $keys : array<string|int, mixed>
Return values
stringclearCache()
public
clearCache() : void
copyRow()
public
copyRow(string $src, string $dst) : bool
Parameters
- $src : string
- $dst : string
Return values
boolcreateRows()
Create new rows into the storage.
public
createRows(array<string|int, mixed> $rows) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
-
List of rows as
[row, ...].
Tags
Return values
array<string|int, mixed> —Returns created rows as `[key => row, ...] pairs.
deleteRows()
Delete rows from the storage.
public
deleteRows(array<string|int, mixed> $rows) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
-
Array of
[key => row, ...]pairs.
Tags
Return values
array<string|int, mixed> —Returns deleted rows. Note that non-existing rows have null as their value.
extractKeysFromRow()
public
extractKeysFromRow(array<string|int, mixed> $row) : array<string|int, mixed>
Parameters
- $row : array<string|int, mixed>
Return values
array<string|int, mixed>extractKeysFromStorageKey()
public
extractKeysFromStorageKey(string $key) : array<string|int, mixed>
Parameters
- $key : string
Return values
array<string|int, mixed>getExistingKeys()
Returns associated array of all existing storage keys with a timestamp.
public
getExistingKeys() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Returns all existing keys as [key => [storage_key => key, storage_timestamp => timestamp], ...].
getKeyField()
public
getKeyField() : string
Tags
Return values
stringgetMediaPath()
Get filesystem path for the collection or object media.
public
getMediaPath([string $key = null ]) : string|null
Parameters
- $key : string = null
-
Optional storage key.
Tags
Return values
string|null —Path in the filesystem. Can be URI or null if media isn't supported.
getMetaData()
public
getMetaData(array<string|int, string> $keys[, bool $reload = false ]) : array<string|int, mixed>
Parameters
- $keys : array<string|int, string>
- $reload : bool = false
Return values
array<string|int, mixed>getStoragePath()
Get filesystem path for the collection or object storage.
public
getStoragePath([string $key = null ]) : string|null
Parameters
- $key : string = null
-
Optional storage key.
Tags
Return values
string|null —Path in the filesystem. Can be URI or null if storage is not filesystem based.
hasKey()
Check if the key exists in the storage.
public
hasKey(string $key) : bool
Parameters
- $key : string
-
Storage key of an object.
Tags
Return values
bool —Returns true if the key exists in the storage, false otherwise.
hasKeys()
Check if the key exists in the storage.
public
hasKeys(array<string|int, mixed> $keys) : array<string|int, bool>
Parameters
- $keys : array<string|int, mixed>
-
Storage key of an object.
Tags
Return values
array<string|int, bool> —Returns keys with true if the key exists in the storage, false otherwise.
isIndexed()
public
isIndexed() : bool
Return values
boolnormalizeKey()
public
normalizeKey(string $key) : string
Parameters
- $key : string
Return values
stringparseKey()
public
parseKey(string $key[, bool $variations = true ]) : array<string|int, mixed>
Parameters
- $key : string
- $variations : bool = true
Return values
array<string|int, mixed>readRows()
Read rows from the storage.
public
readRows(array<string|int, mixed> $rows[, array<string|int, mixed> &$fetched = null ]) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
-
Array of
[key => row, ...]pairs. - $fetched : array<string|int, mixed> = null
-
Optional reference to store only fetched items.
Tags
Return values
array<string|int, mixed> —Returns rows. Note that non-existing rows will have null as their value.
renameRow()
public
renameRow(string $src, string $dst) : bool
Parameters
- $src : string
- $dst : string
Tags
Return values
boolreplaceRows()
Replace rows regardless if they exist or not.
public
replaceRows(array<string|int, mixed> $rows) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
-
Array of
[key => row, ...]pairs.
Tags
Return values
array<string|int, mixed> —Returns both created and updated rows.
updateRows()
Update existing rows in the storage.
public
updateRows(array<string|int, mixed> $rows) : array<string|int, mixed>
Parameters
- $rows : array<string|int, mixed>
-
Array of
[key => row, ...]pairs.
Tags
Return values
array<string|int, mixed> —Returns updated rows. Note that non-existing rows will not be saved and have null as their value.
buildIndex()
Returns list of all stored keys in [key => timestamp] pairs.
protected
buildIndex() : array<string|int, mixed>
Return values
array<string|int, mixed>detectDataFormatter()
protected
detectDataFormatter(string $filename) : string|null
Parameters
- $filename : string
Return values
string|nullgenerateKey()
Generates a random, unique key for the row.
protected
generateKey() : string
Return values
stringgetFile()
protected
getFile(string $filename) : CompiledJsonFile|CompiledYamlFile|CompiledMarkdownFile
Parameters
- $filename : string
Return values
CompiledJsonFile|CompiledYamlFile|CompiledMarkdownFilegetKeyFromPath()
Get key from the filesystem path.
protected
getKeyFromPath(string $path) : string
Parameters
- $path : string
Return values
stringgetNewKey()
protected
getNewKey() : string
Return values
stringgetObjectMeta()
protected
getObjectMeta(string $key[, bool $reload = false ]) : array<string|int, mixed>
Parameters
- $key : string
- $reload : bool = false
Return values
array<string|int, mixed>initDataFormatter()
protected
initDataFormatter(string|array<string|int, mixed> $formatter) : void
Parameters
- $formatter : string|array<string|int, mixed>
loadRow()
protected
loadRow(string $key) : array<string|int, mixed>
Parameters
- $key : string
Return values
array<string|int, mixed>prepareRow()
Prepares the row for saving and returns the storage key for the record.
protected
prepareRow(array<string|int, mixed> &$row) : void
Parameters
- $row : array<string|int, mixed>
resolvePath()
protected
resolvePath(string $path) : string
Parameters
- $path : string
Return values
stringsave()
protected
save() : void
saveRow()
protected
saveRow(string $key, array<string|int, mixed> $row) : array<string|int, mixed>
Parameters
- $key : string
- $row : array<string|int, mixed>
Return values
array<string|int, mixed>validateKey()
Checks if a key is valid.
protected
validateKey(string $key) : bool
Parameters
- $key : string