e547652e76df384b8e8ac9886d661be017b6676a
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / FolderStructure / DefaultFactory.php
1 <?php
2 namespace TYPO3\CMS\Install\FolderStructure;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Core\Bootstrap;
18
19 /**
20 * Factory returns default folder structure object hierarchy
21 */
22 class DefaultFactory
23 {
24 /**
25 * Get default structure object hierarchy
26 *
27 * @return StructureFacadeInterface
28 */
29 public function getStructure()
30 {
31 $rootNode = new RootNode($this->getDefaultStructureDefinition(), null);
32 $structureFacade = new StructureFacade($rootNode);
33 return $structureFacade;
34 }
35
36 /**
37 * Default definition of folder and file structure with dynamic
38 * permission settings
39 *
40 * @return array
41 */
42 protected function getDefaultStructureDefinition()
43 {
44 $filePermission = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'];
45 $directoryPermission = $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
46
47 if (Bootstrap::usesComposerClassLoading()) {
48 // In composer mode the links are configurable and might even be actual files
49 // Ignore this structure in this case
50 $structureAdditional = [];
51 } else {
52 $structureAdditional = [
53 [
54 'name' => 'index.php',
55 'type' => LinkNode::class,
56 'target' => 'typo3_src/index.php',
57 ],
58 [
59 'name' => 'typo3',
60 'type' => LinkNode::class,
61 'target' => 'typo3_src/typo3',
62 ],
63 ];
64 }
65 $structureBase = [
66 [
67 'name' => 'typo3temp',
68 'type' => DirectoryNode::class,
69 'targetPermission' => $directoryPermission,
70 'children' => [
71 [
72 'name' => 'index.html',
73 'type' => FileNode::class,
74 'targetPermission' => $filePermission,
75 'targetContent' => '',
76 ],
77 [
78 'name' => 'assets',
79 'type' => DirectoryNode::class,
80 'targetPermission' => $directoryPermission,
81 'children' => [
82 [
83 'name' => 'compressed',
84 'type' => DirectoryNode::class,
85 'targetPermission' => $directoryPermission
86 ],
87 [
88 'name' => 'css',
89 'type' => DirectoryNode::class,
90 'targetPermission' => $directoryPermission
91 ],
92 [
93 'name' => 'js',
94 'type' => DirectoryNode::class,
95 'targetPermission' => $directoryPermission
96 ],
97 [
98 'name' => 'images',
99 'type' => DirectoryNode::class,
100 'targetPermission' => $directoryPermission
101 ],
102 [
103 'name' => '_processed_',
104 'type' => DirectoryNode::class,
105 'targetPermission' => $directoryPermission
106 ]
107 ]
108 ],
109 [
110 'name' => 'var',
111 'type' => DirectoryNode::class,
112 'targetPermission' => $directoryPermission,
113 'children' => [
114 [
115 'name' => '.htaccess',
116 'type' => FileNode::class,
117 'targetPermission' => $filePermission,
118 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/typo3temp-var-htaccess',
119 ],
120 [
121 'name' => 'charset',
122 'type' => DirectoryNode::class,
123 'targetPermission' => $directoryPermission,
124 ],
125 [
126 'name' => 'Cache',
127 'type' => DirectoryNode::class,
128 'targetPermission' => $directoryPermission,
129 ],
130 [
131 'name' => 'locks',
132 'type' => DirectoryNode::class,
133 'targetPermission' => $directoryPermission,
134 ]
135 ]
136 ],
137 ],
138 ],
139 [
140 'name' => 'typo3conf',
141 'type' => DirectoryNode::class,
142 'targetPermission' => $directoryPermission,
143 'children' => [
144 [
145 'name' => 'ext',
146 'type' => DirectoryNode::class,
147 'targetPermission' => $directoryPermission,
148 ],
149 [
150 'name' => 'l10n',
151 'type' => DirectoryNode::class,
152 'targetPermission' => $directoryPermission,
153 ],
154 ],
155 ],
156 [
157 'name' => 'uploads',
158 'type' => DirectoryNode::class,
159 'targetPermission' => $directoryPermission,
160 'children' => [
161 [
162 'name' => 'index.html',
163 'type' => FileNode::class,
164 'targetPermission' => $filePermission,
165 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/uploads-index.html',
166 ],
167 [
168 'name' => 'media',
169 'type' => DirectoryNode::class,
170 'targetPermission' => $directoryPermission,
171 'children' => [
172 [
173 'name' => 'index.html',
174 'type' => FileNode::class,
175 'targetPermission' => $filePermission,
176 'targetContent' => '',
177 ],
178 ],
179 ],
180 ],
181 ],
182 [
183 'name' => !empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin',
184 'type' => DirectoryNode::class,
185 'targetPermission' => $directoryPermission,
186 'children' => [
187 [
188 'name' => '_temp_',
189 'type' => DirectoryNode::class,
190 'targetPermission' => $directoryPermission,
191 'children' => [
192 [
193 'name' => '.htaccess',
194 'type' => FileNode::class,
195 'targetPermission' => $filePermission,
196 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess',
197 ],
198 [
199 'name' => 'index.html',
200 'type' => FileNode::class,
201 'targetPermission' => $filePermission,
202 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
203 ],
204 ],
205 ],
206 [
207 'name' => 'user_upload',
208 'type' => DirectoryNode::class,
209 'targetPermission' => $directoryPermission,
210 'children' => [
211 [
212 'name' => '_temp_',
213 'type' => DirectoryNode::class,
214 'targetPermission' => $directoryPermission,
215 'children' => [
216 [
217 'name' => 'index.html',
218 'type' => FileNode::class,
219 'targetPermission' => $filePermission,
220 'targetContent' => '',
221 ],
222 [
223 'name' => 'importexport',
224 'type' => DirectoryNode::class,
225 'targetPermission' => $directoryPermission,
226 'children' => [
227 [
228 'name' => '.htaccess',
229 'type' => FileNode::class,
230 'targetPermission' => $filePermission,
231 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-user_upload-temp-importexport-htaccess',
232 ],
233 [
234 'name' => 'index.html',
235 'type' => FileNode::class,
236 'targetPermission' => $filePermission,
237 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
238 ],
239 ],
240 ],
241 ],
242 ],
243 [
244 'name' => 'index.html',
245 'type' => FileNode::class,
246 'targetPermission' => $filePermission,
247 'targetContent' => '',
248 ],
249 ],
250 ],
251 ],
252 ],
253 ];
254
255 return [
256 // Cut off trailing forward / from PATH_site, so root node has no trailing slash like all others
257 'name' => substr(PATH_site, 0, -1),
258 'targetPermission' => $directoryPermission,
259 'children' => array_merge($structureAdditional, $structureBase)
260 ];
261 }
262 }