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