| 1: | <?php |
| 2: | |
| 3: | /** |
| 4: | * Element is the representation of a XML-tag Elment |
| 5: | * |
| 6: | * @property string $keyname is name of the XML-tag |
| 7: | * @property undefined $value in between the XML-tag |
| 8: | * @property bool $mandatory optional to set mandatory entry |
| 9: | * @property bool $hasattributes mark tags which provides attriburtes |
| 10: | * @property bool $isdepended value in between the XML-tag |
| 11: | * @property bool $isparenttag mark XML-tag Elemnt as parent XML-tag |
| 12: | * @property array $children stroes child Elements of XML-tag Element |
| 13: | * @property array $allowedvaluelist stroes allowed values of the XML-tag |
| 14: | * @property array $attributes stroes attributes of XML-tag Element * |
| 15: | * @author sfrenzel |
| 16: | * @version 1.0 |
| 17: | * |
| 18: | */ |
| 19: | class Element { |
| 20: | |
| 21: | public string $keyname; |
| 22: | public $value; |
| 23: | public bool $mandatory = false; |
| 24: | public bool $hasattributes = false; |
| 25: | public bool $isdepended = false; |
| 26: | public bool $isparenttag = false; |
| 27: | public array $children = []; |
| 28: | public array $allowedvaluelist = []; |
| 29: | public array $attributes = []; |
| 30: | /** |
| 31: | * |
| 32: | */ |
| 33: | public function __construct() { |
| 34: | |
| 35: | } |
| 36: | |
| 37: | /** |
| 38: | * |
| 39: | * @return type |
| 40: | */ |
| 41: | public function getKeyname() { |
| 42: | return $this->keyname; |
| 43: | } |
| 44: | /** |
| 45: | * |
| 46: | * @return type |
| 47: | */ |
| 48: | public function getValue() { |
| 49: | return $this->value; |
| 50: | } |
| 51: | /** |
| 52: | * |
| 53: | * @return type |
| 54: | */ |
| 55: | public function getMandatory() { |
| 56: | return $this->mandatory; |
| 57: | } |
| 58: | /** |
| 59: | * |
| 60: | * @return type |
| 61: | */ |
| 62: | public function getAllowedvaluelist() { |
| 63: | return $this->allowedvaluelist; |
| 64: | } |
| 65: | /** |
| 66: | * |
| 67: | * @return type |
| 68: | */ |
| 69: | public function getAttributes() { |
| 70: | return $this->attributes; |
| 71: | } |
| 72: | /** |
| 73: | * |
| 74: | * @return type |
| 75: | */ |
| 76: | public function getChildren() { |
| 77: | return $this->children; |
| 78: | } |
| 79: | |
| 80: | /** |
| 81: | * |
| 82: | * @param type $keyname |
| 83: | * @return void |
| 84: | */ |
| 85: | public function setKeyname($keyname): void { |
| 86: | $this->keyname = $keyname; |
| 87: | } |
| 88: | /** |
| 89: | * |
| 90: | * @param type $value |
| 91: | * @return void |
| 92: | */ |
| 93: | public function setValue($value): void { |
| 94: | $this->value = $value; |
| 95: | } |
| 96: | /** |
| 97: | * |
| 98: | * @param type $keyname |
| 99: | * @param type $value |
| 100: | * @return void |
| 101: | */ |
| 102: | public function setKeynameValue($keyname, $value): void { |
| 103: | $this->keyname = $keyname; |
| 104: | $this->value = $value; |
| 105: | } |
| 106: | /** |
| 107: | * |
| 108: | * @param type $mandatory |
| 109: | * @return void |
| 110: | */ |
| 111: | public function setMandatory($mandatory): void { |
| 112: | $this->mandatory = $mandatory; |
| 113: | } |
| 114: | /** |
| 115: | * |
| 116: | * @param type $allowedvalue |
| 117: | * @return void |
| 118: | */ |
| 119: | public function insertAllowedvaluelist($allowedvalue): void { |
| 120: | array_push($this->allowedvaluelist, $allowedvalue); |
| 121: | } |
| 122: | /** |
| 123: | * Insert attribute in Attribut |
| 124: | * @param type $attribute |
| 125: | * @return void |
| 126: | */ |
| 127: | public function insertAttributes($attribute): void { |
| 128: | array_push($this->attributes, $attribute); |
| 129: | if (!$this->hasattributes) { |
| 130: | $this->hasattributes = true; |
| 131: | } |
| 132: | } |
| 133: | /** |
| 134: | * Inserts child node in parent nodes array |
| 135: | * @param Element $child |
| 136: | * @return void |
| 137: | */ |
| 138: | public function insertChild(Element $child): void { |
| 139: | $child->isdepended = true; |
| 140: | array_push($this->children, $child); |
| 141: | if (!$this->isparenttag) { |
| 142: | $this->isparenttag = true; |
| 143: | } |
| 144: | } |
| 145: | /** |
| 146: | * |
| 147: | * @param array $children |
| 148: | * @param String $retagname |
| 149: | * @return type |
| 150: | */ |
| 151: | public function copyChildreninNew(array $children, String $retagname) { |
| 152: | foreach ($children as $child) { |
| 153: | $returnChild = $this->changekeynameofChild($child, $retagname); |
| 154: | $this->insertChild($returnChild); |
| 155: | } |
| 156: | return; |
| 157: | } |
| 158: | /** |
| 159: | * |
| 160: | * @param Element $child |
| 161: | * @param type $keyname |
| 162: | * @return Element |
| 163: | */ |
| 164: | public function changekeynameofChild(Element $child, $keyname): Element { |
| 165: | $rchild = clone $child; |
| 166: | $rchild->setKeyname($keyname); |
| 167: | return $rchild; |
| 168: | } |
| 169: | |
| 170: | } |
| 171: |