Schema
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
Schema constructor.
It collects the information from the database and creates files in YAML format for the reconstruction of its structure. Also save the view structure.
Return true if complete table structure was saved, otherwise return false.
Merge the existing yaml file with the structure of the database, prevailing the latter.
Verify the parameters established in the yaml file with the structure of the database, creating the missing data and correcting the possible errors.
Verify the $fieldData established in the yaml file with the structure of the database, creating the missing data and correcting the possible errors.
Returns an array with data from the specified yaml file
Returns the path to the specified file, or empty string if it does not exist.
Load data from CSV file.
Load data from Yaml file.
Save the data array in a .yaml file
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.
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.
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.
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.
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
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
at line 163
static array
getFromYamlFile(string $tableName, string $type = 'schema')
Returns an array with data from the specified yaml file
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.
at line 217
static array
loadDataFromCsv(string $fileName)
Load data from CSV file.
at line 234
static array
loadDataFromYaml(string $fileName)
Load data from Yaml file.
at line 262
static private bool
saveSchemaFileName(array $data, string $tableName, string $type = 'schema')
Save the data array in a .yaml file
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.
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.
at line 333
static array
setValues(string $tableName, array $values)
Create the SQL statements to fill the table with default data.