Completed
Push — master ( 01c9a5...19083c )
by Biao
04:36
created

Context::delete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hhxsv5\LaravelS\Swoole\Coroutine;
4
5
use Swoole\Coroutine;
6
7
class Context
8
{
9
    protected static $box = [];
10
11
    public static function get($key)
12
    {
13
        $uid = Coroutine::getuid();
14
        if ($uid < 0) {
15
            return null;
16
        }
17
        if (isset(self::$box[$uid][$key])) {
18
            return self::$box[$uid][$key];
19
        }
20
        return null;
21
    }
22
23
    public static function put($key, $item)
24
    {
25
        $uid = Coroutine::getuid();
26
        if ($uid > 0) {
27
            self::$box[$uid][$key] = $item;
28
        }
29
    }
30
31
    public static function delete($key = null)
32
    {
33
        $uid = Coroutine::getuid();
34
        if ($uid > 0) {
35
            if ($key) {
36
                unset(self::$box[$uid][$key]);
37
            } else {
38
                unset(self::$box[$uid]);
39
            }
40
        }
41
    }
42
}