contentRootId = 'alias-treeRootNode'; $this->contentRootTag = 'aliasList'; $this->attributes = array('name' => '', 'param' => ''); $this->objTagName = 'alias'; if (!file_exists($this->xmlName)) { $this->createDom(); $this->xp = new domxpath($this->contentDom); } } protected function createDom() { $rootElement = $this->contentDom->createElement($this->contentRootTag); $rootElement->setAttribute('xml:id', $this->contentRootId); $this->contentDom->appendChild($rootElement); $this->contentDom->save($this->xmlName); } /* * Add Alias in Alias.xml */ protected function addAlias($obj) { $objList = $this->contentDom->getElementById($this->contentRootId); $newObj = $this->contentDom->createElement($this->objTagName); $newObj->setAttribute('xml:id',$this->id); $obj_arr = (array)$obj; foreach ($this->attributes as $key => $value) { if ($key == 'name') $newObj->setAttribute($key, $obj_arr[$key]); } $objList -> appendChild($newObj); $this->saveContent() ; } /* * Create Alias */ protected function createParameter($obj) { $this->id = $obj->param; $this -> addAlias($obj); return "OK"; } /***************************************************************** * PUBLIC FUNCTIONS *****************************************************************/ public function getList() { $AliasList = $this->contentDom->getElementsByTagName('alias'); return $AliasList; } public function substrParamAlias($chain, $paramName, $aliasName) { $aliasName="#".$aliasName; $pos = strpos($chain, $paramName); while ( $pos !== FALSE ) { $pos = $pos+strlen($paramName); if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') { $chain = substr_replace($chain, $aliasName,$pos-strlen($paramName),strlen($paramName)); } $pos = strpos($chain, $paramName, $pos); } return $chain; } public function substrAliasParam($chain, $paramName, $aliasName) { $aliasName="#".$aliasName; $pos = strpos($chain, $aliasName); while ( $pos !== FALSE ) { $pos = $pos+strlen($aliasName); if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') { $chain = substr_replace($chain, $paramName,$pos-strlen($aliasName),strlen($aliasName)); } $pos = strpos($chain, $aliasName, $pos); } return $chain; } protected function deleteParameter($id){ } /* * Get Object into Edit */ public function getObject($id) { if (!($obj = $this->objectExistsById($id))) return "NO_SUCH_ID"; $attributesToReturn['id'] = $obj->getAttribute('xml:id'); $attributesToReturn['name'] = $obj->getAttribute('name'); return $attributesToReturn; } /* * Get alias of parameter */ public function getAlias($id) { $alias = ""; if (($obj = $this->objectExistsById($id))) if ($obj->hasAttribute('name')) $alias = $obj->getAttribute('name'); return $alias; } }