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