class Schema

The Schema class contains static methods that allow you to manipulate the database. It is used to create and modify tables and indexes in the database.

Properties

static private array $files Content files yet readed.

Methods

__construct()

Schema constructor.

static 
saveStructure()

It collects the information from the database and creates files in YAML format for the reconstruction of its structure. Also save the view structure.

static bool
saveTableStructure(string $table)

Return true if complete table structure was saved, otherwise return false.

static array
mergeArray(array $struct, array $data, bool $isView = false)

Merge the existing yaml file with the structure of the database, prevailing the latter.

static array
mergeViewData(array $struct, array $data)

Verify the parameters established in the yaml file with the structure of the database, creating the missing data and correcting the possible errors.

static array
mergeViewField(string $field, array $values, array $fieldData)

Verify the $fieldData established in the yaml file with the structure of the database, creating the missing data and correcting the possible errors.

static array
getFromYamlFile(string $tableName, string $type = 'schema')

Returns an array with data from the specified yaml file

static string
getSchemaFileName(string $tableName, string $type = 'schema')

Returns the path to the specified file, or empty string if it does not exist.

static array
loadDataFromCsv(string $fileName)

Load data from CSV file.

static array
loadDataFromYaml(string $fileName)

Load data from Yaml file.

static bool
saveSchemaFileName(array $data, string $tableName, string $type = 'schema')

Save the data array in a .yaml file

static array
setNormalizedStructure(array $structure, string $tableName)

Normalize an array that has the file structure defined in the model by setStructure, so that it has fields with all the values it must have. Those that do not exist are created with the default value, avoiding having to do the check each time, or calculating their value based on the data provided by the other fields.

static array|null
normalizeField(string $tableName, string $field, array $structure)

Take the definition of a field, and make sure you have all the information that is necessary for its creation or maintenance, calculating the missing data if possible. It can cause an exception if some vital data is missing, but this should only occur at the design stage.

static array
setValues(string $tableName, array $values)

Create the SQL statements to fill the table with default data.

Details

at line 38
__construct()

Schema constructor.

at line 50
static saveStructure()

It collects the information from the database and creates files in YAML format for the reconstruction of its structure. Also save the view structure.

at line 67
static bool saveTableStructure(string $table)

Return true if complete table structure was saved, otherwise return false.

If the name of the table includes the prefix used in the database, it is removed from the name of the table.

Parameters

string $table

Return Value

bool

at line 91
static protected array mergeArray(array $struct, array $data, bool $isView = false)

Merge the existing yaml file with the structure of the database, prevailing the latter.

Parameters

array $struct current database table structure
array $data current yaml file structure
bool $isView

Return Value

array

at line 110
static protected array mergeViewData(array $struct, array $data)

Verify the parameters established in the yaml file with the structure of the database, creating the missing data and correcting the possible errors.

Posible data: unique, min, max, length, pattern, placeholder, label & shortlabel

Parameters

array $struct current database table structure
array $data current yaml file data

Return Value

array

at line 131
static protected array mergeViewField(string $field, array $values, array $fieldData)

Verify the $fieldData established in the yaml file with the structure of the database, creating the missing data and correcting the possible errors.

Posible data: unique, min, max, length, pattern, placeholder, label & shortlabel

Parameters

string $field
array $values
array $fieldData

Return Value

array

at line 163
static array getFromYamlFile(string $tableName, string $type = 'schema')

Returns an array with data from the specified yaml file

Parameters

string $tableName
string $type must be 'schema' or 'viewdata'

Return Value

array

at line 187
static private string getSchemaFileName(string $tableName, string $type = 'schema')

Returns the path to the specified file, or empty string if it does not exist.

Parameters

string $tableName name of the file without extension (assumes .yaml or .csv according to the type)
string $type It's the foldername (in lowercase). It's usually schema (by default) or viewdata.

Return Value

string

at line 217
static array loadDataFromCsv(string $fileName)

Load data from CSV file.

Parameters

string $fileName

Return Value

array

at line 234
static array loadDataFromYaml(string $fileName)

Load data from Yaml file.

Parameters

string $fileName

Return Value

array

at line 262
static private bool saveSchemaFileName(array $data, string $tableName, string $type = 'schema')

Save the data array in a .yaml file

Parameters

array $data
string $tableName
string $type

Return Value

bool

at line 283
static array setNormalizedStructure(array $structure, string $tableName)

Normalize an array that has the file structure defined in the model by setStructure, so that it has fields with all the values it must have. Those that do not exist are created with the default value, avoiding having to do the check each time, or calculating their value based on the data provided by the other fields.

It also ensures that the keys and default values exist as an empty array if they did not exist.

Parameters

array $structure
string $tableName

Return Value

array

at line 307
static protected array|null normalizeField(string $tableName, string $field, array $structure)

Take the definition of a field, and make sure you have all the information that is necessary for its creation or maintenance, calculating the missing data if possible. It can cause an exception if some vital data is missing, but this should only occur at the design stage.

Parameters

string $tableName
string $field
array $structure

Return Value

array|null

at line 333
static array setValues(string $tableName, array $values)

Create the SQL statements to fill the table with default data.

Parameters

string $tableName
array $values

Return Value

array