74fca205db4a1f71dd99cd8de1ec2349dec46b3c
[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 * @throws Exception
28 * @return RootNode
29 * @TODO: Use objectManager instead of new (will be injected)
30 */
31 public function getStructure()
32 {
33 $rootNode = new RootNode($this->getDefaultStructureDefinition(), null);
34 if (!($rootNode instanceof RootNodeInterface)) {
35 throw new Exception(
36 'Root node must implement RootNodeInterface',
37 1366139176
38 );
39 }
40 $structureFacade = new StructureFacade($rootNode);
41 if (!($structureFacade instanceof StructureFacadeInterface)) {
42 throw new Exception(
43 'Structure facade must implement StructureFacadeInterface',
44 1366535827
45 );
46 }
47 return $structureFacade;
48 }
49
50 /**
51 * Default definition of folder and file structure with dynamic
52 * permission settings
53 *
54 * @return array
55 */
56 protected function getDefaultStructureDefinition()
57 {
58 $filePermission = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'];
59 $directoryPermission = $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
60
61 if (Bootstrap::usesComposerClassLoading()) {
62 // In composer mode the links are configurable and might even be actual files
63 // Ignore this structure in this case
64 $structureAdditional = array();
65 } else {
66 $structureAdditional = array(
67 array(
68 'name' => 'index.php',
69 'type' => LinkNode::class,
70 'target' => 'typo3_src/index.php',
71 ),
72 array(
73 'name' => 'typo3',
74 'type' => LinkNode::class,
75 'target' => 'typo3_src/typo3',
76 ),
77 array(
78 'name' => 'typo3_src',
79 'type' => LinkNode::class,
80 ),
81 );
82 }
83 $structureBase = array(
84 array(
85 'name' => 'typo3temp',
86 'type' => DirectoryNode::class,
87 'targetPermission' => $directoryPermission,
88 'children' => array(
89 array(
90 'name' => 'index.html',
91 'type' => FileNode::class,
92 'targetPermission' => $filePermission,
93 'targetContent' => '',
94 ),
95 array(
96 'name' => 'compressor',
97 'type' => DirectoryNode::class,
98 'targetPermission' => $directoryPermission,
99 ),
100 array(
101 'name' => 'cs',
102 'type' => DirectoryNode::class,
103 'targetPermission' => $directoryPermission,
104 ),
105 array(
106 'name' => 'Cache',
107 'type' => DirectoryNode::class,
108 'targetPermission' => $directoryPermission,
109 ),
110 array(
111 'name' => 'GB',
112 'type' => DirectoryNode::class,
113 'targetPermission' => $directoryPermission,
114 ),
115 array(
116 'name' => 'locks',
117 'type' => DirectoryNode::class,
118 'targetPermission' => $directoryPermission,
119 ),
120 array(
121 'name' => 'pics',
122 'type' => DirectoryNode::class,
123 'targetPermission' => $directoryPermission,
124 ),
125 array(
126 'name' => 'temp',
127 'type' => DirectoryNode::class,
128 'targetPermission' => $directoryPermission,
129 ),
130 array(
131 'name' => '_processed_',
132 'type' => DirectoryNode::class,
133 'targetPermission' => $directoryPermission,
134 ),
135 ),
136 ),
137 array(
138 'name' => 'typo3conf',
139 'type' => DirectoryNode::class,
140 'targetPermission' => $directoryPermission,
141 'children' => array(
142 array(
143 'name' => 'ext',
144 'type' => DirectoryNode::class,
145 'targetPermission' => $directoryPermission,
146 ),
147 array(
148 'name' => 'l10n',
149 'type' => DirectoryNode::class,
150 'targetPermission' => $directoryPermission,
151 ),
152 ),
153 ),
154 array(
155 'name' => 'uploads',
156 'type' => DirectoryNode::class,
157 'targetPermission' => $directoryPermission,
158 'children' => array(
159 array(
160 'name' => 'index.html',
161 'type' => FileNode::class,
162 'targetPermission' => $filePermission,
163 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/uploads-index.html',
164 ),
165 array(
166 'name' => 'media',
167 'type' => DirectoryNode::class,
168 'targetPermission' => $directoryPermission,
169 'children' => array(
170 array(
171 'name' => 'index.html',
172 'type' => FileNode::class,
173 'targetPermission' => $filePermission,
174 'targetContent' => '',
175 ),
176 ),
177 ),
178 array(
179 'name' => 'pics',
180 'type' => DirectoryNode::class,
181 'targetPermission' => $directoryPermission,
182 'children' => array(
183 array(
184 'name' => 'index.html',
185 'type' => FileNode::class,
186 'targetPermission' => $filePermission,
187 'targetContent' => '',
188 ),
189 ),
190 ),
191 array(
192 'name' => 'tx_felogin',
193 'type' => DirectoryNode::class,
194 'targetPermission' => $directoryPermission,
195 ),
196 ),
197 ),
198 array(
199 'name' => !empty($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin',
200 'type' => DirectoryNode::class,
201 'targetPermission' => $directoryPermission,
202 'children' => array(
203 array(
204 'name' => '_temp_',
205 'type' => DirectoryNode::class,
206 'targetPermission' => $directoryPermission,
207 'children' => array(
208 array(
209 'name' => '.htaccess',
210 'type' => FileNode::class,
211 'targetPermission' => $filePermission,
212 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess',
213 ),
214 array(
215 'name' => 'index.html',
216 'type' => FileNode::class,
217 'targetPermission' => $filePermission,
218 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
219 ),
220 ),
221 ),
222 array(
223 'name' => 'user_upload',
224 'type' => DirectoryNode::class,
225 'targetPermission' => $directoryPermission,
226 'children' => array(
227 array(
228 'name' => '_temp_',
229 'type' => DirectoryNode::class,
230 'targetPermission' => $directoryPermission,
231 'children' => array(
232 array(
233 'name' => 'index.html',
234 'type' => FileNode::class,
235 'targetPermission' => $filePermission,
236 'targetContent' => '',
237 ),
238 array(
239 'name' => 'importexport',
240 'type' => DirectoryNode::class,
241 'targetPermission' => $directoryPermission,
242 'children' => array(
243 array(
244 'name' => '.htaccess',
245 'type' => FileNode::class,
246 'targetPermission' => $filePermission,
247 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-user_upload-temp-importexport-htaccess',
248 ),
249 array(
250 'name' => 'index.html',
251 'type' => FileNode::class,
252 'targetPermission' => $filePermission,
253 'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
254 ),
255 ),
256 ),
257 ),
258 ),
259 array(
260 'name' => 'index.html',
261 'type' => FileNode::class,
262 'targetPermission' => $filePermission,
263 'targetContent' => '',
264 ),
265 ),
266 ),
267 ),
268 ),
269 );
270
271 return array(
272 // Cut off trailing forward / from PATH_site, so root node has no trailing slash like all others
273 'name' => substr(PATH_site, 0, -1),
274 'targetPermission' => $directoryPermission,
275 'children' => array_merge($structureAdditional, $structureBase)
276 );
277 }
278 }