[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / Classes / Dependency / DependencyEntityFactory.php
1 <?php
2 namespace TYPO3\CMS\Version\Dependency;
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 /**
17 * Object to create and keep track of element or reference entities.
18 */
19 class DependencyEntityFactory {
20
21 /**
22 * @var array
23 */
24 protected $elements = array();
25
26 /**
27 * @var array
28 */
29 protected $references = array();
30
31 /**
32 * Gets and registers a new element.
33 *
34 * @param string $table
35 * @param integer $id
36 * @param array $data (optional)
37 * @param \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency
38 * @return \TYPO3\CMS\Version\Dependency\ElementEntity
39 */
40 public function getElement($table, $id, array $data = array(), \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency) {
41 /** @var $element ElementEntity */
42 $element = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\Dependency\\ElementEntity', $table, $id, $data, $dependency);
43 $elementName = $element->__toString();
44 if (!isset($this->elements[$elementName])) {
45 $this->elements[$elementName] = $element;
46 }
47 return $this->elements[$elementName];
48 }
49
50 /**
51 * Gets and registers a new reference.
52 *
53 * @param \TYPO3\CMS\Version\Dependency\ElementEntity $element
54 * @param string $field
55 * @return \TYPO3\CMS\Version\Dependency\ReferenceEntity
56 */
57 public function getReference(\TYPO3\CMS\Version\Dependency\ElementEntity $element, $field) {
58 $referenceName = $element->__toString() . '.' . $field;
59 if (!isset($this->references[$referenceName][$field])) {
60 $this->references[$referenceName][$field] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\Dependency\\ReferenceEntity', $element, $field);
61 }
62 return $this->references[$referenceName][$field];
63 }
64
65 /**
66 * Gets and registers a new reference.
67 *
68 * @param string $table
69 * @param integer $id
70 * @param string $field
71 * @param array $data (optional
72 * @param \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency
73 * @return \TYPO3\CMS\Version\Dependency\ReferenceEntity
74 * @see getElement
75 * @see getReference
76 */
77 public function getReferencedElement($table, $id, $field, array $data = array(), \TYPO3\CMS\Version\Dependency\DependencyResolver $dependency) {
78 return $this->getReference($this->getElement($table, $id, $data, $dependency), $field);
79 }
80
81 }