/**
  * 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'));
     if (isset($handler->values[HVAL_FORMPARAM])) {
         foreach ($handler->values[HVAL_FORMPARAM] as $key => $value) {
             // 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, $value);
         }
     }
     // 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 ($handler->wrapper->paraminfo as $name => $paraminfo) {
             $param = $wrapper->addChild(new Node('param', null, ['name' => $name, 'type' => $paraminfo['type'], 'occurrence' => $paraminfo['occurrence']]));
             if ($paraminfo['values']) {
                 foreach ($paraminfo['values'] as $key => $value) {
                     $param->addChild(new Node('value', $value, ['name' => $key]));
                 }
             }
             if ($paraminfo['default']) {
                 $param->addChild(new Node('default', $paraminfo['default']));
             }
         }
     }
 }
Пример #2
0
 protected function node($name, $in)
 {
     if (is_object($in)) {
         return Node::fromObject($in, $name);
     } else {
         if (is_array($in)) {
             return Node::fromArray($in, $name);
         } else {
             return new Node($name, $in);
         }
     }
 }
 /**
  * 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 || $data instanceof \lang\types\Bytes) {
             $value->addChild(new Node('base64', base64_encode($data)));
             return $value;
         } else {
             if ($data instanceof \lang\Generic) {
                 $n = $value->addChild(new Node('struct'));
                 $n->addChild(Node::fromArray(['name' => '__xp_class', 'value' => ['string' => nameof($data)]], 'member'));
                 foreach ($data->getClass()->getFields() as $field) {
                     if ($field->getModifiers() & MODIFIER_STATIC) {
                         continue;
                     }
                     $member = $n->addChild(new Node('member'));
                     $member->addChild(new Node('name', $field->getName()));
                     $member->addChild($this->_marshall($field->setAccessible(true)->get($data)));
                 }
                 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 \lang\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 = \xml\Node::fromArray($info, 'error');
     } else {
         if (is_object($info)) {
             $c = \xml\Node::fromObject($info, 'error');
         } else {
             $c = new \xml\Node('error', $info);
         }
     }
     $c->setAttributes(['type' => $type, 'field' => $field, 'checker' => $checker]);
     $this->document->formerrors->addChild($c);
     return false;
 }