Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added postHydrate hook to PHP5OBjectBuilder and BaseObject

  • Loading branch information...
commit 28b61db0733a72a5df3ba210285fb08dd5590d80 1 parent 441f969
@gertvr gertvr authored
View
4 generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -2053,7 +2053,11 @@ protected function addHydrateBody(&$script)
if (\$rehydrate) {
\$this->ensureConsistency();
}
+ \$this->postHydrate(\$row, \$startcol, \$rehydrate);";
+
+ $this->applyBehaviorModifier('postHydrate', $script, " ");
+ $script .= "
return \$startcol + $n; // $n = ".$this->getPeerClassname()."::NUM_HYDRATE_COLUMNS.
} catch (Exception \$e) {
View
8 runtime/lib/om/BaseObject.php
@@ -208,6 +208,14 @@ public function postDelete(PropelPDO $con = null)
}
/**
+ * Code to be run after deleting the object in database
+ * @param PropelPDO $con
+ */
+ public function postHydrate($row, $startcol = 0, $rehydrate = false)
+ {
+ }
+
+ /**
* Sets the modified state for the object to be false.
* @param string $col If supplied, only the specified column is reset.
* @return void
View
10 test/testsuite/generator/behavior/ObjectBehaviorTest.php
@@ -129,6 +129,16 @@ public function testPostDelete()
$this->assertEquals($t->postDeleteBuilder, 'PHP5ObjectBuilder', 'postDelete hook is called with the object builder as parameter');
$this->assertFalse($t->postDeleteIsBeforeDelete, 'postDelete hook is called before deletion');
}
+
+ public function testPostHydrate()
+ {
+ $t = new Table3();
+ $t->postHydrate = 0;
+ $t->hydrate(array(1, 'Title', 'Test'));
+ $this->assertEquals($t->postHydrate, 1, 'postHydrate hook is called on object hydration');
+ $this->assertEquals($t->postHydrateBuilder, 'PHP5ObjectBuilder', 'postHydrate hook is called with the object builder as parameter');
+ $this->assertTrue($t->postHydrateIsAfterHydrate, 'postHydrate hook is called after hydrate');
+ }
public function testObjectMethods()
{
View
9 test/testsuite/generator/builder/om/GeneratedObjectTest.php
@@ -1044,7 +1044,14 @@ public function testPostDelete()
$author->delete();
$this->assertEquals("Post-Deleted", $author->getLastName());
}
-
+
+ public function testPostHydrate()
+ {
+ $author = new TestAuthor();
+ $author->hydrate(array(1, 'bogus', 'Lastname', 'bogus@mail.com', 21));
+ $this->assertEquals("Post-Hydrated", $author->getLastName());
+ }
+
public function testMagicVirtualColumnGetter()
{
$book = new Book();
View
6 test/tools/helpers/bookstore/behavior/TestAuthor.php
@@ -65,6 +65,12 @@ public function postDelete(PropelPDO $con = null)
parent::postDelete($con);
$this->setLastName("Post-Deleted");
}
+
+ public function postHydrate($row, $startcol = 0, $rehydrate = false)
+ {
+ parent::postHydrate($row, $startcol, $rehydrate);
+ $this->setLastName("Post-Hydrated");
+ }
}
class TestAuthorDeleteFalse extends TestAuthor
View
5 test/tools/helpers/bookstore/behavior/Testallhooksbehavior.php
@@ -114,6 +114,11 @@ public function postDelete($builder)
{
return '$this->postDelete = 1;$this->postDeleteIsBeforeDelete = isset(Table3Peer::$instances[$this->id]);$this->postDeleteBuilder="' . get_class($builder) . '";';
}
+
+ public function postHydrate($builder)
+ {
+ return '$this->postHydrate = 1;$this->postHydrateIsAfterHydrate = isset($this->id);$this->postHydrateBuilder="' . get_class($builder) . '";';
+ }
public function objectMethods($builder)
{
Please sign in to comment.
Something went wrong with that request. Please try again.