Explorar o código

Add new extension method: preUpdate, postUpdate, preRemove, postRemove, prePersist, postPersist

Thomas Rabaix %!s(int64=11) %!d(string=hai) anos
pai
achega
172586b0d4
Modificáronse 3 ficheiros con 104 adicións e 18 borrados
  1. 31 18
      Admin/Admin.php
  2. 37 0
      Admin/AdminExtension.php
  3. 36 0
      Admin/AdminExtensionInterface.php

+ 31 - 18
Admin/Admin.php

@@ -566,8 +566,16 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     public function update($object)
     {
         $this->preUpdate($object);
+        foreach ($this->extensions as $extension) {
+            $extension->preUpdate($this, $object);
+        }
+
         $this->getModelManager()->update($object);
+
         $this->postUpdate($object);
+        foreach ($this->extensions as $extension) {
+            $extension->postUpdate($this, $object);
+        }
     }
 
     /**
@@ -576,8 +584,17 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     public function create($object)
     {
         $this->prePersist($object);
+        foreach ($this->extensions as $extension) {
+            $extension->prePersist($this, $object);
+        }
+
         $this->getModelManager()->create($object);
+
         $this->postPersist($object);
+        foreach ($this->extensions as $extension) {
+            $extension->postPersist($this, $object);
+        }
+
         $this->createObjectSecurity($object);
     }
 
@@ -587,58 +604,54 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     public function delete($object)
     {
         $this->preRemove($object);
+        foreach ($this->extensions as $extension) {
+            $extension->preRemove($this, $object);
+        }
+
         $this->getSecurityHandler()->deleteObjectSecurity($this, $object);
         $this->getModelManager()->delete($object);
+
         $this->postRemove($object);
+        foreach ($this->extensions as $extension) {
+            $extension->postRemove($this, $object);
+        }
     }
 
     /**
      * {@inheritdoc}
      */
     public function preUpdate($object)
-    {
-
-    }
+    {}
 
     /**
      * {@inheritdoc}
      */
     public function postUpdate($object)
-    {
-
-    }
+    {}
 
     /**
      * {@inheritdoc}
      */
     public function prePersist($object)
-    {
-
-    }
+    {}
 
     /**
      * {@inheritdoc}
      */
     public function postPersist($object)
-    {
-
-    }
+    {}
 
     /**
      * {@inheritdoc}
      */
     public function preRemove($object)
-    {
-
-    }
+    {}
 
     /**
      * {@inheritdoc}
      */
     public function postRemove($object)
-    {
-
-    }
+    {}
 
     /**
      * build the view FieldDescription array

+ 37 - 0
Admin/AdminExtension.php

@@ -76,4 +76,41 @@ abstract class AdminExtension implements AdminExtensionInterface
      */
     public function alterNewInstance(AdminInterface $admin, $object)
     {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function preUpdate(AdminInterface $admin, $object)
+    {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function postUpdate(AdminInterface $admin, $object)
+    {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function prePersist(AdminInterface $admin, $object)
+    {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function postPersist(AdminInterface $admin, $object)
+    {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function preRemove(AdminInterface $admin, $object)
+    {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function postRemove(AdminInterface $admin, $object)
+    {}
 }
+

+ 36 - 0
Admin/AdminExtensionInterface.php

@@ -99,4 +99,40 @@ interface AdminExtensionInterface
      * @param mixed          $object
      */
     public function alterNewInstance(AdminInterface $admin, $object);
+
+    /**
+     * @param AdminInterface $admin
+     * @param mixed          $object
+     */
+    public function preUpdate(AdminInterface $admin, $object);
+
+    /**
+     * @param AdminInterface $admin
+     * @param mixed          $object
+     */
+    public function postUpdate(AdminInterface $admin, $object);
+
+    /**
+     * @param AdminInterface $admin
+     * @param mixed          $object
+     */
+    public function prePersist(AdminInterface $admin, $object);
+
+    /**
+     * @param AdminInterface $admin
+     * @param mixed          $object
+     */
+    public function postPersist(AdminInterface $admin, $object);
+
+    /**
+     * @param AdminInterface $admin
+     * @param mixed          $object
+     */
+    public function preRemove(AdminInterface $admin, $object);
+
+    /**
+     * @param AdminInterface $admin
+     * @param mixed          $object
+     */
+    public function postRemove(AdminInterface $admin, $object);
 }