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