1 | <?php |
||
20 | class ViewComposer |
||
21 | { |
||
22 | /** |
||
23 | * Views compose locale by this app locale. |
||
24 | * |
||
25 | * @var Application |
||
26 | */ |
||
27 | protected $app; |
||
28 | |||
29 | /** |
||
30 | * Application source locale. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $sourceLocale; |
||
35 | |||
36 | /** |
||
37 | * File system use to searching view path. |
||
38 | * |
||
39 | * @var Filesystem |
||
40 | */ |
||
41 | protected $files; |
||
42 | |||
43 | /** |
||
44 | * View path locale resolved. |
||
45 | * |
||
46 | * @var array|string[] |
||
47 | */ |
||
48 | protected $resolvedPaths = []; |
||
49 | |||
50 | /** |
||
51 | * Create new ViewComposer instance. |
||
52 | * |
||
53 | * @param Application $app |
||
54 | * @param string $sourceLocale |
||
55 | * @param Filesystem $files |
||
56 | */ |
||
57 | public function __construct(Application $app, string $sourceLocale, Filesystem $files) |
||
63 | |||
64 | /** |
||
65 | * Compose given View instance. |
||
66 | * |
||
67 | * @param View $view |
||
68 | */ |
||
69 | public function compose(View $view): void |
||
88 | |||
89 | /** |
||
90 | * Resolve path by user locale. |
||
91 | * |
||
92 | * The searching is based on the specified language code. In particular, |
||
93 | * a file with the same name will be looked for under the subdirectory |
||
94 | * whose name is the same as the language code. For example, given the file "path/to/view.php" |
||
95 | * and language code "zh-CN", the localized file will be looked for as |
||
96 | * "path/to/zh-CN/view.php". If the file is not found, it will try a fallback with just a language code that is |
||
97 | * "zh" i.e. "path/to/zh/view.php". If it is not found as well the original file will be returned. |
||
98 | * |
||
99 | * The implementation of this method referenced FileHelper in Yii2 Framework. |
||
100 | * |
||
101 | * @param View $view |
||
102 | * @return string|null |
||
103 | */ |
||
104 | protected function resolvePath(View $view): ?string |
||
124 | |||
125 | /** |
||
126 | * Find sub path. |
||
127 | * |
||
128 | * @param View $view |
||
129 | * @param string $subDir |
||
130 | * @return string|null |
||
131 | */ |
||
132 | protected function findSubPath(View $view, string $subDir): ?string |
||
140 | |||
141 | /** |
||
142 | * Find sub view path. |
||
143 | * |
||
144 | * @param View $view |
||
145 | * @param string $subDir |
||
146 | * @return string|null |
||
147 | */ |
||
148 | protected function findSubViewPath(View $view, string $subDir): ?string |
||
168 | |||
169 | /** |
||
170 | * Find sub native path. |
||
171 | * |
||
172 | * @param View $view |
||
173 | * @param string $subDir |
||
174 | * @return string|null |
||
175 | */ |
||
176 | protected function findSubNativePath(View $view, string $subDir): ?string |
||
188 | } |
||
189 |