/**
  * Serialize
  *
  * @param   var value
  * @return  string
  */
 public function serialize($payload)
 {
     $t = new Tree();
     $t->setEncoding('UTF-8');
     if ($payload instanceof Payload) {
         $root = isset($payload->properties['name']) ? $payload->properties['name'] : 'root';
         $payload = $payload->value;
     } else {
         $root = 'root';
     }
     if ($payload instanceof Generic) {
         $t->root = Node::fromObject($payload, $root);
     } else {
         if (is_array($payload)) {
             $t->root = Node::fromArray($payload, $root);
         } else {
             $t->root = new Node($root, $payload);
         }
     }
     return $t->getDeclaration() . "\n" . $t->getSource(INDENT_NONE);
 }
 /**
  * Adds an error. The XML representation will look like this:
  * <xmp>
  *   <error
  *    checker="foo.bar.wrapper.MyLoginDataChecker"
  *    type="user_nonexistant"
  *    field="username"                    
  *   />                                                 
  * </xmp>
  *
  * @param   string checker The class checking the input
  * @param   string type The error type
  * @param   string field default '*' The form field corresponding
  * @param   var info default NULL 
  * @return  bool FALSE
  */
 public function addFormError($checker, $type, $field = '*', $info = NULL)
 {
     if (is_array($info)) {
         $c = Node::fromArray($info, 'error');
     } else {
         if (is_object($info)) {
             $c = Node::fromObject($info, 'error');
         } else {
             $c = new Node('error', $info);
         }
     }
     $c->setAttributes(array('type' => $type, 'field' => $field, 'checker' => $checker));
     $this->document->formerrors->addChild($c);
     return FALSE;
 }
Ejemplo n.º 3
0
    public function fromObject()
    {
        $this->assertEquals("<node>\n" . "  <id>1549</id>\n" . "  <color>green</color>\n" . "  <name>Name goes here</name>\n" . "  <__id/>\n" . "</node>", $this->sourceOf(Node::fromObject(newinstance('lang.Object', array(), '{
          public $id= 1549;
          public $color= "green";
          public $name;

          public function __construct() {
            $this->name= new String("Name goes here");
          } 
        }'), 'node')));
    }
Ejemplo n.º 4
0
 public function dateFormatCallbackWithoutTZ()
 {
     $date = new Date('2009-09-20 21:33:00');
     $this->assertEquals($date->toString('Y-m-d H:i:s T'), $this->runTransformation(Node::fromObject($date, 'date')->getSource(), 'xp.date::format', array('string(/date/value)', "'Y-m-d H:i:s T'")));
 }
Ejemplo n.º 5
0
 public function writeInterfaces($description, $output)
 {
     static $purposes = array(HOME_INTERFACE => 'home', REMOTE_INTERFACE => 'remote');
     foreach ($description->getInterfaces() as $type => $interface) {
         $node = Node::fromObject($interface, 'interface');
         $node->setAttribute('purpose', $purposes[$type]);
         $node->addChild(new Node('jndiName', $this->jndi));
         $this->processor->setXMLBuf($node->getSource(INDENT_NONE));
         $this->processor->run();
         $output->append(strtr($interface->getClassName(), '.', '/') . xp::CLASS_FILE_EXT, $this->processor->output());
     }
 }