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 | /** |
||
70 | * Getter for pathMap. |
||
71 | */ |
||
72 | public function init() |
||
83 | |||
84 | protected $_viewPath; |
||
85 | protected $_widgetPath; |
||
86 | |||
87 | public function getViewPath() |
||
91 | |||
92 | public function getWidgetPath() |
||
96 | |||
97 | public function calcParentPaths() |
||
110 | |||
111 | public function buildViewPaths() |
||
122 | |||
123 | protected $_baseUrl; |
||
124 | |||
125 | /** |
||
126 | * @return string the base URL (without ending slash) for this theme. |
||
127 | * All resources of this theme are considered to be under this base URL. |
||
128 | */ |
||
129 | public function getBaseUrl() |
||
137 | |||
138 | protected $_reflection; |
||
139 | |||
140 | public function getReflection() |
||
148 | |||
149 | private $_settings; |
||
150 | |||
151 | /** |
||
152 | * @param $settings string theme settings model class name |
||
153 | */ |
||
154 | public function setSettings($settings) |
||
158 | |||
159 | public function getSettings() |
||
171 | |||
172 | public static function calcSettingsClass($class) |
||
176 | |||
177 | public static function findSettingsClass($class) |
||
183 | } |
||
184 |
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.