Ejemplo n.º 1
0
 /**
  * Write a record
  *
  * @param   lang.Generic object
  * @param   string[] fields if omitted, all fields will be written
  */
 public function write(\lang\Generic $object, array $fields = [])
 {
     $values = [];
     $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);
 }
Ejemplo n.º 2
0
 /**
  * Write a record
  *
  * @param   lang.Generic object
  * @param   string[] fields if omitted, all fields will be written
  */
 public function write(Generic $object, array $fields = [])
 {
     $values = [];
     $class = $object->getClass();
     // Use the array-cast trick to access private and protected members
     if ($fields) {
         foreach ($fields as $name) {
             $values[] = $class->getField($name)->setAccessible(true)->get($object);
         }
     } else {
         foreach ($class->getFields() as $field) {
             if (!($field->getModifiers() & MODIFIER_STATIC)) {
                 $values[] = $field->setAccessible(true)->get($object);
             }
         }
     }
     return $this->writeValues($values);
 }
Ejemplo n.º 3
0
 /**
  * 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(\xml\Node $target = null, \lang\Generic $instance, $inject = [])
 {
     $class = $instance->getClass();
     // Create node if not existant
     if (null === $target) {
         $target = new \xml\Node(null);
     }
     self::recurse($instance, $class, $target, $inject);
     return $target;
 }