| @@ 72-89 (lines=18) @@ | ||
| 69 | * @throws UnexpectedValueException The current object cannot be its own parent. |
|
| 70 | * @return HierarchicalInterface Chainable |
|
| 71 | */ |
|
| 72 | public function setMaster($master) |
|
| 73 | { |
|
| 74 | $master = $this->objFromIdent($master); |
|
| 75 | ||
| 76 | if ($master instanceof ModelInterface) { |
|
| 77 | if ($master->id() === $this->id()) { |
|
| 78 | throw new UnexpectedValueException(sprintf( |
|
| 79 | 'Can not be ones own parent: %s', |
|
| 80 | $master->id() |
|
| 81 | )); |
|
| 82 | } |
|
| 83 | } |
|
| 84 | ||
| 85 | $this->master = $master; |
|
| 86 | ||
| 87 | $this->resetHierarchy(); |
|
| 88 | ||
| 89 | return $this; |
|
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| @@ 285-300 (lines=16) @@ | ||
| 282 | * @throws UnexpectedValueException The current object cannot be its own child. |
|
| 283 | * @return HierarchicalInterface Chainable |
|
| 284 | */ |
|
| 285 | public function addChild($child) |
|
| 286 | { |
|
| 287 | $child = $this->objFromIdent($child); |
|
| 288 | ||
| 289 | if ($child instanceof ModelInterface) { |
|
| 290 | if ($child->id() === $this->id()) { |
|
| 291 | throw new UnexpectedValueException(sprintf( |
|
| 292 | 'Can not be ones own child: %s', |
|
| 293 | $child->id() |
|
| 294 | )); |
|
| 295 | } |
|
| 296 | } |
|
| 297 | ||
| 298 | $this->children[] = $child; |
|
| 299 | ||
| 300 | return $this; |
|
| 301 | } |
|
| 302 | ||
| 303 | /** |
|