‪TYPO3CMS  9.5
PseudoFileReference.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 
34 {
38  private ‪$_uid;
39 
43  private ‪$_uidLocal;
44 
45  public function ‪__sleep(): array
46  {
47  // in case this is a persisted file reference, use it directly as reference
48  // as a consequence, in-memory changes are lost and have to be persisted first
49  // (it seems that in ext:form a `FileReference` was never persisted)
50  if ($this->uid > 0) {
51  $this->_uid = (int)$this->uid;
52  return ['_uid'];
53  }
54  if ($this->‪getOriginalResource()->‪getUid() > 0) {
55  $this->_uid = (int)$this->‪getOriginalResource()->‪getUid();
56  return ['_uid'];
57  }
58  // in case this is a transient file reference, just expose the associated `sys_file.uid`
59  // (based on previous comments, this is the most probably case in ext:form)
60  $this->_uidLocal = (int)$this->‪getOriginalResource()->getOriginalFile()->‪getUid();
61  return ['_uidLocal'];
62  }
63 
64  public function ‪__wakeup(): void
65  {
66  $factory = GeneralUtility::makeInstance(ResourceFactory::class);
67  if ($this->_uid > 0) {
68  $this->originalResource = $factory->getFileReferenceObject($this->_uid);
69  } elseif ($this->_uidLocal > 0) {
70  $this->originalResource = $factory->createFileReferenceObject([
71  'uid_local' => $this->_uidLocal,
72  'uid_foreign' => 0,
73  'uid' => 0,
74  'crop' => null,
75  ]);
76  } else {
77  throw new \LogicException(
78  sprintf('Cannot unserialize %s', static::class),
79  1613216548
80  );
81  }
82  unset($this->_uid, $this->_uidLocal);
83  }
84 }
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFileReference
Definition: PseudoFileReference.php:34
‪TYPO3\CMS\Extbase\Domain\Model\FileReference\getOriginalResource
‪TYPO3 CMS Core Resource FileReference getOriginalResource()
Definition: FileReference.php:57
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter
Definition: FormDefinitionArrayConverter.php:3
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFileReference\$_uid
‪int null $_uid
Definition: PseudoFileReference.php:37
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int getUid()
Definition: AbstractDomainObject.php:62
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Extbase\Domain\Model\FileReference
Definition: FileReference.php:25
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFileReference\$_uidLocal
‪int null $_uidLocal
Definition: PseudoFileReference.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFileReference\__wakeup
‪__wakeup()
Definition: PseudoFileReference.php:62
‪TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFileReference\__sleep
‪__sleep()
Definition: PseudoFileReference.php:43