‪TYPO3CMS  ‪main
DefaultFactory.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
26 {
27  private const ‪TEMPLATE_PATH = __DIR__ . '/../../Resources/Private/FolderStructureTemplateFiles';
28 
34  public function ‪getStructure(‪WebserverType $webserverType = WebserverType::Other)
35  {
36  $rootNode = new ‪RootNode($this->‪getDefaultStructureDefinition($webserverType), null);
37  return new ‪StructureFacade($rootNode);
38  }
39 
44  protected function ‪getDefaultStructureDefinition(‪WebserverType $webserverType): array
45  {
46  $filePermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'];
47  $directoryPermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
49  $structure = [
50  // Note that root node has no trailing slash like all others
52  'targetPermission' => $directoryPermission,
53  'children' => [
54  [
55  'name' => 'typo3temp',
56  'type' => DirectoryNode::class,
57  'targetPermission' => $directoryPermission,
58  'children' => [
59  [
60  'name' => 'index.html',
61  'type' => FileNode::class,
62  'targetPermission' => $filePermission,
63  'targetContent' => '',
64  ],
66  [
67  'name' => 'var',
68  'type' => DirectoryNode::class,
69  'targetPermission' => $directoryPermission,
70  'children' => [
71  [
72  'name' => '.htaccess',
73  'type' => FileNode::class,
74  'targetPermission' => $filePermission,
75  'targetContentFile' => self::TEMPLATE_PATH . '/typo3temp-var-htaccess',
76  ],
77  [
78  'name' => 'charset',
79  'type' => DirectoryNode::class,
80  'targetPermission' => $directoryPermission,
81  ],
82  [
83  'name' => 'cache',
84  'type' => DirectoryNode::class,
85  'targetPermission' => $directoryPermission,
86  ],
87  [
88  'name' => 'build',
89  'type' => DirectoryNode::class,
90  'targetPermission' => $directoryPermission,
91  ],
92  [
93  'name' => 'lock',
94  'type' => DirectoryNode::class,
95  'targetPermission' => $directoryPermission,
96  ],
97  ],
98  ],
99  ],
100  ],
101  [
102  'name' => 'typo3conf',
103  'type' => DirectoryNode::class,
104  'targetPermission' => $directoryPermission,
105  'children' => [
106  [
107  'name' => 'ext',
108  'type' => DirectoryNode::class,
109  'targetPermission' => $directoryPermission,
110  ],
111  [
112  'name' => 'l10n',
113  'type' => DirectoryNode::class,
114  'targetPermission' => $directoryPermission,
115  ],
116  [
117  'name' => 'sites',
118  'type' => DirectoryNode::class,
119  'targetPermission' => $directoryPermission,
120  ],
121  [
122  'name' => 'system',
123  'type' => DirectoryNode::class,
124  'targetPermission' => $directoryPermission,
125  ],
126  ],
127  ],
128  $this->‪getFileadminStructure(),
129  ],
130  ];
131 
132  // Have a default .htaccess if running apache web server or a default web.config if running IIS
133  if ($webserverType->isApacheServer()) {
134  $structure['children'][] = [
135  'name' => '.htaccess',
136  'type' => FileNode::class,
137  'targetPermission' => $filePermission,
138  'targetContentFile' => self::TEMPLATE_PATH . '/root-htaccess',
139  ];
140  } elseif ($webserverType->isMicrosoftInternetInformationServer()) {
141  $structure['children'][] = [
142  'name' => 'web.config',
143  'type' => FileNode::class,
144  'targetPermission' => $filePermission,
145  'targetContentFile' => self::TEMPLATE_PATH . '/root-web-config',
146  ];
147  }
148  } else {
149  // This is when the public path is a subfolder (e.g. public/ or web/)
150  $publicPath = substr(‪Environment::getPublicPath(), strlen(‪Environment::getProjectPath()) + 1);
151 
152  $publicPathSubStructure = [
153  [
154  'name' => 'typo3temp',
155  'type' => DirectoryNode::class,
156  'targetPermission' => $directoryPermission,
157  'children' => [
158  [
159  'name' => 'index.html',
160  'type' => FileNode::class,
161  'targetPermission' => $filePermission,
162  'targetContent' => '',
163  ],
165  ],
166  ],
167  [
168  'name' => 'typo3conf',
169  'type' => DirectoryNode::class,
170  'targetPermission' => $directoryPermission,
171  ],
172  $this->‪getFileadminStructure(),
173  ];
174 
175  // Have a default .htaccess if running apache web server or a default web.config if running IIS
176  if ($webserverType->isApacheServer()) {
177  $publicPathSubStructure[] = [
178  'name' => '.htaccess',
179  'type' => FileNode::class,
180  'targetPermission' => $filePermission,
181  'targetContentFile' => self::TEMPLATE_PATH . '/root-htaccess',
182  ];
183  } elseif ($webserverType->isMicrosoftInternetInformationServer()) {
184  $publicPathSubStructure[] = [
185  'name' => 'web.config',
186  'type' => FileNode::class,
187  'targetPermission' => $filePermission,
188  'targetContentFile' => self::TEMPLATE_PATH . '/root-web-config',
189  ];
190  }
191 
192  $structure = [
193  // Note that root node has no trailing slash like all others
194  'name' => ‪Environment::getProjectPath(),
195  'targetPermission' => $directoryPermission,
196  'children' => [
197  [
198  'name' => 'config',
199  'type' => DirectoryNode::class,
200  'targetPermission' => $directoryPermission,
201  'children' => [
202  [
203  'name' => 'sites',
204  'type' => DirectoryNode::class,
205  'targetPermission' => $directoryPermission,
206  ],
207  [
208  'name' => 'system',
209  'type' => DirectoryNode::class,
210  'targetPermission' => $directoryPermission,
211  ],
212  ],
213  ],
214  $this->‪getPublicStructure($publicPath, $publicPathSubStructure),
215  [
216  'name' => 'var',
217  'type' => DirectoryNode::class,
218  'targetPermission' => $directoryPermission,
219  'children' => [
220  [
221  'name' => '.htaccess',
222  'type' => FileNode::class,
223  'targetPermission' => $filePermission,
224  'targetContentFile' => self::TEMPLATE_PATH . '/typo3temp-var-htaccess',
225  ],
226  [
227  'name' => 'charset',
228  'type' => DirectoryNode::class,
229  'targetPermission' => $directoryPermission,
230  ],
231  [
232  'name' => 'cache',
233  'type' => DirectoryNode::class,
234  'targetPermission' => $directoryPermission,
235  ],
236  [
237  'name' => 'labels',
238  'type' => DirectoryNode::class,
239  'targetPermission' => $directoryPermission,
240  ],
241  [
242  'name' => 'lock',
243  'type' => DirectoryNode::class,
244  'targetPermission' => $directoryPermission,
245  ],
246  ],
247  ],
248  ],
249  ];
250  }
251  return $structure;
252  }
253 
257  protected function ‪getPublicStructure(string $publicPath, array $subStructure): array
258  {
259  $directoryPermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
260  $publicPathParts = array_reverse(explode('/', $publicPath));
261 
262  $lastNode = null;
263  foreach ($publicPathParts as $publicPathPart) {
264  $node = [
265  'name' => $publicPathPart,
266  'type' => DirectoryNode::class,
267  'targetPermission' => $directoryPermission,
268  ];
269  if ($lastNode !== null) {
270  $node['children'][] = $lastNode;
271  } else {
272  $node['children'] = $subStructure;
273  }
274  $lastNode = $node;
275  }
276 
277  return $lastNode;
278  }
279 
280  protected function ‪getFileadminStructure(): array
281  {
282  $filePermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'];
283  $directoryPermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
284  return [
285  'name' => !empty(‪$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) ? rtrim(‪$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') : 'fileadmin',
286  'type' => DirectoryNode::class,
287  'targetPermission' => $directoryPermission,
288  'children' => [
289  [
290  'name' => '.htaccess',
291  'type' => FileNode::class,
292  'targetPermission' => $filePermission,
293  'targetContentFile' => self::TEMPLATE_PATH . '/resources-root-htaccess',
294  ],
295  [
296  'name' => '_temp_',
297  'type' => DirectoryNode::class,
298  'targetPermission' => $directoryPermission,
299  'children' => [
300  [
301  'name' => '.htaccess',
302  'type' => FileNode::class,
303  'targetPermission' => $filePermission,
304  'targetContentFile' => self::TEMPLATE_PATH . '/fileadmin-temp-htaccess',
305  ],
306  [
307  'name' => 'index.html',
308  'type' => FileNode::class,
309  'targetPermission' => $filePermission,
310  'targetContentFile' => self::TEMPLATE_PATH . '/fileadmin-temp-index.html',
311  ],
312  ],
313  ],
314  [
315  'name' => 'user_upload',
316  'type' => DirectoryNode::class,
317  'targetPermission' => $directoryPermission,
318  'children' => [
319  [
320  'name' => '_temp_',
321  'type' => DirectoryNode::class,
322  'targetPermission' => $directoryPermission,
323  'children' => [
324  [
325  'name' => 'index.html',
326  'type' => FileNode::class,
327  'targetPermission' => $filePermission,
328  'targetContent' => '',
329  ],
330  [
331  'name' => 'importexport',
332  'type' => DirectoryNode::class,
333  'targetPermission' => $directoryPermission,
334  'children' => [
335  [
336  'name' => '.htaccess',
337  'type' => FileNode::class,
338  'targetPermission' => $filePermission,
339  'targetContentFile' => self::TEMPLATE_PATH . '/fileadmin-user_upload-temp-importexport-htaccess',
340  ],
341  [
342  'name' => 'index.html',
343  'type' => FileNode::class,
344  'targetPermission' => $filePermission,
345  'targetContentFile' => self::TEMPLATE_PATH . '/fileadmin-temp-index.html',
346  ],
347  ],
348  ],
349  ],
350  ],
351  [
352  'name' => 'index.html',
353  'type' => FileNode::class,
354  'targetPermission' => $filePermission,
355  'targetContent' => '',
356  ],
357  ],
358  ],
359  ],
360  ];
361  }
362 
366  protected function ‪getTemporaryAssetsFolderStructure(): array
367  {
368  $directoryPermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
369  return [
370  'name' => 'assets',
371  'type' => DirectoryNode::class,
372  'targetPermission' => $directoryPermission,
373  'children' => [
374  [
375  'name' => 'compressed',
376  'type' => DirectoryNode::class,
377  'targetPermission' => $directoryPermission,
378  ],
379  [
380  'name' => 'css',
381  'type' => DirectoryNode::class,
382  'targetPermission' => $directoryPermission,
383  ],
384  [
385  'name' => 'js',
386  'type' => DirectoryNode::class,
387  'targetPermission' => $directoryPermission,
388  ],
389  [
390  'name' => 'images',
391  'type' => DirectoryNode::class,
392  'targetPermission' => $directoryPermission,
393  ],
394  [
395  'name' => '_processed_',
396  'type' => DirectoryNode::class,
397  'targetPermission' => $directoryPermission,
398  ],
399  ],
400  ];
401  }
402 }
‪TYPO3\CMS\Install\FolderStructure\StructureFacadeInterface
Definition: StructureFacadeInterface.php:24
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getDefaultStructureDefinition
‪getDefaultStructureDefinition(WebserverType $webserverType)
Definition: DefaultFactory.php:44
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getFileadminStructure
‪getFileadminStructure()
Definition: DefaultFactory.php:280
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getPublicStructure
‪getPublicStructure(string $publicPath, array $subStructure)
Definition: DefaultFactory.php:257
‪TYPO3\CMS\Install\FolderStructure\StructureFacade
Definition: StructureFacade.php:26
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory
Definition: DefaultFactory.php:26
‪TYPO3\CMS\Install\FolderStructure
Definition: AbstractNode.php:16
‪TYPO3\CMS\Install\WebserverType
‪WebserverType
Definition: WebserverType.php:26
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getStructure
‪StructureFacadeInterface getStructure(WebserverType $webserverType=WebserverType::Other)
Definition: DefaultFactory.php:34
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\TEMPLATE_PATH
‪const TEMPLATE_PATH
Definition: DefaultFactory.php:27
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:28
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getTemporaryAssetsFolderStructure
‪getTemporaryAssetsFolderStructure()
Definition: DefaultFactory.php:366
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41