1 | <?php |
||
22 | class ViewRenderBehavior extends Behavior |
||
23 | { |
||
24 | use DetectorTrait; |
||
25 | |||
26 | /** |
||
27 | * @var array have key's device type and value's directory name store all views of this device. |
||
28 | * @see [[getDir()]] |
||
29 | */ |
||
30 | public $dirMap = [ |
||
31 | 'mobile' => 'mobile', |
||
32 | 'tablet' => 'tablet' |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * @inheritDoc |
||
37 | */ |
||
38 | 6 | public function events() |
|
44 | |||
45 | /** |
||
46 | * An event handle when rendering view support render by device type. |
||
47 | * |
||
48 | * @param ViewEvent $event triggered. |
||
49 | * @throws \yii\base\InvalidConfigException |
||
50 | */ |
||
51 | 6 | public function beforeRender(ViewEvent $event) |
|
65 | |||
66 | /** |
||
67 | * Get dir by requested device. |
||
68 | * |
||
69 | * @return string|null dir store all views of device or null if not match all element in [[$dirMap]]. |
||
70 | * @throws \yii\base\InvalidConfigException |
||
71 | */ |
||
72 | 6 | protected function getDir(): ?string |
|
95 | } |
||
96 |