|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\models; |
|
4
|
|
|
|
|
5
|
|
|
use Closure; |
|
6
|
|
|
use Yii; |
|
7
|
|
|
|
|
8
|
|
|
class ObjClass extends \yii\base\Object |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
public $knownClasses = []; |
|
11
|
|
|
|
|
12
|
|
|
protected $className; |
|
13
|
|
|
|
|
14
|
|
|
protected $_alias; |
|
15
|
|
|
|
|
16
|
|
|
protected $_color; |
|
17
|
|
|
|
|
18
|
|
|
protected $_label; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct($className, $config = []) |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct($config); |
|
23
|
|
|
$this->className = $className; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getAlias() |
|
27
|
|
|
{ |
|
28
|
|
|
if ($this->_alias === null) { |
|
29
|
|
|
$this->_alias = $this->getValue('alias'); |
|
30
|
|
|
} |
|
31
|
|
|
if ($this->_alias === null) { |
|
32
|
|
|
$this->_alias = $this->className; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $this->_alias; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getColor() |
|
39
|
|
|
{ |
|
40
|
|
|
if ($this->_color === null) { |
|
41
|
|
|
$this->_color = $this->getValue('color'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $this->_color; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getLabel() |
|
48
|
|
|
{ |
|
49
|
|
|
if ($this->_label === null) { |
|
50
|
|
|
$this->_label = $this->findLabel(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this->_label; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function findLabel() |
|
57
|
|
|
{ |
|
58
|
|
|
$label = $this->getValue('label'); |
|
59
|
|
|
if ($label instanceof Closure) { |
|
60
|
|
|
$label = call_user_func($label, $this); |
|
61
|
|
|
} |
|
62
|
|
|
if (!$label) { |
|
63
|
|
|
$label = ucfirst($this->className); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $label; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getValue($key) |
|
70
|
|
|
{ |
|
71
|
|
|
if (isset($this->knownClasses[$this->className][$key])) { |
|
72
|
|
|
return $this->knownClasses[$this->className][$key]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public static function get($className) |
|
79
|
|
|
{ |
|
80
|
|
|
return Yii::$container->get(static::class, [$className]); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.