TYPO3 CMS  TYPO3_6-2
DependencyResolver.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $workspace = 0;
26 
30  protected $factory;
31 
35  protected $elements = array();
36 
40  protected $eventCallbacks = array();
41 
46 
50  protected $outerMostParents;
51 
57  public function setWorkspace($workspace) {
58  $this->workspace = (int) $workspace;
59  }
60 
66  public function getWorkspace() {
67  return $this->workspace;
68  }
69 
77  public function setEventCallback($eventName, \TYPO3\CMS\Version\Dependency\EventCallback $callback) {
78  $this->eventCallbacks[$eventName] = $callback;
79  return $this;
80  }
81 
90  public function executeEventCallback($eventName, $caller, array $callerArguments = array()) {
91  if (isset($this->eventCallbacks[$eventName])) {
93  $callback = $this->eventCallbacks[$eventName];
94  return $callback->execute($callerArguments, $caller, $eventName);
95  }
96  return NULL;
97  }
98 
106  $this->outerMostParentsRequireReferences = (bool) $outerMostParentsRequireReferences;
107  return $this;
108  }
109 
118  public function addElement($table, $id, array $data = array()) {
119  $element = $this->getFactory()->getElement($table, $id, $data, $this);
120  $elementName = $element->__toString();
121  $this->elements[$elementName] = $element;
122  return $element;
123  }
124 
130  public function getOuterMostParents() {
131  if (!isset($this->outerMostParents)) {
132  $this->outerMostParents = array();
134  foreach ($this->elements as $element) {
135  $this->processOuterMostParent($element);
136  }
137  }
139  }
140 
147  protected function processOuterMostParent(\TYPO3\CMS\Version\Dependency\ElementEntity $element) {
148  if ($this->outerMostParentsRequireReferences === FALSE || $element->hasReferences()) {
149  $outerMostParent = $element->getOuterMostParent();
150  if ($outerMostParent !== FALSE) {
151  $outerMostParentName = $outerMostParent->__toString();
152  if (!isset($this->outerMostParents[$outerMostParentName])) {
153  $this->outerMostParents[$outerMostParentName] = $outerMostParent;
154  }
155  }
156  }
157  }
158 
166  public function getNestedElements(\TYPO3\CMS\Version\Dependency\ElementEntity $outerMostParent) {
167  $outerMostParentName = $outerMostParent->__toString();
168  if (!isset($this->outerMostParents[$outerMostParentName])) {
169  throw new \RuntimeException('Element "' . $outerMostParentName . '" was not detected as outermost parent.', 1289318609);
170  }
171  $nestedStructure = array_merge(array($outerMostParentName => $outerMostParent), $outerMostParent->getNestedChildren());
172  return $nestedStructure;
173  }
174 
180  public function getElements() {
181  return $this->elements;
182  }
183 
189  public function getFactory() {
190  if (!isset($this->factory)) {
191  $this->factory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\Dependency\\DependencyEntityFactory');
192  }
193  return $this->factory;
194  }
195 
196 }
processOuterMostParent(\TYPO3\CMS\Version\Dependency\ElementEntity $element)
setEventCallback($eventName, \TYPO3\CMS\Version\Dependency\EventCallback $callback)
setOuterMostParentsRequireReferences($outerMostParentsRequireReferences)
addElement($table, $id, array $data=array())
getNestedElements(\TYPO3\CMS\Version\Dependency\ElementEntity $outerMostParent)