1 | <?php |
||
21 | class Theme extends \yii\base\Theme implements \hiqdev\yii2\collection\ItemWithNameInterface |
||
22 | { |
||
23 | use GetManagerTrait; |
||
24 | |||
25 | /** |
||
26 | * @var string theme name |
||
27 | */ |
||
28 | public $name; |
||
29 | |||
30 | /** |
||
31 | * @var string theme label |
||
32 | */ |
||
33 | public $label; |
||
34 | |||
35 | /** |
||
36 | * @var array assets to be registered for this theme |
||
37 | */ |
||
38 | public $assets = []; |
||
39 | |||
40 | private $_view; |
||
41 | |||
42 | /** |
||
43 | * Returns the view object that can be used to render views or view files. |
||
44 | * The [[render()]] and [[renderFile()]] methods will use |
||
45 | * this view object to implement the actual view rendering. |
||
46 | * If not set, it will default to the "view" application component. |
||
47 | * |
||
48 | * @return \yii\web\View the view object that can be used to render views or view files |
||
49 | */ |
||
50 | public function getView() |
||
58 | |||
59 | /** |
||
60 | * Sets the view object to be used. |
||
61 | * |
||
62 | * @param View $view the view object that can be used to render views or view files |
||
63 | */ |
||
64 | public function setView($view) |
||
68 | |||
69 | public $pathMap = [ |
||
70 | __DIR__ . '/widgets/views' => '$themedWidgetPaths', |
||
71 | '$themedWidgetPaths' => '$themedViewPaths/widgets', |
||
72 | ]; |
||
73 | |||
74 | /** |
||
75 | * Getter for pathMap. |
||
76 | */ |
||
77 | public function init() |
||
90 | |||
91 | public function compilePathMap($map) |
||
104 | |||
105 | public function substituteVars($vars) |
||
129 | |||
130 | public function isVar($name) |
||
134 | |||
135 | public function calcExp($exp, $vars) |
||
145 | |||
146 | public function buildThemedViewPaths() |
||
150 | |||
151 | public function findParentPaths() |
||
164 | |||
165 | protected $_reflection; |
||
166 | |||
167 | public function getReflection() |
||
175 | |||
176 | private $_settings; |
||
177 | |||
178 | /** |
||
179 | * @param string $settings theme settings model class name or config. |
||
180 | */ |
||
181 | public function setSettings($settings) |
||
185 | |||
186 | public function getSettings() |
||
198 | |||
199 | public static function calcSettingsClass($class) |
||
203 | |||
204 | public static function findSettingsClass($class) |
||
210 | } |
||
211 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.