AliasMgr.php
4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* @class AliasMgr
* @version $Id: AliasMgr.php 899 2012-05-02 14:08:28Z benjamin $
*/
class AliasMgr extends AmdaObjectMgr {
function __construct() {
parent::__construct('Alias.xml');
$this->contentRootId = 'alias-treeRootNode';
$this->contentRootTag = 'aliasList';
$this->attributes = array('name' => '', 'param' => '', 'iconCls' => '');
$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) {
$newObj->setAttribute($key, $obj_arr[$key]);
}
if (count($obj_arr['component_info']) > 0) {
foreach ($obj_arr['component_info'] as $key => $value) {
$newObj->setAttribute($key, $value);
}
}
$objList -> appendChild($newObj);
$this->saveContent() ;
}
/*
* Create Alias
*/
protected function createParameter($obj) {
$this->id = $obj->param;
$this->addAlias($obj);
return "OK";
}
/*****************************************************************
* PUBLIC FUNCTIONS
*****************************************************************/
public function getAliasArraySorted($byParamLength) {
$AliasList = $this->contentDom->getElementsByTagName('alias');
$AliasArray = array();
foreach ($AliasList as $alias) {
$AliasArray[$alias->getAttribute('xml:id')] = $alias->getAttribute('name');
}
if ($byParamLength) { // sort array by parameter length
$keys = array_map('strlen', array_keys($AliasArray));
array_multisort($keys, SORT_DESC, $AliasArray);
}
else { // sort array by alias length
$keys = array_map('strlen',$AliasArray);
array_multisort($keys,SORT_DESC,$AliasArray);
}
return $AliasArray;
}
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 = $pos-strlen($paramName)+strlen($aliasName);
}
$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 = $pos-strlen($aliasName)+strlen($paramName);
}
$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;
}
}