xmlNode = $xmlNode; $this->infoboxData = $infoboxData; } /** * @return ExternalParser */ public function getExternalParser() { if ( !isset( $this->externalParser ) ) { $this->setExternalParser( new SimpleParser() ); } return $this->externalParser; } /** * @param mixed $externalParser */ public function setExternalParser( ExternalParser $externalParser ) { $this->externalParser = $externalParser; } public function getType() { return $this->xmlNode->getName(); } public function getData() { return [ 'value' => (string)$this->xmlNode ]; } public function isEmpty( $data ) { return !( isset( $data[ 'value' ] ) ) || empty( $data[ 'value' ] ); } protected function getValueWithDefault( \SimpleXMLElement $xmlNode ) { $source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ); $value = null; if ( !empty( $source ) ) { $value = $this->getInfoboxData( $source ); } if ( !$value ) { if ( $xmlNode->{self::DEFAULT_TAG_NAME} ) { $value = (string)$xmlNode->{self::DEFAULT_TAG_NAME}; $value = $this->getExternalParser()->parseRecursive( $value ); } } return $value; } protected function getXmlAttribute( \SimpleXMLElement $xmlNode, $attribute ) { if ( isset( $xmlNode[ $attribute ] ) ) return (string)$xmlNode[ $attribute ]; return null; } protected function getInfoboxData( $key ) { $data = isset( $this->infoboxData[ $key ] ) ? $this->infoboxData[ $key ] : null; return $this->getExternalParser()->parseRecursive( $data ); } }