RelationDescription.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\persistence;
12 
14 
15 /**
16  * Instances of RelationDescription describe relations between different types
17  * of PersistentObjects. A relation always has two ends: 'this' end and 'other' end.
18  *
19  * @author ingo herwig <ingo@wemove.com>
20  */
22 
23  protected $thisType = '';
24  protected $thisRole = '';
25  protected $otherType = '';
26  protected $otherRole = '';
27 
28  protected $thisMinMultiplicity = '0';
29  protected $thisMaxMultiplicity = 'unbound';
30  protected $otherMinMultiplicity = '0';
31  protected $otherMaxMultiplicity = 'unbound';
32 
33  protected $thisAggregationKind = 'none';
34  protected $otherAggregationKind = 'none';
35 
36  protected $thisNavigability = true;
37  protected $otherNavigability = true;
38 
39  protected $hierarchyType = 'undefined';
40 
41  private $isMultiValued = null;
42 
43  /**
44  * Constructor.
45  * @param $thisType The PersistentObject type at this end
46  * @param $thisRole The role name at this end
47  * @param $otherType The PersistentObject type at the other end
48  * @param $otherRole The role name at the other end
49  * @param $thisMinMultiplicity The minimum number of instances at this end (number or 'unbound')
50  * @param $thisMaxMultiplicity The maximum number of instances at this end (number or 'unbound')
51  * @param $otherMinMultiplicity The minimum number of instances at the other end (number or 'unbound')
52  * @param $otherMaxMultiplicity The maximum number of instances at the other end (number or 'unbound')
53  * @param $thisAggregationKind The aggregation kind at this end ('none', 'shared' or 'composite')
54  * @param $otherAggregationKind The aggregation kind at the other end ('none', 'shared' or 'composite')
55  * @param $thisNavigability Boolean whether this end is navigable from the other end or not
56  * @param $otherNavigability Boolean whether the other end is navigable from this end or not
57  * @param $hierarchyType The hierarchy type that the other end has in relation to this end ('parent', 'child', 'undefined')
58  */
62 
63  $this->thisType = $thisType;
64  $this->thisRole = $thisRole;
65  $this->otherType = $otherType;
66  $this->otherRole = $otherRole;
67 
68  $this->thisMinMultiplicity = $thisMinMultiplicity;
69  $this->thisMaxMultiplicity = $thisMaxMultiplicity;
70  $this->otherMinMultiplicity = $otherMinMultiplicity;
71  $this->otherMaxMultiplicity = $otherMaxMultiplicity;
72 
73  $this->thisAggregationKind = $thisAggregationKind;
74  $this->otherAggregationKind = $otherAggregationKind;
75 
76  $this->thisNavigability = $thisNavigability;
77  $this->otherNavigability = $otherNavigability;
78 
79  $this->hierarchyType = $hierarchyType;
80  }
81 
82  /**
83  * Determine if there may more than one objects at the other side of the relation
84  * @return Boolean
85  */
86  public function isMultiValued() {
87  if ($this->isMultiValued == null) {
88  $maxMultiplicity = $this->getOtherMaxMultiplicity();
89  $this->isMultiValued = ($maxMultiplicity > 1 || $maxMultiplicity == 'unbounded');
90  }
91  return $this->isMultiValued;
92  }
93 
94  /**
95  * Get the PersistentObject type at this end
96  * @return String
97  */
98  public function getThisType() {
99  return $this->thisType;
100  }
101 
102  /**
103  * Get the PersistentMapper at this end
104  * @return PersistenceMapper
105  */
106  public function getThisMapper() {
107  return ObjectFactory::getInstance('persistenceFacade')->getMapper($this->getThisType());
108  }
109 
110  /**
111  * Get the role name at this end
112  * @return String
113  */
114  public function getThisRole() {
115  return $this->thisRole;
116  }
117 
118  /**
119  * Get the PersistentObject type at the other end
120  * @return String
121  */
122  public function getOtherType() {
123  return $this->otherType;
124  }
125 
126  /**
127  * Get the PersistentMapper at the other end
128  * @return PersistenceMapper
129  */
130  public function getOtherMapper() {
131  return ObjectFactory::getInstance('persistenceFacade')->getMapper($this->getOtherType());
132  }
133 
134  /**
135  * Get the role name at the other end
136  * @return String
137  */
138  public function getOtherRole() {
139  return $this->otherRole;
140  }
141 
142  /**
143  * Get the minimum number of instances at this end
144  * @return Number or 'unbound'
145  */
146  public function getThisMinMultiplicity() {
148  }
149 
150  /**
151  * Get the maximum number of instances at this end
152  * @return Number or 'unbound'
153  */
154  public function getThisMaxMultiplicity() {
156  }
157 
158  /**
159  * Get the minimum number of instances at the other end
160  * @return Number or 'unbound'
161  */
162  public function getOtherMinMultiplicity() {
164  }
165 
166  /**
167  * Get the maximum number of instances at the other end
168  * @return Number or 'unbound'
169  */
170  public function getOtherMaxMultiplicity() {
172  }
173 
174  /**
175  * Get the aggregation kind at this end
176  * @return String 'none', 'shared' or 'composite'
177  */
178  public function getThisAggregationKind() {
180  }
181 
182  /**
183  * Get the aggregation kind at the other end
184  * @return String 'none', 'shared' or 'composite'
185  */
186  public function getOtherAggregationKind() {
188  }
189 
190  /**
191  * Check whether this end is navigable from the other end or not
192  * @return Boolean
193  */
194  public function getThisNavigability() {
196  }
197 
198  /**
199  * Check whether the other end is navigable from this end or not
200  * @return Boolean
201  */
202  public function getOtherNavigability() {
204  }
205 
206  /**
207  * Get the hierarchy type that the other end has in relation to this end
208  * @return String 'parent', 'child', 'undefined'
209  */
210  public function getHierarchyType() {
211  return $this->hierarchyType;
212  }
213 
214  /**
215  * Check if another RelationDescription instance describes the same relation as
216  * this one. This is true if they connect the same types using the same role names
217  * (independent from the direction). All other attributes are not compared.
218  * @param $other The other RelationDescription
219  * @return Boolean
220  */
221  public function isSameRelation(RelationDescription $other) {
222  if (($this->getThisType() == $other->getThisType() && $this->getOtherType() == $other->getOtherType()
223  && $this->getThisRole() == $other->getThisRole() && $this->getOtherRole() == $other->getOtherRole()) ||
224  ($this->getThisType() == $other->getOtherType() && $this->getOtherType() == $other->getThisType()
225  && $this->getThisRole() == $other->getOtherRole() && $this->getOtherRole() == $other->getThisRole())
226  ) {
227  return true;
228  }
229  return false;
230  }
231 }
232 ?>
getThisRole()
Get the role name at this end.
getThisType()
Get the PersistentObject type at this end.
getThisAggregationKind()
Get the aggregation kind at this end.
getOtherType()
Get the PersistentObject type at the other end.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
isSameRelation(RelationDescription $other)
Check if another RelationDescription instance describes the same relation as this one.
Instances of RelationDescription describe relations between different types of PersistentObjects.
isMultiValued()
Determine if there may more than one objects at the other side of the relation.
getThisNavigability()
Check whether this end is navigable from the other end or not.
getOtherMinMultiplicity()
Get the minimum number of instances at the other end.
getOtherMapper()
Get the PersistentMapper at the other end.
static getInstance($name, $dynamicConfiguration=[])
getThisMapper()
Get the PersistentMapper at this end.
getOtherNavigability()
Check whether the other end is navigable from this end or not.
getOtherAggregationKind()
Get the aggregation kind at the other end.
__construct($thisType, $thisRole, $otherType, $otherRole, $thisMinMultiplicity, $thisMaxMultiplicity, $otherMinMultiplicity, $otherMaxMultiplicity, $thisAggregationKind, $otherAggregationKind, $thisNavigability, $otherNavigability, $hierarchyType)
Constructor.
getHierarchyType()
Get the hierarchy type that the other end has in relation to this end.
getOtherRole()
Get the role name at the other end.
getThisMinMultiplicity()
Get the minimum number of instances at this end.
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...
getOtherMaxMultiplicity()
Get the maximum number of instances at the other end.
getThisMaxMultiplicity()
Get the maximum number of instances at this end.