Jet\Config class
Now that you have already familiarized yourself with the principle of the configuration subsystem and also with the issue of definic configuration, it is time to "take a look" at the Jet\Config class, which is the central point of the whole subsystem.
The class has the following roles:
- It is the parent class of all configuration definitions - they must inherit from it.
- It is the starting point for working with configuration definitions.
- It takes care of loading, compiling, and saving configuration data to and from files.
General Methods
Method | Meaning |
---|---|
public static setBeTolerant( bool $be_tolerant ): void | This static method enables (disables) tolerant configuration mode. What does it mean? When the configuration is loaded while the application is running normally, a basic check is performed. That is, the configuration (configuration file) must exist, mandatory configuration values must be set. If these conditions are not met, then an exception is thrown and the application run is thus terminated - a serious error occurs. Running an application without a complete configuration could have unpleasant consequences, so it is treated strictly. However, if you are developing an installer, for example, you have to take into account that the configuration is incomplete or does not exist yet. This is what the so-called tolerant mode is for, which works in general - for all configuration definitions and files. |
public static beTolerant( ): bool | Indicates whether or not tolerant mode is enabled. |
Basic methods
Method | Meaning |
---|---|
public __construct( ?array $data = null ) | The constructor initializes the configuration, of course. That is, it converts the configuration data into properties of an instance of the class, initializes subsections, and so on. The important thing is how the optional parameter $data behaves. This is the field that contains the configuration data in its raw form - that is, as an associated field. However, you will not normally use this parameter in an application. If this parameter is omitted (as it usually will be in practice), the configuration is read from the corresponding file. However, it may happen that you need to create an ad hoc instance of the configuration without reading the data from the file. Example? An ad hoc connection to the database in some single-purpose service script that you won't use elsewhere. Therefore, there is an option to create a configuration instance and directly pass configuration data in this way. |
public setData( array $data ): void | See the constructor (which calls this method). You can set the configuration data in one more way by using this method. |
public toArray( ): array | You could say that this is the reverse method to the constructor and the setData method. That is, it converts the configuration instance into an associated array. |
Working with a configuration definition
Method | Importance |
---|---|
public getDefinition( ): Config_Definition_Config | Returns an instance of the object that represents the definition of the given configuration. |
public getPropertiesDefinition( ): Config_Definition_Property[] | Returns an array of object instances representing the definitions of each configuration parameter (i.e., properties of the given configuration class). |
Working with a configuration file
Method | Meaning |
---|---|
public getConfigFilePath( ): string | Returns the path to the configuration file. Unless otherwise specified by the setConfigFilePath method (see below), the path to the file is set as follows:
SysConf_Path::getConfig() . $this->getDefinition()->getName() . '.php'
Thus:
return [ 'backend_type' => 'MySQL', 'backend_config' => [ 'connection_read' => 'default', 'connection_write' => 'default', 'engine' => 'InnoDB', 'default_charset' => 'utf8', 'collate' => 'utf8_general_ci', ], ];
Because the Jet\DataModel_Config class has specified it so with its definition: namespace Jet;
#[Conf
|