| 1 | <?php |
||
| 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 = []) |
|
| 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 | 1 | $tableName, |
|
| 53 | 1 | App::className($tableName, 'Model/Table', 'Table') |
|
| 54 | 1 | ); |
|
| 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 | 4 | } |
|
| 64 | |||
| 65 | 4 | return self::$instance; |
|
| 66 | } |
||
| 67 | |||
| 68 | 23 | public static function reset() |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @inheritDoc |
||
| 75 | */ |
||
| 76 | 1 | public function info() |
|
| 80 | } |
||
| 81 |