How to work with configs in Mezon Framework

Mezon has it’s own routine for working with configs. It can be accesed with a set of functions, wich are described below.

This is the way how to start using it in your project:

composer require mezon/conf

Or get it directly from repo;

Gettin…


This content originally appeared on DEV Community and was authored by alexdodonov

Mezon has it's own routine for working with configs. It can be accesed with a set of functions, wich are described below.

This is the way how to start using it in your project:

composer require mezon/conf

Or get it directly from repo;

Getting access to the key in config can be done with Conf::getValue($route, $defaultValue = false) function. It returns config value with route $route and return $defaultValue if this key was not found. For example:

$value = Conf::getValue('res/images/favicon', 'http://yoursite.com/res/images/favicon.ico');

Setting values for the config key can be done by calling Conf::setConfigValue($route, $value) or Conf::addConfigValue($route, $value) function. The main difference between these two functions is that the first one sets scalar key, and the second one adds element to the array in config. Here is small example:

Conf::setConfigValue('res/value', 'Value!');
var_dump(Conf::getValue('res/value')); // displays 'Value!' string

Conf::addConfigValue('res/value', 'Value 1!');
Conf::addConfigValue('res/value', 'Value 2!');
var_dump(Conf::getValue('res/value')); // displays array( [0] => 'Value 1!' , [1] => 'Value 2!' )

You also can use typed versions of these methods:

Conf::getValueAsArray(...);
Conf::getValueAsObject(...);
Conf::getValueAsString(...);

Conf::setConfigArrayValue(...);
Conf::setConfigObjectValue(...);
Conf::setConfigStringValue(...);

You can set multyple values to the config:

// here $settings is an associative array
Conf::setConfigValues(array $settings);

Or you can read config from JSON:

Conf::loadConfigFromJson(string $pathToConfig);

If you are not shure that the key exists, then you can check it:

Conf::setConfigValue('res/value', 'Value!');

var_dump(Conf::configKeyExists('res')); // true
var_dump(Conf::configKeyExists('res2')); // false
var_dump(Conf::configKeyExists('res/value')); // true

You can also able to delete config key

Conf::setConfigValue('res/value', 'Value!');
Conf::deleteConfigValue('res/value');
var_dump(Conf::configKeyExists('res/value')); // false
var_dump(Conf::configKeyExists('res')); // also false

Or clear the entire config:

Conf::clear();

That's all you need to know about config read/write.

Learn more

More information can be found here:

Twitter
Mezon Framework

It will be great if you will contribute something to this project. Documentation, sharing the project in your social media, bug fixing, refactoring, or even submitting issue with question or feature request. Thanks anyway )


This content originally appeared on DEV Community and was authored by alexdodonov


Print Share Comment Cite Upload Translate Updates
APA

alexdodonov | Sciencx (2022-01-17T10:17:02+00:00) How to work with configs in Mezon Framework. Retrieved from https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/

MLA
" » How to work with configs in Mezon Framework." alexdodonov | Sciencx - Monday January 17, 2022, https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/
HARVARD
alexdodonov | Sciencx Monday January 17, 2022 » How to work with configs in Mezon Framework., viewed ,<https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/>
VANCOUVER
alexdodonov | Sciencx - » How to work with configs in Mezon Framework. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/
CHICAGO
" » How to work with configs in Mezon Framework." alexdodonov | Sciencx - Accessed . https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/
IEEE
" » How to work with configs in Mezon Framework." alexdodonov | Sciencx [Online]. Available: https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/. [Accessed: ]
rf:citation
» How to work with configs in Mezon Framework | alexdodonov | Sciencx | https://www.scien.cx/2022/01/17/how-to-work-with-configs-in-mezon-framework/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.