diff --git a/examples/ConditionExample/page.html b/examples/ConditionExample/page.html
index 80ef43a..d98dbdd 100644
--- a/examples/ConditionExample/page.html
+++ b/examples/ConditionExample/page.html
@@ -34,7 +34,7 @@
Condition Examples
-->
Aug 1. 2019
- December 12, 2019
+ December 30, 2019
This page was loaded between Aug 1 and Dec 30 2019
diff --git a/src/Page/Page.php b/src/Page/Page.php
index 9ffe1bd..e93ead1 100644
--- a/src/Page/Page.php
+++ b/src/Page/Page.php
@@ -241,12 +241,12 @@ public function instantiateElement(string $xpath_expression, string $class_name)
continue;
}
+ // get args from element and remove child arg
+ $args = $this->getArgs($element);
+
// get xml from element
$xml = $this->getXml($element);
- // get args from element
- $args = $this->getArgs($element);
-
// instantiate element
$element_object = new $element_class_name($xml, $args);
@@ -284,6 +284,35 @@ private function getXml(\DOMElement $element): string
return $xml;
}
+ /**
+ * Adds an item to smart list.
+ *
+ * @param array $args
+ * @param string $name
+ * @param string $value
+ */
+ private function addToSmartList(array &$args, string $name, string $value) : void {
+
+ if( ! isset($args[$name]) ) {
+ // set value
+ $args[$name] = $value;
+ } else if ($args[$name] == $value ) {
+ // if item value exists as string skip
+ } else if( is_string($args[$name]) ) {
+ // change string value to array
+ $present_value = $args[$name];
+ $args[$name] = [];
+ array_push($args[$name], $present_value);
+ array_push($args[$name], $value);
+ } else if (in_array($value, $args[$name]) ) {
+ // if item already exists return
+ return;
+ } else if ( is_array($args[$name]) ) {
+ // add to array
+ array_push($args[$name], $value);
+ }
+ }
+
/**
* Get element's ARGs
*
@@ -297,16 +326,26 @@ private function getArgs(\DOMElement &$element): array
// get attributes
if ($element->hasAttributes()) {
foreach ($element->attributes as $name => $attribute) {
- $args[$name] = $attribute->value;
+ $this->addToSmartList($args, $name, $attribute->value);
}
}
// get child args
- $objects = $element->getElementsByTagName('arg');
- foreach ($objects as $object) {
- $name = $object->getAttribute('name');
- $value = $object->nodeValue;
- $args[$name] = $value;
+ $arg_elements = $element->getElementsByTagName('arg');
+ // iterate in reverse threw list of arguments to avoid bug with removing
+ for($i = $arg_elements->length - 1; $i >= 0; $i--){
+
+ // get argument
+ $arg_element = $arg_elements->item($i);
+
+ // add item to args
+ $name = $arg_element->getAttribute('name');
+ $value = $arg_element->nodeValue;
+
+ $this->addToSmartList($args, $name, $value);
+
+ // remove element
+ $arg_element->parentNode->removeChild($arg_element);
}
// use element id attribute to load args