How to use
Learn how to use this library
This library is abandoned. Please consider using a different library.
For the next examples, we will use the memory driver, which is initialized as below
use Opis\DataStore\Drivers\Memory;
$dataStore = new Memory([
"admin" => [
"username" => "admin",
"extra" => [
"fullname" => "John Doe"
]
]
]);
Reading a value
You can read values by using the read method.
echo $dataStore->read("admin.username"); // admin
echo $dataStore->read("admin.language", "en"); // en
Checking if a value is present
You can check for data presence by using has method.
if ($dataStore->has("admin.extra.fullname")) {
// ...
}
Adding or changing values
You can write new values, or overwrite existing ones, by using the write method.
$dataStore->write("admin.language", "en-US");
echo $dataStore->read("admin.language"); // en-US
$dataStore->write("admin.extra", [
"fullname" => "Anonymous"
]);
echo $dataStore->read("admin.extra.fullname"); // Anonymous
Removing values
You can remove values by using the delete method.
$dataStore->delete("admin.extra");
if ($dataStore->has("admin.extra")) {
// This should never execute, because we just deleted the value
}