‪TYPO3CMS  9.5
DependencyEntityFactory.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
23 {
27  protected ‪$elements = [];
28 
32  protected ‪$references = [];
33 
43  public function ‪getElement($table, $id, array $data = [], ‪DependencyResolver $dependency)
44  {
45  $element = GeneralUtility::makeInstance(ElementEntity::class, $table, $id, $data, $dependency);
46  $elementName = $element->__toString();
47  if (!isset($this->elements[$elementName])) {
48  $this->elements[$elementName] = $element;
49  }
50  return $this->elements[$elementName];
51  }
52 
60  public function ‪getReference(‪ElementEntity $element, $field)
61  {
62  $referenceName = $element->‪__toString() . '.' . $field;
63  if (!isset($this->references[$referenceName][$field])) {
64  $this->references[$referenceName][$field] = GeneralUtility::makeInstance(ReferenceEntity::class, $element, $field);
65  }
66  return $this->references[$referenceName][$field];
67  }
68 
81  public function ‪getReferencedElement($table, $id, $field, array $data = [], ‪DependencyResolver $dependency)
82  {
83  return $this->‪getReference($this->‪getElement($table, $id, $data, $dependency), $field);
84  }
85 }
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\getElement
‪ElementEntity getElement($table, $id, array $data=[], DependencyResolver $dependency)
Definition: DependencyEntityFactory.php:41
‪TYPO3\CMS\Workspaces\Dependency\ReferenceEntity
Definition: ReferenceEntity.php:21
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\__toString
‪string __toString()
Definition: ElementEntity.php:191
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity
Definition: ElementEntity.php:24
‪TYPO3\CMS\Workspaces\Dependency\DependencyResolver
Definition: DependencyResolver.php:23
‪TYPO3\CMS\Workspaces\Dependency
Definition: DependencyEntityFactory.php:2
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory
Definition: DependencyEntityFactory.php:23
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\$references
‪array $references
Definition: DependencyEntityFactory.php:30
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\getReference
‪ReferenceEntity getReference(ElementEntity $element, $field)
Definition: DependencyEntityFactory.php:58
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\$elements
‪array $elements
Definition: DependencyEntityFactory.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\getReferencedElement
‪ReferenceEntity getReferencedElement($table, $id, $field, array $data=[], DependencyResolver $dependency)
Definition: DependencyEntityFactory.php:79