Parses a node list of <value> elements.

@param \DOMNodeList $valueNodes

@return array|string
548343
protected function parseFieldTypeValues(\DOMNodeList $valueNodes)
    {
        $resultValues = array();
        $resultString = '';

        foreach ($valueNodes as $valueNode) {
            switch ($valueNode->nodeType) {
                case XML_ELEMENT_NODE:
                    if ($valueNode->tagName !== 'value') {
                        throw new \RuntimeException(
                            sprintf(
                                'Invalid value tag: <%s>.',
                                $valueNode->tagName
                            )
                        );
                    }

                    $parsedValue = $this->parseFieldTypeValues($valueNode->childNodes);
                    if ($valueNode->hasAttribute('key')) {
                        $resultValues[$valueNode->getAttribute('key')] = $parsedValue;
                    } else {
                        $resultValues[] = $parsedValue;
                    }
                    break;

                case XML_TEXT_NODE:
                    $resultString .= $valueNode->wholeText;
                    break;

                case XML_CDATA_SECTION_NODE:
                    $resultString .= $valueNode->data;
                    break;
            }
        }

        $resultString = trim($resultString);
        if ($resultString !== '') {
            return $this->castScalarValue($resultString);
        }

        return $resultValues;
    }
1191675
public function parseOrganizationsNode(\DOMDocument $dom)
    {
        $organizationsList = $dom->getElementsByTagName('organizations');
        $resources = $dom->getElementsByTagName('resource');

        if ($organizationsList->length > 0) {
            $organizations = $organizationsList->item(0);
            $organization = $organizations->firstChild;

            if (!is_null($organizations->attributes)
                && !is_null($organizations->attributes->getNamedItem('default'))) {
                $defaultOrganization = $organizations->attributes->getNamedItem('default')->nodeValue;
            } else {
                $defaultOrganization = null;
            }
            // No default organization is defined
            if (is_null($defaultOrganization)) {
                while (!is_null($organization)
                    && 'organization' !== $organization->nodeName) {
                    $organization = $organization->nextSibling;
                }

                if (is_null($organization)) {
                    return $this->parseResourceNodes($resources);
                }
            }
            // A default organization is defined
            // Look for it
            else {
                while (!is_null($organization)
                    && ('organization' !== $organization->nodeName
                        || is_null($organization->attributes->getNamedItem('identifier'))
                        || $organization->attributes->getNamedItem('identifier')->nodeValue !== $defaultOrganization)) {
                    $organization = $organization->nextSibling;
                }

                if (is_null($organization)) {
                    throw new InvalidScormArchiveException('default_organization_not_found_message');
                }
            }

            return $this->parseItemNodes($organization, $resources);
        } else {
            throw new InvalidScormArchiveException('no_organization_found_message');
        }
    }
1356880
private function decodeObjectNode(\DOMNode $node): array
    {
        $data = [];
        foreach ($node->childNodes as $childNode) {
            if ($childNode instanceof \DOMText) {
                continue;
            }

            $data[$childNode->getAttribute('name')] = $this->decodeNode($childNode);
        }

        return $data;
    }
274764
private function prepareNodesTree(
        $nodes,
        $webspaceKey,
        $languageCode,
        $complete = true,
        $excludeGhosts = false,
        $maxDepth = 1,
        $currentDepth = 0
    ) {
        ++$currentDepth;

        $results = [];
        foreach ($nodes as $node) {
            $result = $this->prepareNode($node, $webspaceKey, $languageCode, 1, $complete, $excludeGhosts);
            if (null !== $maxDepth &&
                $currentDepth < $maxDepth &&
                $node->getHasChildren() &&
                null != $node->getChildren()
            ) {
                $result['_embedded']['nodes'] = $this->prepareNodesTree(
                    $node->getChildren(),
                    $webspaceKey,
                    $languageCode,
                    $complete,
                    $excludeGhosts,
                    $maxDepth,
                    $currentDepth
                );
            }
            $results[] = $result;
        }

        return $results;
    }
1091316
protected function parseElements(array $elements)
    {
        // assume empty result
        $result = [];

        //@todo check input?

        // get count of inner elements
        $countElements = count($elements[1]);

        pred($elements);

        // iterate elements of <form>
        for ($j = 0; $j < $countElements; ++$j) {
            // get properties
            $element = $this->parsePropertiesFromHtml($elements[1][$j]);

            // rearrange them
            $element = $this->prepareStructureAndData($element);

            // check fieldname for existence of our own prefix so rip off
            $fieldName = (isset($element['properties']['name'])) ?
                substr($element['properties']['name'], 0, strlen(Doozr_Form_Service_Constant::PREFIX)) :
                '';

            if ($fieldName !== Doozr_Form_Service_Constant::PREFIX) {
                // get Id
                $id = $this->getId($element['properties']);

                // inject Id
                $element['properties']['id'] = $id;

                // get template identifier
                $templateIdentifier = $this->buildTemplateIdentifier(
                    $id,
                    isset($element['properties']['type']) ? $element['properties']['type'] : $element['tag']
                );

                $this->template = str_replace(
                    $elements[1][$j], // lookup
                    $templateIdentifier, // replace
                    $this->template // subject
                );

                // drop into result
                $result[] = $element;
            }
        }

        return $result;
    }
581666
public function loadDomNodeList(\DOMNodeList $dom_node_list)
    {
        if (!isset($this->document) && $dom_node_list->length === 0) {
            throw new \Exception('DOMDocument is missing!');
        }

        if ($dom_node_list->length > 0) {
            $this->setDomDocument($dom_node_list->item(0)->ownerDocument);
        }

        foreach ($dom_node_list as $node) {
            $this->addDomNode($node);
        }
    }
273013
public function parseNode($query, $node)
    {
        if ($node instanceof Nodes\KeyNode) {
            return $this->parseKey($node->getValue());
        }

        if ($node instanceof Nodes\ValueNode) {
            return $this->parseValue($node->getValue());
        }

        if ($node instanceof Nodes\FunctionNode) {
            // .. ?

            $f = $this->getBuilder()->getFunctions()->first(function ($item, $key) use ($node) {
                $class = $item->getNode();

                return $node instanceof $class;
            });

            if (!$f) {
                throw new \Railken\SQ\Exceptions\QuerySyntaxException();
            }

            $childs = new Collection();

            foreach ($node->getChildren() as $child) {
                $childs[] = $this->parseNode($query, $child);
            }

            $childs = $childs->map(function ($v) use ($query) {
                if ($v instanceof \Illuminate\Database\Query\Expression) {
                    return $v->getValue();
                }

                $query->addBinding($v, 'where');

                return '?';
            });

            return DB::raw($f->getName().'('.$childs->implode(',').')');
        }
    }
363703
protected function _toArray(DOMNodeList $nodes) {
		$array = array();
		foreach ($nodes as $node) {
			if ($node->nodeType != XML_ELEMENT_NODE) {
				continue;
			}
			if ($node->hasAttributes()) { // deep
				if ($node->tagName == 'error') {
					$array = array(
						'id' => $node->getAttribute('id'),
						'code' => $node->getAttribute('code'),
						'auxCode' => $node->getAttribute('auxCode'),
						'message' => $node->nodeValue
					);
				} else {
					// in the case of custom charges, use the id for the key
					if ($node->hasAttribute('code') && $node->getAttribute('code')) {
						$key = $node->getAttribute('code');

						$tmpArr = array();

						if ($node->hasAttribute('id')) {
							$tmpArr = array(
								'id' => $node->getAttribute('id')
							);
						}
						$tmpArr = $tmpArr + array('code'=>$key);

						// charges need to be a nested array since there can be multiple charges with the same charge code
						if ($node->tagName == 'charge') {
							$array[$key][] = $tmpArr;
						} else {
							$array[$key] = $tmpArr;
						}

						unset($tmpArr);

					} else {
						$key = $node->getAttribute('id');
						$array[$key] = array('id' => $node->getAttribute('id'));
					}
					$array[$key] = $array[$key] + $this->_toArray($node->childNodes);
				}
			} else {
				if ($node->tagName == 'errors') {
					$array[$node->tagName][] = $this->_toArray($node->childNodes);
				} else if ($node->childNodes->length > 1) { // sub array
					$array[$node->tagName] = $this->_toArray($node->childNodes);
				} else {
					$array[$node->tagName] = $node->nodeValue;
				}
			}
		}
		return $array;
	}
1330333
protected function remove(\DOMNodeList $elements)
    {
        $encoded = array('textarea', 'code');

        foreach ($elements as $element)
        {
            if ($this->childbearing($element))
            {
                continue;
            }

            $output = (string) $element->nodeValue;

            if (in_array($element->nodeName, $encoded))
            {
                $output = htmlentities($element->nodeValue);
            }

            array_push($this->data, (string) $output);

            $current = count($this->data) - 1;

            $element->nodeValue = '$' . $current . '$';
        }
    }
1067411
public function evaluate($expression, $values = [])
    {
        return $this->parse($expression, array_keys($values))->getNodes()->evaluate($this->functions, $values);
    }
622275
private function getNodesByLowercasePropertyValue(Document $doc, string $tag, string $property, string $value): NodeList {
        return $doc->findXPath("descendant::".$tag."[translate(@".$property.", 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='".$value."']");
    }
1156704
protected function convertNode(\DOMNode $node, $path = '')
    {
        $output = [];
        if ($node->nodeType == XML_ELEMENT_NODE) {
            $nodeName = $this->parseNodeName($node);
            $output[$nodeName] = $this->parseNodeData($node, $path);
        } elseif ($node->nodeType == XML_CDATA_SECTION_NODE
            || $node->nodeType == XML_TEXT_NODE && trim($node->nodeValue) != '') {
            return $node->nodeValue;
        }

        return $output;
    }
589450
private function deserializeHierarchy($values) {
    if ($this->isSerializedNode($values)) {
      // the values represent a node
      $result = $this->deserializeNode($values);
      $node = $result['node'];
      $values = $result['data'];
      $values[$node->getOID()->__toString()] = $node;
    }
    else {
      foreach ($values as $key => $value) {
        if (is_array($value) || is_object($value)) {
          // array/object value
          $result = $this->deserializeHierarchy($value);
          // flatten the array, if the deserialization result is only an array
          // with size 1 and the key is an oid (e.g. if a node was deserialized)
          if (is_array($result) && sizeof($result) == 1 && ObjectId::isValid(key($result))) {
            unset($values[$key]);
            $values[key($result)] = current($result);
          }
          else {
            $values[$key] = $result;
          }
        }
        else {
          // string value
          $values[$key] = $value;
        }
      }
    }
    return $values;
  }
916801
protected function getItems( \DomNodeList $nodes )
	{
		$codes = $map = [];
		$manager = \Aimeos\MShop::create( $this->getContext(), 'product' );

		foreach( $nodes as $node )
		{
			if( $node->nodeName === 'productitem' && ( $attr = $node->attributes->getNamedItem( 'ref' ) ) !== null ) {
				$codes[$attr->nodeValue] = null;
			}
		}

		$search = $manager->createSearch()->setSlice( 0, count( $codes ) );
		$search->setConditions( $search->compare( '==', 'product.code', array_keys( $codes ) ) );

		foreach( $manager->searchItems( $search, [] ) as $item ) {
			$map[$item->getCode()] = $item;
		}

		return $map;
	}
333877
public static function fromXml(\DOMNodeList $xml)
    {
        $value = 0;
        if ($xml->length > 0) {
            $value = (float) $xml->item(0)->textContent;
        }
        return new static($value);
    }
1047611
protected function getValuesOfArrayNode($nodeName)
    {
        $domElements = $this->getDomElement()->getElementsByTagName($nodeName);

        $values = array();
        for ($i = 0; $i < $domElements->length; $i++) {
            $values[$i] = $domElements->item($i)->nodeValue;
        }

        return $values;
    }
988464
private function parseSetResultNodes(DOMElement $child, $name, array &$result = null)
    {
        if (!(is_array($result[$name]) && $this->valueIsList($result[$name]))) {
            return false;
        }

        $value = static::getPhpValue($child, null, $this);

        if (is_array($value) && $this->valueIsList($value)) {
            return $result[$name] = array_merge($result[$name], $value);
        }

        return $result[$name][] = $value;
    }