‪TYPO3CMS  ‪main
DependencyEntityFactory.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 
21 
28 {
29  protected array ‪$elements = [];
30  protected array ‪$references = [];
31 
35  public function ‪getElement(string $table, int $id, array $data, ‪DependencyResolver $dependency): ‪ElementEntity
36  {
37  $element = GeneralUtility::makeInstance(ElementEntity::class, $table, $id, $data, $dependency);
38  $elementName = $element->__toString();
39  if (!isset($this->elements[$elementName])) {
40  $this->elements[$elementName] = $element;
41  }
42  return $this->elements[$elementName];
43  }
44 
48  public function ‪getReference(‪ElementEntity $element, string $field): ‪ReferenceEntity
49  {
50  $referenceName = $element->‪__toString() . '.' . $field;
51  if (!isset($this->references[$referenceName][$field])) {
52  $this->references[$referenceName][$field] = GeneralUtility::makeInstance(ReferenceEntity::class, $element, $field);
53  }
54  return $this->references[$referenceName][$field];
55  }
56 
63  public function ‪getReferencedElement(string $table, int $id, string $field, array $data, ‪DependencyResolver $dependency): ‪ReferenceEntity
64  {
65  return $this->‪getReference($this->‪getElement($table, $id, $data, $dependency), $field);
66  }
67 }
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\getReferencedElement
‪getReferencedElement(string $table, int $id, string $field, array $data, DependencyResolver $dependency)
Definition: DependencyEntityFactory.php:63
‪TYPO3\CMS\Workspaces\Dependency\ReferenceEntity
Definition: ReferenceEntity.php:26
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity
Definition: ElementEntity.php:30
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\__toString
‪__toString()
Definition: ElementEntity.php:132
‪TYPO3\CMS\Workspaces\Dependency\DependencyResolver
Definition: DependencyResolver.php:28
‪TYPO3\CMS\Workspaces\Dependency
Definition: DependencyEntityFactory.php:18
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory
Definition: DependencyEntityFactory.php:28
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\$references
‪array $references
Definition: DependencyEntityFactory.php:30
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\$elements
‪array $elements
Definition: DependencyEntityFactory.php:29
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\getReference
‪getReference(ElementEntity $element, string $field)
Definition: DependencyEntityFactory.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Workspaces\Dependency\DependencyEntityFactory\getElement
‪getElement(string $table, int $id, array $data, DependencyResolver $dependency)
Definition: DependencyEntityFactory.php:35