Skip to content

Commit

Permalink
update mem table class
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 24, 2019
1 parent f8ea7c3 commit 05ab750
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/MemTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function set(string $key, array $data): bool
* @param string $key Index key
* @param string $field Filed name of Index
*
* @return array|false Will return an array when success, return false when failure
* @return array|false|mixed Will return an array when success, return false when failure
* @throws RuntimeException
*/
public function get(string $key, string $field = null)
Expand Down Expand Up @@ -256,6 +256,16 @@ public function count(): int
* Extra methods
****************************************************************************/

/**
* @param callable $fn
*/
public function each(callable $fn): void
{
foreach ($this->table as $row) {
$fn($row);
}
}

/**
* clear/flush table data
*/
Expand Down Expand Up @@ -292,7 +302,9 @@ public function restore(bool $coRead = false): void
$content = file_get_contents($file);
}

$this->load((array)json_decode($content, true));
if ($content) {
$this->load((array)json_decode($content, true));
}
}

/**
Expand Down Expand Up @@ -330,7 +342,6 @@ public function load(array $data): void
}
}


/*****************************************************************************
* Getter/Setter methods
****************************************************************************/
Expand Down

0 comments on commit 05ab750

Please sign in to comment.