protected function parseValueCopy($sourceObjectPath, $targetObjectPath)
{
$sourceObjectPathArray = $this->getParsedObjectPath($sourceObjectPath);
$targetObjectPathArray = $this->getParsedObjectPath($targetObjectPath);
$sourceIsPrototypeDefinition = count($sourceObjectPathArray) >= 2 && $sourceObjectPathArray[count($sourceObjectPathArray) - 2] === '__prototypes';
$targetIsPrototypeDefinition = count($targetObjectPathArray) >= 2 && $targetObjectPathArray[count($targetObjectPathArray) - 2] === '__prototypes';
if ($sourceIsPrototypeDefinition || $targetIsPrototypeDefinition) {
// either source or target are a prototype definition
if ($sourceIsPrototypeDefinition && $targetIsPrototypeDefinition && count($sourceObjectPathArray) === 2 && count($targetObjectPathArray) === 2) {
// both are a prototype definition and the path has length 2: this means
// it must be of the form "prototype(Foo) < prototype(Bar)"
$targetObjectPathArray[] = '__prototypeObjectName';
$this->setValueInObjectTree($targetObjectPathArray, end($sourceObjectPathArray));
} elseif ($sourceIsPrototypeDefinition && $targetIsPrototypeDefinition) {
// Both are prototype definitions, but at least one is nested (f.e. foo.prototype(Bar))
// Currently, it is not supported to override the prototypical inheritance in
// parts of the TS rendering tree.
// Although this might work conceptually, it makes reasoning about the prototypical
// inheritance tree a lot more complex; that's why we forbid it right away.
throw new Fusion\Exception('Tried to parse "' . $targetObjectPath . '" < "' . $sourceObjectPath . '", however one of the sides is nested (e.g. foo.prototype(Bar)). Setting up prototype inheritance is only supported at the top level: prototype(Foo) < prototype(Bar)', 1358418019);
} else {
// Either "source" or "target" are no prototypes. We do not support copying a
// non-prototype value to a prototype value or vice-versa.
throw new Fusion\Exception('Tried to parse "' . $targetObjectPath . '" < "' . $sourceObjectPath . '", however one of the sides is no prototype definition of the form prototype(Foo). It is only allowed to build inheritance chains with prototype objects.', 1358418015);
}
} else {
$originalValue = $this->getValueFromObjectTree($sourceObjectPathArray);
$value = is_object($originalValue) ? clone $originalValue : $originalValue;
$this->setValueInObjectTree($targetObjectPathArray, $value);
}
}