/** * Adds a node * * This method is essential for using this library because it will instruct it what to do and how to do it. * * @param EncoderNode $node * @return EncoderNode Will return the EncoderNode if the node had been successfully added */ public static function addNode(EncoderNode $node) { $nodeName = $node->getNodeName(); $nodeNameSingle = $node->getNodeNameSingle(); if ($nodeName === null || empty($nodeName) || !is_string($nodeName)) { throw new EncoderNodeException('Node without a name has been added. It must be a string and it cannot be empty.'); } if ($node->getNodeTypeName() !== null) { throw new EncoderNodeException('The node you\'re trying to add seems to be a node type because it has a type name'); } if (self::nodeExists($nodeName)) { throw new EncoderNodeException(sprintf('Node with name "%s" already exists', $nodeName)); } else { if ($nodeNameSingle != null) { if (self::nodeExists($nodeNameSingle)) { throw new EncoderNodeException(sprintf('Node with single name "%s" already exists', $nodeNameSingle)); } self::$nodes[$nodeNameSingle] = $node; } } self::$nodes[$nodeName] = $node; // make this node the default one if no type has yet been specified if (count(self::getNodeTypes($nodeName)) == 0) { // set the default type name so it can be registered as a type $node->typeName = self::DEFAULT_TYPE; self::addNodeType($node); } self::softCleanNodeCache(); return $node; }
/** * @param \SimpleXMLElement $nodeData * @param EncoderNode $nodeProxy * @param $isSingle * @return mixed */ protected function decodeRawNode($nodeData, EncoderNode $nodeProxy, $isSingle) { $path = $nodeProxy->getNodeNameSingle(); if (!$isSingle) { $path = $nodeProxy->getNodeName() . '/' . $path; } $children = $nodeData->xpath($path); return $isSingle ? $children[0] : $children; }
public function processOptionsFromNode(EncoderNode $node) { return array_merge($this->_processOptions($node->getNodeNameSingle()), $this->_processOptions($node->getNodeName())); }
protected function decodeRawNode($nodeData, EncoderNode $nodeProxy, $isSingle) { $nodeData = (array) $nodeData; $arr = (array) ($isSingle ? $nodeData[$nodeProxy->getNodeNameSingle()] : $nodeData[$nodeProxy->getNodeName()]); return $arr; }