1 | <?php |
||
20 | class ViewComposer |
||
21 | { |
||
22 | /** |
||
23 | * Agent help to detect user device. |
||
24 | * |
||
25 | * @var Agent |
||
26 | */ |
||
27 | protected $agent; |
||
28 | |||
29 | /** |
||
30 | * An array with key's device type mapping with sub dir of it. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $deviceSubDirs; |
||
35 | |||
36 | /** |
||
37 | * Resolved path cached. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $resolvedPaths = []; |
||
42 | |||
43 | /** |
||
44 | * Helpful resolve path. |
||
45 | * |
||
46 | * @var Filesystem |
||
47 | */ |
||
48 | protected $files; |
||
49 | |||
50 | /** |
||
51 | * Create a new ViewComposer instance. |
||
52 | * |
||
53 | * @param Agent $agent |
||
54 | * @param array $deviceSubDirs |
||
55 | * @param Filesystem $files |
||
56 | */ |
||
57 | public function __construct(Agent $agent, array $deviceSubDirs, Filesystem $files) |
||
63 | |||
64 | /** |
||
65 | * Compose given View instance. |
||
66 | * |
||
67 | * @param View $view |
||
68 | */ |
||
69 | public function compose(View $view): void |
||
85 | |||
86 | /** |
||
87 | * Resolve path by end-user device. |
||
88 | * |
||
89 | * @param View $view |
||
90 | * @return string|null |
||
91 | */ |
||
92 | protected function resolvePath(View $view): ?string |
||
102 | |||
103 | /** |
||
104 | * Checking current device of end-user by given value. |
||
105 | * |
||
106 | * @param $device |
||
107 | * @return bool |
||
108 | */ |
||
109 | protected function isDevice($device): bool |
||
122 | |||
123 | /** |
||
124 | * Find sub path. |
||
125 | * |
||
126 | * @param View $view |
||
127 | * @param string $subDir |
||
128 | * @return string|null |
||
129 | */ |
||
130 | protected function findSubPath(View $view, string $subDir): ?string |
||
138 | |||
139 | /** |
||
140 | * Find sub view path. |
||
141 | * |
||
142 | * @param View $view |
||
143 | * @param string $subDir |
||
144 | * @return string|null |
||
145 | */ |
||
146 | protected function findSubViewPath(View $view, string $subDir): ?string |
||
166 | |||
167 | /** |
||
168 | * Find sub native path. |
||
169 | * |
||
170 | * @param View $view |
||
171 | * @param string $subDir |
||
172 | * @return string|null |
||
173 | */ |
||
174 | protected function findSubNativePath(View $view, string $subDir): ?string |
||
186 | } |
||
187 |