asgard/data

Installs: 298

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:asgard-bundle

v0.3.1 2016-05-13 12:31 UTC

This package is not auto-updated.

Last update: 2024-11-09 16:37:31 UTC


README

#Data

Build Status

Data is package for key-value database storage.

##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);

##Fetch a value

$data->get('key', 'default'); #'default' if returned in the value could not fetched
#or
$data['key'];

##Store a value

$data->set('key', 'value');
#or
$data['key'] = 'value';

##Delete a key

$data->delete('key');
#or
unset($data['key']);

##Check for a key existence

$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