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