/** * Write a record * * @param lang.Generic object * @param string[] fields if omitted, all fields will be written */ public function write(Generic $object, array $fields = array()) { $values = array(); $class = $object->getClass(); if (!$fields) { foreach ($class->getFields() as $f) { $values[] = $class->getMethod('get' . ucfirst($f->getName()))->invoke($object); } } else { foreach ($fields as $name) { $values[] = $class->getMethod('get' . ucfirst($name))->invoke($object); } } return $this->writeValues($values); }
/** * Write a record * * @param lang.Generic object * @param string[] fields if omitted, all fields will be written */ public function write(Generic $object, array $fields = array()) { $values = array(); $class = $object->getClass(); // Use the array-cast trick to access private and protected members $array = (array) $object; if ($fields) { foreach ($fields as $name) { $values[] = $this->fieldValue($array, $class->getField($name)); } } else { foreach ($class->getFields() as $f) { $values[] = $this->fieldValue($array, $f); } } return $this->writeValues($values); }
/** * Marshal an object to xml * * @param xml.Node target * @param lang.Object instance * @param [:var] inject * @return xml.Node the given target */ public function marshalTo(Node $target = NULL, Generic $instance, $inject = array()) { $class = $instance->getClass(); // Create node if not existant if (NULL === $target) { $target = new Node(NULL); } self::recurse($instance, $class, $target, $inject); return $target; }