Storages
in package
Represents a collection of storage objects.
This class manages multiple storage objects and provides methods to interact with them collectively.
Tags
Table of Contents
Properties
- $_storages : array<string|int, mixed>|null
- Array of storage data.
- $_types : array<string|int, mixed>|null
- Types of storages.
- $instance : Storages|null
- The singleton instance of the Storages class.
Methods
- __construct() : mixed
- Constructs a Storages object.
- __get() : mixed
- Magic method to retrieve the value of inaccessible properties.
- Create() : Storages
- Singleton
- Exists() : bool
- Checks if a storage with the specified name exists.
- GetStorages() : array<string|int, mixed>
- Retrieves an array of all storages.
- Load() : Storage|null
- Loads the storage with the specified name and optional module.
- Migrate() : void
- Migrates storage tables and fields.
- _alterStorageField() : void
- Alters an existing storage field.
- _alterStorageIndex() : void
- Alters an existing storage index.
- _alterStorageVirtualField() : void
- Alters an existing virtual storage field.
- _createStorageField() : void
- Creates a new storage field.
- _createStorageIndex() : void
- Creates a new storage index.
- _createStorageTable() : void
- Creates a new storage table.
- _createStorageVirtualField() : void
- Creates a new virtual storage field.
- _fromShortString() : array<string|int, mixed>
- Extracts a short field record
- _replaceTypes() : array<string|int, mixed>
- Replaces a global types
- _updateDefaultAndLength() : array<string|int, mixed>
- Updates the default value and length of a storage field.
Properties
$_storages
Array of storage data.
private
array<string|int, mixed>|null
$_storages
= null
$_types
Types of storages.
private
array<string|int, mixed>|null
$_types
= null
$instance
The singleton instance of the Storages class.
private
static Storages|null
$instance
Methods
__construct()
Constructs a Storages object.
public
__construct() : mixed
__get()
Magic method to retrieve the value of inaccessible properties.
public
__get(string $prop) : mixed
Parameters
- $prop : string
-
The name of the property to retrieve.
Return values
mixed —The value of the specified property.
Create()
Singleton
public
static Create() : Storages
Return values
StoragesExists()
Checks if a storage with the specified name exists.
public
Exists(string $name[, string|null $module = null ]) : bool
If you need to check existance of storage
if(Storages::Create()->Exists('langs', 'lang')) { ... }
Parameters
- $name : string
-
The name of the storage to check.
- $module : string|null = null
-
The module to which the storage belongs (optional).
Return values
bool —True if the storage exists, false otherwise.
GetStorages()
Retrieves an array of all storages.
public
GetStorages() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array containing all storage objects.
Load()
Loads the storage with the specified name and optional module.
public
Load(string $name[, string|null $module = null ]) : Storage|null
For example you can get storage structure information for storage "langs" in module "lang"
$storage = Storages::Create()->Load('langs', 'lang');
Parameters
- $name : string
-
The name of the storage to load.
- $module : string|null = null
-
The module to which the storage belongs (optional).
Return values
Storage|null —The loaded storage object if found, or null if not found.
Migrate()
Migrates storage tables and fields.
public
Migrate(Logger $logger[, bool $isDev = false ]) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $isDev : bool = false
-
Indicates whether the migration is for development purposes (optional, default: false).
_alterStorageField()
Alters an existing storage field.
private
_alterStorageField(Logger $logger, DataAccessPoint $accessPoint, string $prefix, string $table, string $field, string $type, int|null $length, mixed $default, bool $required, string|null $comment) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : DataAccessPoint
-
The data access point object.
- $prefix : string
-
The prefix for the storage field.
- $table : string
-
The name of the table where the field exists.
- $field : string
-
The name of the field to be altered.
- $type : string
-
The new data type of the field.
- $length : int|null
-
The new length of the field if applicable (nullable).
- $default : mixed
-
The new default value for the field.
- $required : bool
-
Indicates if the field is required.
- $comment : string|null
-
A comment describing the field (nullable).
_alterStorageIndex()
Alters an existing storage index.
private
_alterStorageIndex(Logger $logger, DataAccessPoint $accessPoint, string $prefix, string $table, string $indexName, array<string|int, mixed> $fields, string $type, string|null $method) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : DataAccessPoint
-
The data access point object.
- $prefix : string
-
The prefix for the storage index.
- $table : string
-
The name of the table where the index exists.
- $indexName : string
-
The name of the index to be altered.
- $fields : array<string|int, mixed>
-
An array of field names included in the index.
- $type : string
-
The type of the index (e.g., 'INDEX', 'UNIQUE', 'FULLTEXT').
- $method : string|null
-
The method to be used for altering the index (optional).
_alterStorageVirtualField()
Alters an existing virtual storage field.
private
_alterStorageVirtualField(Logger $logger, DataAccessPoint $accessPoint, string $prefix, string $table, string $field, string $type, int|null $length, string $expression, string $comment) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : DataAccessPoint
-
The data access point object.
- $prefix : string
-
The prefix for the storage field.
- $table : string
-
The name of the table where the field exists.
- $field : string
-
The name of the virtual field to be altered.
- $type : string
-
The new data type of the virtual field.
- $length : int|null
-
The new length of the virtual field if applicable (nullable).
- $expression : string
-
The new SQL expression defining the virtual field.
- $comment : string
-
A comment describing the virtual field.
_createStorageField()
Creates a new storage field.
private
_createStorageField(Logger $logger, DataAccessPoint $accessPoint, string $prefix, string $table, string $field, string $type, int|null $length, mixed $default, bool|null $required, string|null $comment) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : DataAccessPoint
-
The data access point object.
- $prefix : string
-
The prefix for the storage field.
- $table : string
-
The name of the table where the field will be created.
- $field : string
-
The name of the field to be created.
- $type : string
-
The data type of the field.
- $length : int|null
-
The length of the field if applicable (nullable).
- $default : mixed
-
The default value for the field.
- $required : bool|null
-
Indicates if the field is required (nullable).
- $comment : string|null
-
A comment describing the field (nullable).
_createStorageIndex()
Creates a new storage index.
private
_createStorageIndex(Logger $logger, mixed $accessPoint, string $prefix, string $table, string $indexName, array<string|int, mixed> $fields, string $type, string|null $method) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : mixed
-
The data access point object.
- $prefix : string
-
The prefix for the storage index.
- $table : string
-
The name of the table where the index will be created.
- $indexName : string
-
The name of the index to be created.
- $fields : array<string|int, mixed>
-
An array of field names included in the index.
- $type : string
-
The type of the index (e.g., 'INDEX', 'UNIQUE', 'FULLTEXT').
- $method : string|null
-
The method to be used for creating the index (optional).
_createStorageTable()
Creates a new storage table.
private
_createStorageTable(Logger $logger, DataAccessPoint $accessPoint, string $prefix, string $table[, bool $levels = false ]) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : DataAccessPoint
-
The data access point object.
- $prefix : string
-
The prefix for the storage table.
- $table : string
-
The name of the table to be created.
- $levels : bool = false
-
Indicates whether the table supports hierarchical levels (optional, default: false).
_createStorageVirtualField()
Creates a new virtual storage field.
private
_createStorageVirtualField(Logger $logger, DataAccessPoint $accessPoint, string $prefix, string $table, string $field, string $type, int|null $length, string|null $expression, string|null $comment) : void
Parameters
- $logger : Logger
-
The logger object to log messages.
- $accessPoint : DataAccessPoint
-
The data access point object.
- $prefix : string
-
The prefix for the storage field.
- $table : string
-
The name of the table where the field will be created.
- $field : string
-
The name of the virtual field to be created.
- $type : string
-
The data type of the virtual field.
- $length : int|null
-
The length of the virtual field if applicable (nullable).
- $expression : string|null
-
The SQL expression defining the virtual field (nullable).
- $comment : string|null
-
A comment describing the virtual field (nullable).
_fromShortString()
Extracts a short field record
private
_fromShortString(string $field) : array<string|int, mixed>
Parameters
- $field : string
Return values
array<string|int, mixed>_replaceTypes()
Replaces a global types
private
_replaceTypes(array<string|int, mixed> $fields) : array<string|int, mixed>
Parameters
- $fields : array<string|int, mixed>
Return values
array<string|int, mixed>_updateDefaultAndLength()
Updates the default value and length of a storage field.
private
_updateDefaultAndLength(string $field, string $type, bool $required, int|null $length, mixed $default) : array<string|int, mixed>
Parameters
- $field : string
-
The name of the field to be updated.
- $type : string
-
The new data type of the field.
- $required : bool
-
Indicates if the field is required.
- $length : int|null
-
The new length of the field if applicable (nullable).
- $default : mixed
-
The new default value for the field.
Return values
array<string|int, mixed> —An array containing the updated default value and length.