‪TYPO3CMS  9.5
SvgFileSlot.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
25 {
29  protected ‪$sanitizer;
30 
34  protected ‪$typeCheck;
35 
37  {
38  $this->sanitizer = ‪$sanitizer ?? GeneralUtility::makeInstance(SvgSanitizer::class);
39  $this->typeCheck = ‪$typeCheck ?? GeneralUtility::makeInstance(SvgTypeCheck::class);
40  }
41 
42  public function ‪preFileAdd(string $targetFileName, ‪FolderInterface $targetFolder, string $sourceFilePath): void
43  {
44  if ($this->typeCheck->forFilePath($sourceFilePath)) {
45  $this->sanitizer->sanitizeFile($sourceFilePath);
46  }
47  }
48 
49  public function ‪preFileReplace(‪FileInterface $file, string $filePath): void
50  {
51  if ($this->typeCheck->forFilePath($filePath)) {
52  $this->sanitizer->sanitizeFile($filePath);
53  }
54  }
55 
56  public function ‪postFileSetContents(‪FileInterface $file, $content): void
57  {
58  if (!$this->typeCheck->forResource($file)) {
59  return;
60  }
61  $content = (string)$content;
62  $sanitizedContent = $this->sanitizer->sanitizeContent($content);
63  // cave: setting content will trigger calling this handler again
64  // (having custom-flags on `FileInterface` would allow to mark it as "processed")
65  if ($sanitizedContent !== $content) {
66  $file->‪setContents($sanitizedContent);
67  }
68  }
69 }
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot
Definition: SvgFileSlot.php:25
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot\preFileReplace
‪preFileReplace(FileInterface $file, string $filePath)
Definition: SvgFileSlot.php:47
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot\postFileSetContents
‪postFileSetContents(FileInterface $file, $content)
Definition: SvgFileSlot.php:54
‪TYPO3\CMS\Core\Resource\FileInterface
Definition: FileInterface.php:21
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot\__construct
‪__construct(SvgSanitizer $sanitizer=null, SvgTypeCheck $typeCheck=null)
Definition: SvgFileSlot.php:34
‪TYPO3\CMS\Core\Resource\Security
Definition: FileMetadataPermissionsAspect.php:2
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot\$typeCheck
‪SvgTypeCheck $typeCheck
Definition: SvgFileSlot.php:32
‪TYPO3\CMS\Core\Resource\Security\SvgSanitizer
Definition: SvgSanitizer.php:23
‪TYPO3\CMS\Core\Resource\FileInterface\setContents
‪File setContents($contents)
‪TYPO3\CMS\Core\Resource\Security\SvgTypeCheck
Definition: SvgTypeCheck.php:26
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.php:21
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot\$sanitizer
‪SvgSanitizer $sanitizer
Definition: SvgFileSlot.php:28
‪TYPO3\CMS\Core\Resource\Security\SvgFileSlot\preFileAdd
‪preFileAdd(string $targetFileName, FolderInterface $targetFolder, string $sourceFilePath)
Definition: SvgFileSlot.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45