‪TYPO3CMS  10.4
PseudoFile.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 
30 {
34  protected ‪$nameFileInfo;
35 
39  protected ‪$payloadFileInfo;
40 
44  protected ‪$payloadFilePath;
45 
52  public function ‪__construct(array $uploadInfo)
53  {
54  if (!isset($uploadInfo['tmp_name']) || !isset($uploadInfo['name'])) {
55  throw new ‪TypeConverterException(
56  'Could not determine uploaded file',
57  1602103603
58  );
59  }
60  $this->nameFileInfo = new \SplFileInfo($uploadInfo['name']);
61  $this->payloadFilePath = $uploadInfo['tmp_name'];
62  $this->payloadFileInfo = GeneralUtility::makeInstance(FileInfo::class, $uploadInfo['tmp_name']);
63  }
64 
65  public function ‪getName(): string
66  {
67  return $this->nameFileInfo->getBasename();
68  }
69 
70  public function ‪getNameWithoutExtension(): string
71  {
72  // `image...png`
73  return rtrim(
74  $this->nameFileInfo->getBasename($this->getExtension()),
75  '.'
76  );
77  }
78 
79  public function ‪getExtension(): string
80  {
81  return $this->nameFileInfo->getExtension();
82  }
83 
84  public function ‪getSize(): ?int
85  {
86  // returns `null` in case size is empty (includes `0`)
87  // @see \TYPO3\CMS\Core\Resource\AbstractFile::getSize()
88  return $this->payloadFileInfo->getSize() ?: null;
89  }
90 
91  public function ‪getMimeType(): ?string
92  {
93  $mimeType = $this->payloadFileInfo->getMimeType();
94  return is_string($mimeType) ? $mimeType : null;
95  }
96 
97  public function ‪getContents(): string
98  {
99  return file_get_contents($this->payloadFilePath);
100  }
101 
102  public function ‪getSha1(): string
103  {
104  return sha1_file($this->payloadFilePath);
105  }
106 }
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getName
‪getName()
Definition: PseudoFile.php:62
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getExtension
‪getExtension()
Definition: PseudoFile.php:76
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getSha1
‪getSha1()
Definition: PseudoFile.php:99
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter
Definition: FormDefinitionArrayConverter.php:18
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\$payloadFileInfo
‪FileInfo $payloadFileInfo
Definition: PseudoFile.php:37
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getNameWithoutExtension
‪getNameWithoutExtension()
Definition: PseudoFile.php:67
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\__construct
‪__construct(array $uploadInfo)
Definition: PseudoFile.php:49
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\$nameFileInfo
‪SplFileInfo $nameFileInfo
Definition: PseudoFile.php:33
‪TYPO3\CMS\Form\Mvc\Property\Exception\TypeConverterException
Definition: TypeConverterException.php:24
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getSize
‪getSize()
Definition: PseudoFile.php:81
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getContents
‪getContents()
Definition: PseudoFile.php:94
‪TYPO3\CMS\Core\Type\File\FileInfo
Definition: FileInfo.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\getMimeType
‪getMimeType()
Definition: PseudoFile.php:88
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile\$payloadFilePath
‪string $payloadFilePath
Definition: PseudoFile.php:41
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFile
Definition: PseudoFile.php:30