‪TYPO3CMS  11.5
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 
45  protected function ‪getDefaultStructureDefinition(): array
46  {
47  $filePermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'];
48  $directoryPermission = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'];
50  $structure = [
51  // Note that root node has no trailing slash like all others
53  'targetPermission' => $directoryPermission,
54  'children' => [
55  [
56  'name' => 'typo3temp',
57  'type' => DirectoryNode::class,
58  'targetPermission' => $directoryPermission,
59  'children' => [
60  [
61  'name' => 'index.html',
62  'type' => FileNode::class,
63  'targetPermission' => $filePermission,
64  'targetContent' => '',
65  ],
67  [
68  'name' => 'var',
69  'type' => DirectoryNode::class,
70  'targetPermission' => $directoryPermission,
71  'children' => [
72  [
73  'name' => '.htaccess',
74  'type' => FileNode::class,
75  'targetPermission' => $filePermission,
76  'targetContentFile' => self::TEMPLATE_PATH . '/typo3temp-var-htaccess',
77  ],
78  [
79  'name' => 'charset',
80  'type' => DirectoryNode::class,
81  'targetPermission' => $directoryPermission,
82  ],
83  [
84  'name' => 'cache',
85  'type' => DirectoryNode::class,
86  'targetPermission' => $directoryPermission,
87  ],
88  [
89  'name' => 'build',
90  'type' => DirectoryNode::class,
91  'targetPermission' => $directoryPermission,
92  ],
93  [
94  'name' => 'lock',
95  'type' => DirectoryNode::class,
96  'targetPermission' => $directoryPermission,
97  ],
98  ],
99  ],
100  ],
101  ],
102  [
103  'name' => 'typo3conf',
104  'type' => DirectoryNode::class,
105  'targetPermission' => $directoryPermission,
106  'children' => [
107  [
108  'name' => 'ext',
109  'type' => DirectoryNode::class,
110  'targetPermission' => $directoryPermission,
111  ],
112  [
113  'name' => 'l10n',
114  'type' => DirectoryNode::class,
115  'targetPermission' => $directoryPermission,
116  ],
117  [
118  'name' => 'sites',
119  'type' => DirectoryNode::class,
120  'targetPermission' => $directoryPermission,
121  ],
122  ],
123  ],
124  $this->‪getFileadminStructure(),
125  ],
126  ];
127 
128  // Have a default .htaccess if running apache web server or a default web.config if running IIS
129  if ($this->‪isApacheServer()) {
130  $structure['children'][] = [
131  'name' => '.htaccess',
132  'type' => FileNode::class,
133  'targetPermission' => $filePermission,
134  'targetContentFile' => self::TEMPLATE_PATH . '/root-htaccess',
135  ];
136  } elseif ($this->‪isMicrosoftIisServer()) {
137  $structure['children'][] = [
138  'name' => 'web.config',
139  'type' => FileNode::class,
140  'targetPermission' => $filePermission,
141  'targetContentFile' => self::TEMPLATE_PATH . '/root-web-config',
142  ];
143  }
144  } else {
145  // This is when the public path is a subfolder (e.g. public/ or web/)
146  $publicPath = substr(‪Environment::getPublicPath(), strlen(‪Environment::getProjectPath()) + 1);
147 
148  $publicPathSubStructure = [
149  [
150  'name' => 'typo3temp',
151  'type' => DirectoryNode::class,
152  'targetPermission' => $directoryPermission,
153  'children' => [
154  [
155  'name' => 'index.html',
156  'type' => FileNode::class,
157  'targetPermission' => $filePermission,
158  'targetContent' => '',
159  ],
161  ],
162  ],
163  [
164  'name' => 'typo3conf',
165  'type' => DirectoryNode::class,
166  'targetPermission' => $directoryPermission,
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' => self::TEMPLATE_PATH . '/root-htaccess',
178  ];
179  } elseif ($this->‪isMicrosoftIisServer()) {
180  $publicPathSubStructure[] = [
181  'name' => 'web.config',
182  'type' => FileNode::class,
183  'targetPermission' => $filePermission,
184  'targetContentFile' => self::TEMPLATE_PATH . '/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' => self::TEMPLATE_PATH . '/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' => self::TEMPLATE_PATH . '/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' => self::TEMPLATE_PATH . '/fileadmin-temp-htaccess',
300  ],
301  [
302  'name' => 'index.html',
303  'type' => FileNode::class,
304  'targetPermission' => $filePermission,
305  'targetContentFile' => self::TEMPLATE_PATH . '/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' => self::TEMPLATE_PATH . '/fileadmin-user_upload-temp-importexport-htaccess',
335  ],
336  [
337  'name' => 'index.html',
338  'type' => FileNode::class,
339  'targetPermission' => $filePermission,
340  'targetContentFile' => self::TEMPLATE_PATH . '/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:33
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getTemporaryAssetsFolderStructure
‪array getTemporaryAssetsFolderStructure()
Definition: DefaultFactory.php:363
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:206
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getFileadminStructure
‪getFileadminStructure()
Definition: DefaultFactory.php:275
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getDefaultStructureDefinition
‪array getDefaultStructureDefinition()
Definition: DefaultFactory.php:45
‪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\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:177
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\TEMPLATE_PATH
‪const TEMPLATE_PATH
Definition: DefaultFactory.php:26
‪TYPO3\CMS\Install\FolderStructure\RootNode
Definition: RootNode.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Install\FolderStructure\DefaultFactory\getPublicStructure
‪array getPublicStructure(string $publicPath, array $subStructure)
Definition: DefaultFactory.php:252
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43