1 | <?php |
||
22 | class BaseHandler extends \yii\base\Object |
||
23 | { |
||
24 | /** |
||
25 | * @var Goal |
||
26 | */ |
||
27 | public $goal; |
||
28 | |||
29 | /** |
||
30 | * @var string template file name to be used for rendering |
||
31 | */ |
||
32 | public $template; |
||
33 | |||
34 | /** |
||
35 | * @var View object. |
||
36 | */ |
||
37 | protected $_view; |
||
38 | |||
39 | /** |
||
40 | * Returns the view object that can be used to render views or view files. |
||
41 | * If not set, it will default to the "view" application component. |
||
42 | * |
||
43 | * @return View|\yii\web\View the view object that can be used to render views or view files. |
||
44 | */ |
||
45 | public function getView() |
||
46 | { |
||
47 | if ($this->_view === null) { |
||
48 | $this->_view = Yii::$app->getView(); |
||
49 | } |
||
50 | |||
51 | return $this->_view; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Renders prepared data. |
||
56 | * Must be redefined in child. |
||
57 | * |
||
58 | * @param array $data |
||
59 | * |
||
60 | * @throws InvalidConfigException |
||
61 | * |
||
62 | * @return string file content |
||
63 | */ |
||
64 | public function renderPrepared(array $data) |
||
68 | |||
69 | /** |
||
70 | * Renders raw data. |
||
71 | * Prepares data with ArrayHelper::toArray. |
||
72 | * |
||
73 | * @param mixed $data |
||
74 | * |
||
75 | * @return string file content |
||
76 | */ |
||
77 | public function render($data) |
||
81 | |||
82 | public function prepareData($data) |
||
87 | |||
88 | /** |
||
89 | * Renders file content using given data. |
||
90 | * Converts to array with ArrayHelper::toArray. |
||
91 | * |
||
92 | * @param mixed $data |
||
93 | * |
||
94 | * @return string file content |
||
95 | */ |
||
96 | public function renderPath($path, $data) |
||
100 | |||
101 | public function parsePath($path, $minimal = null) |
||
105 | |||
106 | /** |
||
107 | * Writes given content to the file. |
||
108 | * Doesn't touch file if it has exactly same content. |
||
109 | * Creates intermediate directories when necessary. |
||
110 | * @param string $path |
||
111 | * @param string $content |
||
112 | * @return bool true if file was changed |
||
113 | */ |
||
114 | public function write($path, $content) |
||
126 | |||
127 | /** |
||
128 | * Creates directory if not exists. |
||
129 | * @param string $path |
||
130 | * @return bool true if directory did not exist and was created |
||
131 | */ |
||
132 | public function mkdir($path) |
||
144 | |||
145 | public function read($path, $asArray = false) |
||
157 | |||
158 | public function readArray($path) |
||
162 | } |
||
163 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: