33 * Zend_Ldap_Node provides an object oriented view into a LDAP node. |
33 * Zend_Ldap_Node provides an object oriented view into a LDAP node. |
34 * |
34 * |
35 * @category Zend |
35 * @category Zend |
36 * @package Zend_Ldap |
36 * @package Zend_Ldap |
37 * @subpackage Node |
37 * @subpackage Node |
38 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
38 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
39 * @license http://framework.zend.com/license/new-bsd New BSD License |
39 * @license http://framework.zend.com/license/new-bsd New BSD License |
40 */ |
40 */ |
41 class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, RecursiveIterator |
41 class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, RecursiveIterator |
42 { |
42 { |
43 /** |
43 /** |
169 |
169 |
170 if ($ldap !== $this->_ldap) { |
170 if ($ldap !== $this->_ldap) { |
171 $this->_ldap = $ldap; |
171 $this->_ldap = $ldap; |
172 if (is_array($this->_children)) { |
172 if (is_array($this->_children)) { |
173 foreach ($this->_children as $child) { |
173 foreach ($this->_children as $child) { |
|
174 /* @var Zend_Ldap_Node $child */ |
174 $child->attachLdap($ldap); |
175 $child->attachLdap($ldap); |
175 } |
176 } |
176 } |
177 } |
177 } |
178 } |
178 return $this; |
179 return $this; |
317 } |
319 } |
318 |
320 |
319 /** |
321 /** |
320 * Ensures that teh RDN attributes are correctly set. |
322 * Ensures that teh RDN attributes are correctly set. |
321 * |
323 * |
|
324 * @param boolean $overwrite True to overwrite the RDN attributes |
322 * @return void |
325 * @return void |
323 */ |
326 */ |
324 protected function _ensureRdnAttributeValues() |
327 protected function _ensureRdnAttributeValues($overwrite = false) |
325 { |
328 { |
326 foreach ($this->getRdnArray() as $key => $value) { |
329 foreach ($this->getRdnArray() as $key => $value) { |
327 Zend_Ldap_Attribute::setAttribute($this->_currentData, $key, $value, false); |
330 if (!array_key_exists($key, $this->_currentData) || $overwrite) { |
|
331 Zend_Ldap_Attribute::setAttribute($this->_currentData, $key, $value, false); |
|
332 } else if (!in_array($value, $this->_currentData[$key])) { |
|
333 Zend_Ldap_Attribute::setAttribute($this->_currentData, $key, $value, true); |
|
334 } |
328 } |
335 } |
329 } |
336 } |
330 |
337 |
331 /** |
338 /** |
332 * Marks this node as new. |
339 * Marks this node as new. |
426 throw new Zend_Ldap_Exception(null, 'No LDAP connection available'); |
433 throw new Zend_Ldap_Exception(null, 'No LDAP connection available'); |
427 } |
434 } |
428 |
435 |
429 if ($this->willBeDeleted()) { |
436 if ($this->willBeDeleted()) { |
430 if ($ldap->exists($this->_dn)) { |
437 if ($ldap->exists($this->_dn)) { |
|
438 $this->_preDelete(); |
431 $ldap->delete($this->_dn); |
439 $ldap->delete($this->_dn); |
|
440 $this->_postDelete(); |
432 } |
441 } |
433 return $this; |
442 return $this; |
434 } |
443 } |
435 |
444 |
436 if ($this->isNew()) { |
445 if ($this->isNew()) { |
|
446 $this->_preAdd(); |
437 $data = $this->getData(); |
447 $data = $this->getData(); |
438 $ldap->add($this->_getDn(), $data); |
448 $ldap->add($this->_getDn(), $data); |
439 $this->_loadData($data, true); |
449 $this->_loadData($data, true); |
|
450 $this->_postAdd(); |
440 return $this; |
451 return $this; |
441 } |
452 } |
442 |
453 |
443 $changedData = $this->getChangedData(); |
454 $changedData = $this->getChangedData(); |
444 if ($this->willBeMoved()) { |
455 if ($this->willBeMoved()) { |
|
456 $this->_preRename(); |
445 $recursive = $this->hasChildren(); |
457 $recursive = $this->hasChildren(); |
446 $ldap->rename($this->_dn, $this->_newDn, $recursive, false); |
458 $ldap->rename($this->_dn, $this->_newDn, $recursive, false); |
447 foreach ($this->_newDn->getRdn() as $key => $value) { |
459 foreach ($this->_newDn->getRdn() as $key => $value) { |
448 if (array_key_exists($key, $changedData)) { |
460 if (array_key_exists($key, $changedData)) { |
449 unset($changedData[$key]); |
461 unset($changedData[$key]); |
450 } |
462 } |
451 } |
463 } |
452 $this->_dn = $this->_newDn; |
464 $this->_dn = $this->_newDn; |
453 $this->_newDn = null; |
465 $this->_newDn = null; |
|
466 $this->_postRename(); |
454 } |
467 } |
455 if (count($changedData) > 0) { |
468 if (count($changedData) > 0) { |
|
469 $this->_preUpdate(); |
456 $ldap->update($this->_getDn(), $changedData); |
470 $ldap->update($this->_getDn(), $changedData); |
|
471 $this->_postUpdate(); |
457 } |
472 } |
458 $this->_originalData = $this->_currentData; |
473 $this->_originalData = $this->_currentData; |
459 return $this; |
474 return $this; |
460 } |
475 } |
461 |
476 |
1017 if (!is_array($this->_children)) { |
1032 if (!is_array($this->_children)) { |
1018 $this->_children = array(); |
1033 $this->_children = array(); |
1019 if ($this->isAttached()) { |
1034 if ($this->isAttached()) { |
1020 $children = $this->searchChildren('(objectClass=*)', null); |
1035 $children = $this->searchChildren('(objectClass=*)', null); |
1021 foreach ($children as $child) { |
1036 foreach ($children as $child) { |
|
1037 /* @var Zend_Ldap_Node $child */ |
1022 $this->_children[$child->getRdnString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER)] = $child; |
1038 $this->_children[$child->getRdnString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER)] = $child; |
1023 } |
1039 } |
1024 } |
1040 } |
1025 } |
1041 } |
1026 /** |
1042 /** |
1096 */ |
1112 */ |
1097 public function valid() |
1113 public function valid() |
1098 { |
1114 { |
1099 return $this->_iteratorRewind; |
1115 return $this->_iteratorRewind; |
1100 } |
1116 } |
|
1117 |
|
1118 #################################################### |
|
1119 # Empty method bodies for overriding in subclasses # |
|
1120 #################################################### |
|
1121 |
|
1122 /** |
|
1123 * Allows pre-delete logic to be applied to node. |
|
1124 * Subclasses may override this method. |
|
1125 * |
|
1126 * @return void |
|
1127 */ |
|
1128 protected function _preDelete() { } |
|
1129 |
|
1130 /** |
|
1131 * Allows post-delete logic to be applied to node. |
|
1132 * Subclasses may override this method. |
|
1133 * |
|
1134 * @return void |
|
1135 */ |
|
1136 protected function _postDelete() { } |
|
1137 |
|
1138 /** |
|
1139 * Allows pre-add logic to be applied to node. |
|
1140 * Subclasses may override this method. |
|
1141 * |
|
1142 * @return void |
|
1143 */ |
|
1144 protected function _preAdd() { } |
|
1145 |
|
1146 /** |
|
1147 * Allows post-add logic to be applied to node. |
|
1148 * Subclasses may override this method. |
|
1149 * |
|
1150 * @return void |
|
1151 */ |
|
1152 protected function _postAdd() { } |
|
1153 |
|
1154 /** |
|
1155 * Allows pre-rename logic to be applied to node. |
|
1156 * Subclasses may override this method. |
|
1157 * |
|
1158 * @return void |
|
1159 */ |
|
1160 protected function _preRename() { } |
|
1161 |
|
1162 /** |
|
1163 * Allows post-rename logic to be applied to node. |
|
1164 * Subclasses may override this method. |
|
1165 * |
|
1166 * @return void |
|
1167 */ |
|
1168 protected function _postRename() { } |
|
1169 |
|
1170 /** |
|
1171 * Allows pre-update logic to be applied to node. |
|
1172 * Subclasses may override this method. |
|
1173 * |
|
1174 * @return void |
|
1175 */ |
|
1176 protected function _preUpdate() { } |
|
1177 |
|
1178 /** |
|
1179 * Allows post-update logic to be applied to node. |
|
1180 * Subclasses may override this method. |
|
1181 * |
|
1182 * @return void |
|
1183 */ |
|
1184 protected function _postUpdate() { } |
1101 } |
1185 } |