asgard / data
Installs: 298
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:asgard-bundle
Requires
- php: >=5.5.9
- asgard/db: ~0.3.0
- doctrine/dbal: ^2.0
This package is not auto-updated.
Last update: 2024-11-09 16:37:31 UTC
README
#Data
Data is package for key-value database storage.
- Installation
- Usage in the Asgard Framework
- Usage outside the Asgard Framework
- Fetch a value
- Store a value
- Delete a key
- Check for a key existence
- Working with different data types
##Installation If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries.
composer require asgard/data 0.*
##Usage in the Asgard Framework
$data = $container['data'];
The container is often accessible as a method parameter or through a ContainerAware object. You can also use the singleton but it is not recommended.
##Usage outside the Asgard Framework
$config = [
'host' => 'localhost',
'user' => 'root',
'password' => '',
'database' => 'asgard',
'prefix' => '',
'driver' => 'mysql'
];
$db = new \Asgard\Db\DB($config);
$data = new \Asgard\Data\Data($db);
$data->get('key', 'default'); #'default' if returned in the value could not fetched
#or
$data['key'];
$data->set('key', 'value');
#or
$data['key'] = 'value';
$data->delete('key');
#or
unset($data['key']);
$data->has('key');
#or
isset($data['key']);
##Working with different data types
Register a type
$data->register('obj',
function($obj) {
return serialize($obj);
},
function($str) {
return unserialize($str);
}
);
Store a value with a specific type
$obj = new StdClass;
$obj->name = 'bob';
$data->set('key', $obj, 'obj');
###Contributing
Please submit all issues and pull requests to the asgardphp/asgard repository.
License
The Asgard framework is open-sourced software licensed under the MIT license