You must set up folder were we will store all configs.
Simplify\Storekeeper\Config::setConfigFolder('/path/to/folder')
Also, you may select separator for map.
Simplify\Storekeeper\Config::setSeparator('.') // By default separator is "."
Create instance of Simplify\Storekeeper\Config
$config = new Simplify\Storekeeper\Config('name_of_config');
If you want you can store some data inside config, when you create instance
$data = [
'data' => '2',
'data2' => 1
];
$config = new Simplify\Storekeeper\Config('name_of_config', $data);
Storekeeper check is file (with name as config name) exists. If exists it fills current config, otherwise it stays empty.
Now you can start your work with the available methods.
Returns data searched by $map
Example
$config = new Simplify\Storekeeper\Config('name_of_config'),
[
'someData' => [
'subData1' => true,
'subData2' => 'data2'
],
'number' => 123
]
);
$data = $config->get('someData.subData1'); // Returns true
$data2 = $config->get('somData.subData2'); // Returns 'data2'
$data3 = $config->get('number'); // Returns 123
Setup data by $map
Example
$config = new Simplify\Storekeeper\Config('name_of_config');
$config->set('str', '1234');
$config->set('number', 1234);
$config->set('somData.subData2', false);
All data keeps in global value
$config = new Simplify\Storekeeper\Config('name_of_config');
$sameConfig = new Simplify\Storekeeper\Config('name_of_config');
$config->set('foo', 'global value');
echo $sameConfig->get('foo'); // Output: 'global value'
Check is config key exists
Example
$config = new Simplify\Storekeeper\Config('name_of_config'),
[
'existVal' => [
'existsSubVal' => 'data'
]
]
);
$config->contains('existVal') // Returns true
$config->contains('existVal.existsSubVal') // Returns true
$config->contains('thisValueIsNotExists') // Returns false
Removes data by $map
Example
$config = new Simplify\Storekeeper\Config('name_of_config'),
[
'someData' => [
'subData1' => true,
'subData2' => 'data2'
],
'number' => 123
]
);
$config->unset('someData')
$config->get('someData') // throws Exception 'Key someData does not exist'
Returns config to it initial state
Example
$config = new Simplify\Storekeeper\Config('name_of_config'),
[
'value1' => 'i\'am a string'
'value2' => 97
]
);
$config->set('value1', 555)
$config->unset('value2')
print_r($config->get()) // Array (value1 => 555)
$config->reset()
print_r($config->get())
/*
Array (
value1 => i'am a string
value2 => 97
)
*/
When you create instance of Config it saves current state in local value.
$snake_config = new \Simplify\Storekeeper\Config('config'); // Saved state is []
$snake_config->set('foo', 1233); // Current state ['foo' => 1233]
echo $snake_config->get('foo') . PHP_EOL; // output 1233
$camelConfig = new \Simplify\Storekeeper\Config('config'); // Saved state ['foo' => 1233]
$camelConfig->set('foo', 12); // Current state ['foo' => 12]
echo $camelConfig->get('foo') . PHP_EOL; // output 12
$camelConfig->reset(); // Current state ['foo' => 1233]
echo $snake_config->get('foo') . PHP_EOL; // output 1233
$snake_config->reset();
$camelConfig->get('foo'); // Exception: value: 'foo' Does not exists in ...
Remove all data from current config
Example
$config = new Simplify\Storekeeper\Config('name_of_config'),
[
'value1' => 'i\'am a string'
'value2' => 97
]
);
print_r($config->get())
/*
Array (
value1 => i'am a string
value2 => 97
)
*/
$config->truncate();
print_r($config->get()); // Array ()
Remove file from config folder
Stores data to file inside config folder (filename is the same as config name)
Check is current config empty
Check is config file exists