AbstractNodeSerializer.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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\model\impl;
12 
15 
16 /**
17  * NodeSerializerBase is a base class for NodeSerialize implementations.
18  *
19  * @author ingo herwig <ingo@wemove.com>
20  */
21 abstract class AbstractNodeSerializer implements NodeSerializer {
22 
23  /**
24  * Deserialize a node value
25  * @param $node A reference to the node
26  * @param $key The value name or type if value is an array
27  * @param $value The value or child data, if value is an array
28  */
29  protected function deserializeValue(Node $node, $key, $value) {
30  if (!is_array($value)) {
31  // force set value to avoid exceptions in this stage
32  $node->setValue($key, $value, true);
33  }
34  else {
35  $role = $key;
36  if ($this->isMultiValued($node, $role)) {
37  // deserialize children
38  foreach($value as $childData) {
39  $this->deserializeNode($childData, $node, $role);
40  }
41  }
42  else {
43  $this->deserializeNode($value, $node, $role);
44  }
45  }
46  }
47 
48  /**
49  * Check if a relation is multi valued
50  * @param $node The Node that has the relation
51  * @param $role The role of the relation
52  */
53  protected function isMultiValued(Node $node, $role) {
54  $isMultiValued = false;
55  $mapper = $node->getMapper();
56  if ($mapper->hasRelation($role)) {
57  $relation = $mapper->getRelation($role);
58  $isMultiValued = $relation->isMultiValued();
59  }
60  return $isMultiValued;
61  }
62 }
63 ?>
NodeSerializer implementations are used to serialize Nodes into an array representation or deserializ...
setValue($name, $value, $forceSet=false, $trackChange=true)
Definition: Node.php:119
deserializeNode($data, Node $parent=null, $role=null)
Deserialize a Node from serialized data.
deserializeValue(Node $node, $key, $value)
Deserialize a node value.
isMultiValued(Node $node, $role)
Check if a relation is multi valued.
NodeSerializerBase is a base class for NodeSerialize implementations.
Node adds the concept of relations to PersistentObject.
Definition: Node.php:34