wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.ArrayOutputStrategy.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.ArrayOutputStrategy.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/output/class.OutputStrategy.php");
20 /**
21  * @class ArrayOutputStrategy
22  * @ingroup Output
23  * @brief This OutputStrategy outputs an object's content into an array.
24  *
25  * @author ingo herwig <ingo@wemove.com>
26  */
28 {
30 
31  /**
32  * Constructor
33  * @param writeValueProperties True/False wether to write value properties or not [default: false]
34  */
35  function ArrayOutputStrategy($writeValueProperties=false)
36  {
37  $this->_writeValueProperties = $writeValueProperties;
38  }
39  /**
40  * Write the document header.
41  */
42  function writeHeader()
43  {
44  // do nothing
45  }
46  /**
47  * Write the document footer.
48  */
49  function writeFooter()
50  {
51  // do nothing
52  }
53  /**
54  * Write the objects content.
55  * @param obj The object to write.
56  */
57  function writeObject(&$obj)
58  {
59  $content = array();
60  $content['oid'] = $obj->getOID();
61  $content['type'] = $obj->getType();
62  $content['properties'] = array();
63  foreach($obj->getPropertyNames() as $name)
64  $content['properties'][$name] = $this->writeValue($obj->getProperty($name));
65 
66  $content['values'] = array();
67  foreach($obj->getDataTypes() as $type)
68  {
69  $content['values'][$type] = array();
70  foreach($obj->getValueNames($type) as $name)
71  {
72  $content['values'][$type][$name] = array();
73  $value = $this->writeValue($obj->getValue($name, $type));
74  $content['values'][$type][$name]['value'] = $value;
75  if ($this->_writeValueProperties)
76  {
77  $content['values'][$type][$name]['properties'] = array();
78  foreach($obj->getValueProperties($name, $type) as $propertyName => $propertyValue)
79  $content['values'][$type][$name]['properties'][$propertyName] = $this->writeValue($propertyValue);
80  }
81  }
82  }
83  return $content;
84  }
85  /**
86  * Write the objects content.
87  * @param value The value to write.
88  */
89  function writeValue($value)
90  {
91  $content = '';
92  if (is_array($value))
93  {
94  $content = array();
95  for ($i=0; $i<sizeof($value); $i++)
96  array_push($content, utf8_encode($value[$i]));
97  }
98  else if (strtolower(get_class($value)) == 'persistentobject' || is_a($value, 'PersistentObject'))
99  $content = $this->writeObject($value);
100  else
101  $content = utf8_encode($value);
102  return $content;
103  }
104 }
105 ?>
OutputStrategy is used to write an object's content to a destination (called 'document') using a spec...
This OutputStrategy outputs an object's content into an array.
ArrayOutputStrategy($writeValueProperties=false)