-
Notifications
You must be signed in to change notification settings - Fork 30
/
EventManager.php
49 lines (42 loc) · 1.11 KB
/
EventManager.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
<?php
namespace yiicod\socketio;
use Yii;
use yii\base\Component;
use yii\helpers\Json;
class EventManager extends Component
{
/**
* Array of events namespaces
*
* @var array
*/
public $namespaces = [];
/**
* You can set unique nsp for channels
*
* @var string
*/
public $nsp = '';
/**
* List with all events
*
* @var array
*/
protected static $list = [];
public function getList(): array
{
if (empty(static::$list)) {
foreach ($this->namespaces as $key => $namespace) {
$alias = Yii::getAlias('@' . str_replace('\\', '/', trim($namespace, '\\')));
foreach (glob(sprintf('%s/**.php', $alias)) as $file) {
$className = sprintf('%s\%s', $namespace, basename($file, '.php'));
if (method_exists($className, 'name')) {
static::$list[$className::name()] = $className;
}
}
}
//Yii::info(Json::encode(static::$list));
}
return static::$list;
}
}