EventManager::getList()   B
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 2
nop 0
1
<?php
2
3
namespace yiicod\socketio;
4
5
use Yii;
6
use yii\base\Component;
7
use yii\helpers\Json;
8
9
class EventManager extends Component
10
{
11
    /**
12
     * Array of events namespaces
13
     *
14
     * @var array
15
     */
16
    public $namespaces = [];
17
18
    /**
19
     * You can set unique nsp for channels
20
     *
21
     * @var string
22
     */
23
    public $nsp = '';
24
25
    /**
26
     * List with all events
27
     *
28
     * @var array
29
     */
30
    protected static $list = [];
31
32
    public function getList(): array
33
    {
34
        if (empty(static::$list)) {
35
            foreach ($this->namespaces as $key => $namespace) {
36
                $alias = Yii::getAlias('@' . str_replace('\\', '/', trim($namespace, '\\')));
37
                foreach (glob(sprintf('%s/**.php', $alias)) as $file) {
38
                    $className = sprintf('%s\%s', $namespace, basename($file, '.php'));
39
                    if (method_exists($className, 'name')) {
40
                        static::$list[$className::name()] = $className;
41
                    }
42
                }
43
            }
44
            //Yii::info(Json::encode(static::$list));
45
        }
46
47
        return static::$list;
48
    }
49
}
50