当前位置: 首页>>代码示例>>PHP>>正文


PHP Node::fromArray方法代码示例

本文整理汇总了PHP中Node::fromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::fromArray方法的具体用法?PHP Node::fromArray怎么用?PHP Node::fromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Node的用法示例。


在下文中一共展示了Node::fromArray方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addHandlerToFormresult

 /**
  * 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']));
             }
         }
     }
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:39,代码来源:AbstractState.class.php

示例2: serialize

 /**
  * 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);
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:23,代码来源:RestXmlSerializer.class.php

示例3: _marshall

 /**
  * 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;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:96,代码来源:XmlRpcEncoder.class.php

示例4: addFormError

 /**
  * 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;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:31,代码来源:XMLScriptletResponse.class.php

示例5: fromCharacterArray

 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));
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:4,代码来源:NodeTest.class.php

示例6: _createEntry

 /**
  * 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;
 }
开发者ID:stunti,项目名称:zf2,代码行数:12,代码来源:Collection.php

示例7: function

    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());
开发者ID:fulldump,项目名称:8,代码行数:31,代码来源:Node.test.php

示例8: fromArray

 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;
     }
 }
开发者ID:fulldump,项目名称:8,代码行数:13,代码来源:Node.class.php


注:本文中的Node::fromArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。