extends | title | group | prev | next | order |
---|---|---|---|---|---|
docs |
Config |
Architecture |
asset |
template |
2 |
The Tonik\Gin\Foundation\Config
class provides a simple way for creating flexible data collections. It implements the ArrayAccess
interface so you can iterate on it as on a standard array.
Pass an array of options on class initialization.
use Tonik\Gin\Foundation\Config;
$config = new Config(['textdomain' => 'theme-textdomain']);
// $config: class Tonik\Gin\Foundation\Config()
If you want to get a standard array with your configuration options, call all
method or directly cast config variable to an array.
$config->all();
(array) $config;
// ['textdomain' => 'theme-textdomain']
You can get a single configuration value with get
method and option name as the argument.
$config->get('textdomain');
$config['textdomain'];
// 'theme-textdomain'
You may also set configuration options after creating. Run set
method with the option name to update as a first argument and new value as second.
$config->set('textdomain', 'new-textdomain');
$config['textdomain'] = 'new-textdomain';
// ['textdomain' => 'new-textdomain']
The has
method verifies if an option exists in the configuration.
$config->has('textdomain'); // true
$config->has('missing'); // false
isset($config['textdomain']); // true
isset($config['missing']); // false
Allows for modifying a configuration value of the specific option on getting.
add_filter('tonik/gin/config/get/key', function($value) {
return ucfirst($value);
});
Allows for modifying a configuration value of the specific option when setting.
add_filter('tonik/gin/config/set/key', function($value) {
return ucfirst($value);
});