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