PageStorage
extends FolderStorage
in package
Class GravPageStorage
Table of Contents
Properties
- $base_path : string
- $caseSensitive : bool
- $dataExt : string
- $dataFile : string
- $dataFolder : string
- $dataFormatter : FileFormatterInterface
- $dataPattern : string
- $flags : int
- $ignore_files : array<string|int, mixed>
- $ignore_folders : array<string|int, mixed>
- $ignore_hidden : bool
- $include_default_lang_file_extension : bool
- $indexed : bool
- $keyField : string
- $keyLen : int
- $meta : array<string|int, mixed>
- $prefixed : bool
- $recurse : bool
- $regex : string
- $variables : array<string|int, string>
Methods
- __construct() : mixed
- StorageInterface constructor.
- buildFilename() : string
- buildFilepath() : string
- buildFolder() : string
- 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>
- getPathFromKey() : string
- Get filesystem path from the key.
- 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>
- readFrontmatter() : string
- readRaw() : string
- 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.
- buildIndexFromFilesystem() : array<string|int, mixed>
- buildPrefixedIndexFromFilesystem() : array<string|int, mixed>
- canDeleteFolder() : bool
- Check if page folder should be deleted.
- copyFolder() : bool
- deleteFile() : array<string|int, mixed>|string
- deleteFolder() : bool
- detectDataFormatter() : string|null
- generateKey() : string
- Generates a random, unique key for the row.
- getFile() : CompiledJsonFile|CompiledYamlFile|CompiledMarkdownFile
- getIndexMeta() : array<string|int, mixed>
- getKeyFromPath() : string
- Get key from the filesystem path.
- getNewKey() : string
- getObjectMeta() : array<string|int, mixed>
- initDataFormatter() : void
- initOptions() : void
- loadRow() : array<string|int, mixed>
- moveFolder() : bool
- parseParams() : array<string|int, mixed>
- prepareRow() : void
- Prepares the row for saving and returns the storage key for the record.
- resolvePath() : string
- saveRow() : array<string|int, mixed>
- Page storage supports moving and copying the pages and their languages.
- validateKey() : bool
- Checks if a key is valid.
Properties
$base_path
protected
string
$base_path
$caseSensitive
protected
bool
$caseSensitive
= true
$dataExt
protected
string
$dataExt
File extension for the object.
$dataFile
protected
string
$dataFile
Filename for the object.
$dataFolder
protected
string
$dataFolder
Folder where all the data is stored.
$dataFormatter
protected
FileFormatterInterface
$dataFormatter
$dataPattern
protected
string
$dataPattern
= '{FOLDER}/{KEY}/{FILE}{EXT}'
Pattern to access an object.
$flags
protected
int
$flags
$ignore_files
protected
array<string|int, mixed>
$ignore_files
$ignore_folders
protected
array<string|int, mixed>
$ignore_folders
$ignore_hidden
protected
bool
$ignore_hidden
$include_default_lang_file_extension
protected
bool
$include_default_lang_file_extension
$indexed
protected
bool
$indexed
$keyField
protected
string
$keyField
= 'storage_key'
$keyLen
protected
int
$keyLen
= 32
$meta
protected
array<string|int, mixed>
$meta
= []
$prefixed
protected
bool
$prefixed
$recurse
protected
bool
$recurse
$regex
protected
string
$regex
$variables
protected
array<string|int, string>
$variables
= ['FOLDER' => '%1$s', 'KEY' => '%2$s', 'KEY:2' => '%3$s', 'FILE' => '%4$s', 'EXT' => '%5$s']
Methods
__construct()
StorageInterface constructor.
public
__construct(array<string|int, mixed> $options) : mixed
Parameters
- $options : array<string|int, mixed>
buildFilename()
public
buildFilename(array<string|int, mixed> $keys) : string
Parameters
- $keys : array<string|int, mixed>
Return values
stringbuildFilepath()
public
buildFilepath(array<string|int, mixed> $keys) : string
Parameters
- $keys : array<string|int, mixed>
Return values
stringbuildFolder()
public
buildFolder(array<string|int, mixed> $keys) : string
Parameters
- $keys : array<string|int, mixed>
Return values
stringbuildStorageKey()
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
Tags
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[, bool $setDefaultLang = true ]) : array<string|int, mixed>
Parameters
- $row : array<string|int, mixed>
- $setDefaultLang : bool = true
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>getPathFromKey()
Get filesystem path from the key.
public
getPathFromKey(string $key) : string
Parameters
- $key : string
Return values
stringgetStoragePath()
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>readFrontmatter()
public
readFrontmatter(string $key) : string
Parameters
- $key : string
Return values
stringreadRaw()
public
readRaw(string $key) : string
Parameters
- $key : string
Return values
stringreadRows()
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>buildIndexFromFilesystem()
protected
buildIndexFromFilesystem(string $path) : array<string|int, mixed>
Parameters
- $path : string
Return values
array<string|int, mixed>buildPrefixedIndexFromFilesystem()
protected
buildPrefixedIndexFromFilesystem(string $path) : array<string|int, mixed>
Parameters
- $path : string
Return values
array<string|int, mixed>canDeleteFolder()
Check if page folder should be deleted.
protected
canDeleteFolder(string $key) : bool
Deleting page can be done either by deleting everything or just a single language. If key contains the language, delete only it, unless it is the last language.
Parameters
- $key : string
Return values
boolcopyFolder()
protected
copyFolder(string $src, string $dst) : bool
Parameters
- $src : string
- $dst : string
Return values
booldeleteFile()
protected
deleteFile(File $file) : array<string|int, mixed>|string
Parameters
- $file : File
Return values
array<string|int, mixed>|stringdeleteFolder()
protected
deleteFolder(string $path[, bool $include_target = false ]) : bool
Parameters
- $path : string
- $include_target : bool = false
Return values
booldetectDataFormatter()
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|CompiledMarkdownFilegetIndexMeta()
protected
getIndexMeta() : array<string|int, mixed>
Return values
array<string|int, mixed>getKeyFromPath()
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>
initOptions()
protected
initOptions(array<string|int, mixed> $options) : void
Parameters
- $options : array<string|int, mixed>
loadRow()
protected
loadRow(string $key) : array<string|int, mixed>
Parameters
- $key : string
Return values
array<string|int, mixed>moveFolder()
protected
moveFolder(string $src, string $dst) : bool
Parameters
- $src : string
- $dst : string
Return values
boolparseParams()
protected
parseParams(string $key, string $params) : array<string|int, mixed>
Parameters
- $key : string
- $params : 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
stringsaveRow()
Page storage supports moving and copying the pages and their languages.
protected
saveRow(string $key, array<string|int, mixed> $row) : array<string|int, mixed>
$row['__META']['copy'] = true Use this if you want to copy the whole folder, otherwise it will be moved $row['__META']['clone'] = true Use this if you want to clone the file, otherwise it will be renamed
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