Allow users to write multiple items at once

This commit is contained in:
Jake Mitchell
2016-06-26 01:32:09 +00:00
parent e5b48176c4
commit 110ff0a15c
3 changed files with 25 additions and 7 deletions

View File

@@ -25,12 +25,12 @@ interface MetaContract
/**
* Adds the key-value pair into the serialized data set.
*
* @param string|int $key
* @param string|int|array $keyOrArray
* @param string|int|float|array|bool|null $value
*
* @return void
*/
public function write( $key, $value );
public function write( $keyOrArray, $value = null );
/**
* Get the serialized value of the meta info.

View File

@@ -52,14 +52,22 @@ class Meta extends Model implements FoundationModel, MetaContract
/**
* Adds the key-value pair into the serialized data set.
*
* @param string|int $key
* @param string|int|array $keyOrArray
* @param string|int|float|array|bool|null $value
*
* @return void
*/
public function write( $key, $value ){
public function write( $keyOrArray, $value = null ){
$meta = unserialize( $this->meta );
$meta[ $key ] = $value;
if( is_array( $keyOrArray ) ){
foreach( $keyOrArray as $key => $val ){
$meta[ $key ] = $val;
}
} else {
$meta[ $keyOrArray ] = $value;
}
$meta = serialize( $meta );
$this->meta = $meta;
$this->save();