2
0
Просмотр исходного кода

[#ZF-11968] added pre- and post-operation hooks as extension points in sublasses

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24610 44c647ce-9c0f-0410-b52a-842ac1e357ba
sgehrig 14 лет назад
Родитель
Сommit
d13705ba2b
1 измененных файлов с 79 добавлено и 0 удалено
  1. 79 0
      library/Zend/Ldap/Node.php

+ 79 - 0
library/Zend/Ldap/Node.php

@@ -171,6 +171,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
             $this->_ldap = $ldap;
             if (is_array($this->_children)) {
                 foreach ($this->_children as $child) {
+                    /* @var Zend_Ldap_Node $child */
                     $child->attachLdap($ldap);
                 }
             }
@@ -190,6 +191,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
         $this->_ldap = null;
         if (is_array($this->_children)) {
             foreach ($this->_children as $child) {
+                /* @var Zend_Ldap_Node $child */
                 $child->detachLdap();
             }
         }
@@ -433,20 +435,25 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
 
         if ($this->willBeDeleted()) {
             if ($ldap->exists($this->_dn)) {
+                $this->_preDelete();
                 $ldap->delete($this->_dn);
+                $this->_postDelete();
             }
             return $this;
         }
 
         if ($this->isNew()) {
+            $this->_preAdd();
             $data = $this->getData();
             $ldap->add($this->_getDn(), $data);
             $this->_loadData($data, true);
+            $this->_postAdd();
             return $this;
         }
 
         $changedData = $this->getChangedData();
         if ($this->willBeMoved()) {
+            $this->_preRename();
             $recursive = $this->hasChildren();
             $ldap->rename($this->_dn, $this->_newDn, $recursive, false);
             foreach ($this->_newDn->getRdn() as $key => $value) {
@@ -456,9 +463,12 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
             }
             $this->_dn = $this->_newDn;
             $this->_newDn = null;
+            $this->_postRename();
         }
         if (count($changedData) > 0) {
+            $this->_preUpdate();
             $ldap->update($this->_getDn(), $changedData);
+            $this->_postUpdate();
         }
         $this->_originalData = $this->_currentData;
         return $this;
@@ -1024,6 +1034,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
             if ($this->isAttached()) {
                 $children = $this->searchChildren('(objectClass=*)', null);
                 foreach ($children as $child) {
+                    /* @var Zend_Ldap_Node $child */
                     $this->_children[$child->getRdnString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER)] = $child;
                 }
             }
@@ -1103,4 +1114,72 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
     {
         return $this->_iteratorRewind;
     }
+
+    ####################################################
+    # Empty method bodies for overriding in subclasses #
+    ####################################################
+
+    /**
+     * Allows pre-delete logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _preDelete() { }
+
+    /**
+     * Allows post-delete logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _postDelete() { }
+
+    /**
+     * Allows pre-add logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _preAdd() { }
+
+    /**
+     * Allows post-add logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _postAdd() { }
+
+    /**
+     * Allows pre-rename logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _preRename() { }
+
+    /**
+     * Allows post-rename logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _postRename() { }
+
+    /**
+     * Allows pre-update logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _preUpdate() { }
+
+    /**
+     * Allows post-update logic to be applied to node.
+     * Subclasses may override this method.
+     *
+     * @return void
+     */
+    protected function _postUpdate() { }
 }