-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathTableManager.php
54 lines (45 loc) · 1.05 KB
/
TableManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Created by PhpStorm.
* User: yf
* Date: 2018-12-27
* Time: 15:54
*/
namespace EasySwoole\Component;
use Swoole\Table;
class TableManager
{
use Singleton;
private $list = [];
/**
* @param $name
* @param array $columns ['col'=>['type'=>Table::TYPE_STRING,'size'=>1]]
* @param int $size
*/
public function add($name,array $columns,$size = 1024):void
{
if(!isset($this->list[$name])){
$table = new Table($size);
foreach ($columns as $column => $item){
$table->column($column,$item['type'],$item['size']);
}
$table->create();
$this->list[$name] = $table;
}
}
public function get($name):?Table
{
if(isset($this->list[$name])){
return $this->list[$name];
}else{
return null;
}
}
public function del($name)
{
if(isset($this->list[$name])){
$this->list[$name]->destroy();
unset($this->list[$name]);
}
}
}