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 | public static function init(LoopInterface $loop, array $config = []) |
||
31 | { |
||
32 | Pool::getInstance($loop, $config); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param $tableName |
||
37 | * |
||
38 | * @return AsyncTable |
||
|
|||
39 | */ |
||
40 | public static function get($tableName) |
||
41 | { |
||
42 | if (is_array($tableName)) { |
||
43 | $tableName = $tableName['class']; |
||
44 | } |
||
45 | |||
46 | if (isset(static::$tables[$tableName])) { |
||
47 | return static::$tables[$tableName]; |
||
48 | } |
||
49 | |||
50 | $table = new $tableName(); |
||
51 | |||
52 | if ($table instanceof AsyncTableInterface) { |
||
53 | $table->setUpAsyncTable( |
||
54 | Pool::getInstance(), |
||
55 | $tableName, |
||
56 | App::className($tableName, 'Model/Table', 'Table') |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | static::$tables[$tableName] = $table; |
||
61 | return static::$tables[$tableName]; |
||
62 | } |
||
63 | |||
64 | 3 | public static function getInstance() |
|
73 | |||
74 | 25 | public static function reset() |
|
78 | |||
79 | /** |
||
80 | * @inheritDoc |
||
81 | */ |
||
82 | public function info() |
||
86 | } |
||
87 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.