mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
refactor extractSourceFromNode
This commit is contained in:
parent
42900d2ffd
commit
3816c0c88d
|
@ -12,6 +12,7 @@ class Node {
|
||||||
const FORMAT_TAG_NAME = 'format';
|
const FORMAT_TAG_NAME = 'format';
|
||||||
const LABEL_TAG_NAME = 'label';
|
const LABEL_TAG_NAME = 'label';
|
||||||
const VALUE_TAG_NAME = 'value';
|
const VALUE_TAG_NAME = 'value';
|
||||||
|
const EXTRACT_SOURCE_REGEX = '/{{{([^\|}]*?)\|?.*}}}/sU';
|
||||||
|
|
||||||
protected $xmlNode;
|
protected $xmlNode;
|
||||||
protected $children;
|
protected $children;
|
||||||
|
@ -227,16 +228,17 @@ class Node {
|
||||||
$source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ? [$this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME )] : [];
|
$source = $this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME ) ? [$this->getXmlAttribute( $xmlNode, self::DATA_SRC_ATTR_NAME )] : [];
|
||||||
|
|
||||||
if ( $xmlNode->{self::FORMAT_TAG_NAME} ) {
|
if ( $xmlNode->{self::FORMAT_TAG_NAME} ) {
|
||||||
preg_match_all( '/{{{([^\|}]*?)\|?.*}}}/sU', (string)$xmlNode->{self::FORMAT_TAG_NAME}, $sources );
|
$source = $this->matchVariables( $xmlNode->{self::FORMAT_TAG_NAME}, $source );
|
||||||
|
|
||||||
$source = array_unique( array_merge( $source, $sources[ 1 ] ) );
|
|
||||||
}
|
}
|
||||||
if ( $xmlNode->{self::DEFAULT_TAG_NAME} ) {
|
if ( $xmlNode->{self::DEFAULT_TAG_NAME} ) {
|
||||||
preg_match_all( '/{{{([^\|}]*?)\|?.*}}}/sU', (string)$xmlNode->{self::DEFAULT_TAG_NAME}, $sources );
|
$source = $this->matchVariables( $xmlNode->{self::DEFAULT_TAG_NAME}, $source );
|
||||||
|
|
||||||
$source = array_unique( array_merge( $source , $sources[ 1 ] ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $source;
|
return $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function matchVariables( \SimpleXMLElement $node, array $source ) {
|
||||||
|
preg_match_all( self::EXTRACT_SOURCE_REGEX, (string)$node, $sources );
|
||||||
|
return array_unique( array_merge( $source , $sources[ 1 ] ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue