/**
  * Helper method used by setup(). Adds information about the handler (and 
  * about the handler's wrapper, if existant and IFormresultAggregate'd)
  * to the formresult
  *
  * @param   scriptlet.xml.workflow.Handler handler the handler to add
  * @param   xml.Node node the node to add the handler representation to
  * @param   scriptlet.xml.workflow.WorkflowScriptletRequest request 
  */
 protected function addHandlerToFormresult($handler, $node, $request)
 {
     $node->addChild(Node::fromArray($handler->values[HVAL_PERSISTENT], 'values'));
     foreach (array_keys($handler->values[HVAL_FORMPARAM]) as $key) {
         // Skip parameters which were set via setFormValue() and which were
         // posted via request to avoid duplicate parameters. We do not need
         // to use $response->addFormValue() because this is done in
         // XMLScriptlet::processRequest() called in XMLScriptlet::doGet().
         if ($request->hasParam($key)) {
             continue;
         }
         $request->setParam($key, $handler->values[HVAL_FORMPARAM][$key]);
     }
     // Add wrapper parameter representation if the handler has a wrapper
     // and this wrapper implements the IFormresultAggregate interface
     if ($handler->hasWrapper() && $handler->wrapper instanceof IFormresultAggregate) {
         $wrapper = $node->addChild(new Node('wrapper'));
         foreach (array_keys($handler->wrapper->paraminfo) as $name) {
             $param = $wrapper->addChild(new Node('param', NULL, array('name' => $name, 'type' => $handler->wrapper->paraminfo[$name]['type'], 'occurrence' => $handler->wrapper->paraminfo[$name]['occurrence'])));
             if ($handler->wrapper->paraminfo[$name]['values']) {
                 foreach ($handler->wrapper->paraminfo[$name]['values'] as $key => $value) {
                     $param->addChild(new Node('value', $value, array('name' => $key)));
                 }
             }
             if ($handler->wrapper->paraminfo[$name]['default']) {
                 $param->addChild(new Node('default', $handler->wrapper->paraminfo[$name]['default']));
             }
         }
     }
 }
 /**
  * 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 || is_array($payload)) {
         $t->root = Node::fromArray($this->convert($payload), $root);
     } else {
         $t->root = new Node($root, $this->convert($payload));
     }
     return $t->getDeclaration() . "\n" . $t->getSource(INDENT_NONE);
 }
 /**
  * Recursivly serialize data to the given node.
  *
  * Scalar values are natively supported by the protocol, so we just encode
  * them as the spec tells us. As arrays and structs / hashes are the same
  * in PHP, and structs are the more powerful construct, we're always encoding 
  * arrays as structs.
  * 
  * XP objects are encoded as structs, having their FQDN stored in the member
  * __xp_class.
  *
  * @param   xml.Node node
  * @param   var data
  * @throws  lang.IllegalArgumentException in case the data could not be serialized.
  */
 protected function _marshall($data)
 {
     $value = new Node('value');
     // Handle objects:
     // - util.Date objects are serialized as dateTime.iso8601
     // - lang.types.Bytes object are serialized as base64
     // - Provide a standard-way to serialize Object-derived classes
     if ($data instanceof Date) {
         $value->addChild(new Node('dateTime.iso8601', $data->toString('Ymd\\TH:i:s')));
         return $value;
     } else {
         if ($data instanceof Bytes) {
             $value->addChild(new Node('base64', base64_encode($data)));
             return $value;
         } else {
             if ($data instanceof Generic) {
                 $n = $value->addChild(new Node('struct'));
                 $n->addChild(Node::fromArray(array('name' => '__xp_class', 'value' => array('string' => $data->getClassName())), 'member'));
                 $values = (array) $data;
                 foreach ($data->getClass()->getFields() as $field) {
                     $m = $field->getModifiers();
                     if ($m & MODIFIER_STATIC) {
                         continue;
                     } else {
                         if ($m & MODIFIER_PUBLIC) {
                             $name = $field->getName();
                         } else {
                             if ($m & MODIFIER_PROTECTED) {
                                 $name = "*" . $field->getName();
                             } else {
                                 if ($m & MODIFIER_PRIVATE) {
                                     $name = "" . array_search($field->getDeclaringClass()->getName(), xp::$cn, TRUE) . "" . $field->getName();
                                 }
                             }
                         }
                     }
                     $member = $n->addChild(new Node('member'));
                     $member->addChild(new Node('name', $field->getName()));
                     $member->addChild($this->_marshall($values[$name]));
                 }
                 return $value;
             }
         }
     }
     switch (xp::typeOf($data)) {
         case 'integer':
             $value->addChild(new Node('int', $data));
             break;
         case 'boolean':
             $value->addChild(new Node('boolean', (string) (int) $data));
             break;
         case 'double':
         case 'float':
             $value->addChild(new Node('double', $data));
             break;
         case 'array':
             if ($this->_isVector($data)) {
                 $n = $value->addChild(new Node('array'))->addChild(new Node('data'));
                 for ($i = 0, $s = sizeof($data); $i < $s; $i++) {
                     $n->addChild($this->_marshall($data[$i]));
                 }
             } else {
                 $n = $value->addChild(new Node('struct'));
                 foreach ($data as $name => $v) {
                     $member = $n->addChild(new Node('member'));
                     $member->addChild(new Node('name', $name));
                     $member->addChild($this->_marshall($v));
                 }
             }
             break;
         case 'string':
             $value->addChild(new Node('string', $data));
             break;
         case 'NULL':
             $value->addChild(new Node('nil'));
             break;
         default:
             throw new IllegalArgumentException('Cannot serialize data of type "' . xp::typeOf($data) . '"');
     }
     return $value;
 }
 /**
  * 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;
 }
 public function fromCharacterArray()
 {
     $this->assertEquals('<characters><character>1</character><character>&amp;</character><character>1</character></characters>', $this->sourceOf(Node::fromArray(array('1', '&', '1'), 'characters'), INDENT_NONE));
 }
Exemple #6
0
 /**
  * Creates the data structure for the given entry data
  *
  * @param  array $data
  * @return \Zend\LDAP\Node\Node
  */
 protected function _createEntry(array $data)
 {
     $node = Node::fromArray($data, true);
     $node->attachLDAP($this->_iterator->getLDAP());
     return $node;
 }
Exemple #7
0
    if (false !== $result) {
        $pass = false;
        echo "Must return false\n";
    }
    // Print
    $root->print_r();
    return $pass;
};
$tests['fromArray toArray'] = function () {
    $pass = true;
    // Prepare
    $json = '{"id":"c170ad596fb6f987f0b34bf58099ca63","properties":[],"children":{"a":{"id":"2d63f222710222663373b0692b273103","properties":[],"children":{"b":{"id":"dc3a2e4652f068bad6f78e71920483f8","properties":[],"children":{"c":{"id":"63f5f8032383f518381541e2053b9213","properties":[],"children":[]},"d":{"id":"1f3b9cf313b126f9ed03739730d58eed","properties":[],"children":[]}}},"e":{"id":"5049e43d9fd9576aa0e715d9bd8dea20","properties":[],"children":{"f":{"id":"f8a45a93ed68521a7d4c23b7918b13b3","properties":[],"children":[]},"g":{"id":"a95c67d9ebdbc4f3fb175242fb1307eb","properties":[],"children":[]}}}}}}}';
    $array = json_decode($json, true);
    // Run
    $root = new Node();
    $root->fromArray($array);
    $result = $root->toArray();
    $result_json = json_encode($result);
    // Check
    if ($json !== $result_json) {
        $pass = false;
        echo "Serialization fail\n";
    }
    // Print
    echo "{$json}\n{$result_json}";
    return $pass;
};
$tests['get property'] = function () {
    $pass = true;
    // Prepare
    $hash_red = md5(microtime());
Exemple #8
0
 public function fromArray($array)
 {
     $this->id = $array['id'];
     $this->properties = $array['properties'];
     $this->children = array();
     foreach ($array['children'] as $C => $c) {
         $child = new Node();
         $child->key = $C;
         $child->parent = $this;
         $child->fromArray($c);
         $this->children[$C] = $child;
     }
 }