Completed
Push — master ( c7fd8f...a839ca )
by Cees-Jan
05:14
created

AsyncTableRegistry::info()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace WyriHaximus\React\Cake\Orm;
4
5
use Cake\Core\App;
6
use React\EventLoop\LoopInterface;
7
use WyriHaximus\React\ChildProcess\Pool\PoolUtilizerInterface;
8
9
class AsyncTableRegistry implements PoolUtilizerInterface
10
{
11
    /**
12
     * @var AsyncTable[]
13
     */
14
    protected static $tables = [];
15
16
    /**
17
     * @var AsyncTableRegistry
18
     */
19
    protected static $instance = null;
20
21
    /**
22
     * @var boolean
23
     */
24
    protected static $reset = false;
25
26
    /**
27
     * @param LoopInterface $loop
28
     * @param array $config
29
     */
30 2
    public static function init(LoopInterface $loop, array $config = [])
31
    {
32 2
        Pool::getInstance($loop, $config);
33 2
    }
34
35
    /**
36
     * @param $tableName
37
     *
38
     * @return AsyncTable
39
     */
40 1
    public static function get($tableName)
41
    {
42 1
        if (is_array($tableName)) {
43
            $tableName = $tableName['class'];
44
        }
45
        
46 1
        if (isset(static::$tables[$tableName])) {
47 1
            return static::$tables[$tableName];
48
        }
49
50 1
        static::$tables[$tableName] = new AsyncTable(
51 1
            Pool::getInstance(),
52
            $tableName,
53 1
            App::className($tableName, 'Model/Table', 'Table')
54
        );
55 1
        return static::$tables[$tableName];
56
    }
57
58 4
    public static function getInstance()
59
    {
60 4
        if (null === self::$instance || self::$reset) {
61 4
            self::$instance = new static();
62 4
            self::$reset = false;
63
        }
64
65 4
        return self::$instance;
66
    }
67
68 23
    public static function reset()
69
    {
70 23
        self::$reset = true;
71 23
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76 1
    public function info()
77
    {
78 1
        return Pool::getInstance()->info();
79
    }
80
}
81