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


PHP Node::hasChildren方法代码示例

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


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

示例1: explode

 $parsed = str_replace("))", ") )", $parsed);
 $tokens = explode(" ", $parsed);
 // var_dump($tokens);
 foreach ($tokens as $token) {
     if (strcmp(substr($token, 0, 1), "(") == 0) {
         //nāk jauna frāze, jātaisa jauna lapa
         $tokenCategory = trim(substr($token, 1));
         if (!isset($rootNode)) {
             $rootNode = new Node($tokenCategory);
             $currentNode = $rootNode;
             $currentNode->level = 0;
         } else {
             $newNode = new Node($tokenCategory);
             $newNode->setParent($currentNode);
             $newNode->level = $currentNode->level + 1;
             if (!$rootNode->hasChildren()) {
                 $rootNode->addChild($newNode);
             } else {
                 $currentNode->addChild($newNode);
             }
             $currentNode = $newNode;
         }
     } elseif (strcmp(substr($token, -1, 1), ")") == 0) {
         //frāze beidzas
         //ja bija vārds, jāpievieno pie aktuālās lapas, ja nē, jāiet pie vecāka
         $tokenWord = substr($token, 0, -1);
         if (strlen($tokenWord) > 0) {
             $currentNode->setWord($tokenWord);
         }
         if ($currentNode->getParent() != null) {
             $currentNode = $currentNode->getParent();
开发者ID:M4t1ss,项目名称:K-Translate,代码行数:31,代码来源:testChunker.php

示例2: createDomStructure

 /**
  * Returns the DOM representation of the Node.
  *
  * @param \DOMDocument $document   The global document object
  * @param Node         $node       The Node to be converted to string
  * @param bool         $forceCdata Whether the XML content will be enclosed within CDATA tags
  *
  * @return \DOMElement The DOM rappresentation of the Node
  */
 private function createDomStructure(\DOMDocument $document, Node $node, $forceCdata)
 {
     if (!$node->getName()) {
         throw new \RuntimeException('Can not create an XML representation of a Node without a name');
     }
     $element = $document->createElement($node->getName());
     foreach ($node->getAttributes() as $key => $value) {
         $attribute = $document->createAttribute($key);
         $attribute->value = $value;
         $element->appendChild($attribute);
     }
     if (!$node->hasChildren()) {
         // The Node has no children, so only content needs to be displayed
         if ($node->getValue()) {
             // The Node has content to be displayed
             if ($node->getUseCdata() || $forceCdata) {
                 $content = $document->createCDATASection($node->getValue());
             } else {
                 $content = $document->createTextNode($node->getValue());
             }
             $element->appendChild($content);
         } else {
             // The Node has no content, and short-tag is not enabled
             if ($node->getUseCdata() || $forceCdata) {
                 $element->appendChild($document->createCDATASection($node->getValue()));
             }
         }
     } else {
         // The Node has children, so they must be displayed before closing the XML tag
         foreach ($node->getChildren() as $child) {
             $element->appendChild($this->createDomStructure($document, $child, $forceCdata));
         }
     }
     return $element;
 }
开发者ID:dborsatto,项目名称:object-xml,代码行数:44,代码来源:Manager.php

示例3: _addDbContainers

 /**
  * Adds containers to a node that is a database
  *
  * References to existing children are returned
  * if this function is called twice on the same node
  *
  * @param Node   $db   The database node, new containers will be
  *                     attached to this node
  * @param string $type The type of item being paginated on
  *                     the second level of the tree
  * @param int    $pos2 The position for the pagination of
  *                     the branch at the second level of the tree
  *
  * @return array An array of new nodes
  */
 private function _addDbContainers($db, $type, $pos2)
 {
     $retval = array();
     if ($db->hasChildren(true) == 0) {
         if ($db->getPresence('tables')) {
             $retval['tables'] = PMA_NodeFactory::getInstance('Node_Table_Container');
         }
         if ($db->getPresence('views')) {
             $retval['views'] = PMA_NodeFactory::getInstance('Node_View_Container');
         }
         if ($db->getPresence('functions')) {
             $retval['functions'] = PMA_NodeFactory::getInstance('Node_Function_Container');
         }
         if ($db->getPresence('procedures')) {
             $retval['procedures'] = PMA_NodeFactory::getInstance('Node_Procedure_Container');
         }
         if ($db->getPresence('events')) {
             $retval['events'] = PMA_NodeFactory::getInstance('Node_Event_Container');
         }
         // Add all new Nodes to the tree
         foreach ($retval as $node) {
             if ($type == $node->real_name) {
                 $node->pos2 = $pos2;
             }
             $db->addChild($node);
         }
     } else {
         foreach ($db->children as $node) {
             if ($type == $node->real_name) {
                 $node->pos2 = $pos2;
             }
             $retval[$node->real_name] = $node;
         }
     }
     return $retval;
 }
开发者ID:mercysmart,项目名称:naikelas,代码行数:51,代码来源:NavigationTree.class.php

示例4: _unmarshall

 /**
  * Recursively deserialize data for the given node.
  *
  * @param   xml.Node node
  * @return  var
  * @throws  lang.IllegalArgumentException if the data cannot be deserialized
  * @throws  lang.ClassNotFoundException in case a XP object's class could not be loaded
  * @throws  xml.XMLFormatException
  */
 protected function _unmarshall(Node $node)
 {
     // value without type is supposed to be string (XML-RPC specs)
     if ('value' == $node->getName() && !isset($node->children[0])) {
         return (string) $node->getContent();
     }
     if (!isset($node->children[0])) {
         throw new XMLFormatException('Tried to access nonexistant node.');
     }
     // Simple form: If no subnode indicating the type exists, the type
     // is string, e.g. <value>Test</value>
     if (!$node->hasChildren()) {
         return (string) $node->getContent();
     }
     // Long form - with subnode, the type is derived from the node's name,
     // e.g. <value><string>Test</string></value>.
     $c = $node->nodeAt(0);
     switch ($c->getName()) {
         case 'struct':
             $ret = array();
             foreach ($c->getChildren() as $child) {
                 $data = array();
                 $data[$child->nodeAt(0)->getName()] = $child->nodeAt(0);
                 $data[$child->nodeAt(1)->getName()] = $child->nodeAt(1);
                 $ret[$data['name']->getContent()] = $this->_unmarshall($data['value']);
                 unset($data);
             }
             if (!isset($ret['__xp_class'])) {
                 return $ret;
             }
             // Check whether this is a XP object. If so, load the class and
             // create an instance without invoking the constructor.
             $fields = XPClass::forName($ret['__xp_class'])->getFields();
             $cname = array_search($ret['__xp_class'], xp::$cn, TRUE);
             $s = '';
             $n = 0;
             foreach ($fields as $field) {
                 if (!isset($ret[$field->getName()])) {
                     continue;
                 }
                 $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();
                             }
                         }
                     }
                 }
                 $s .= 's:' . strlen($name) . ':"' . $name . '";' . serialize($ret[$field->getName()]);
                 $n++;
             }
             return unserialize('O:' . strlen($cname) . ':"' . $cname . '":' . $n . ':{' . $s . '}');
         case 'array':
             $ret = array();
             foreach ($c->nodeAt(0)->getChildren() as $child) {
                 $ret[] = $this->_unmarshall($child);
             }
             return $ret;
         case 'int':
         case 'i4':
             return (int) $c->getContent();
         case 'double':
             return (double) $c->getContent();
         case 'boolean':
             return (bool) $c->getContent();
         case 'string':
             return (string) $c->getContent();
         case 'dateTime.iso8601':
             return Date::fromString($c->getContent());
         case 'nil':
             return NULL;
         case 'base64':
             return new Bytes(base64_decode($c->getContent()));
         default:
             throw new IllegalArgumentException('Could not decode node as its type is not supported: ' . $c->getName());
     }
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:94,代码来源:XmlRpcDecoder.class.php


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