From db433c844951c3c3e2053bbfdef2005518d56950 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 12 Oct 2006 21:01:53 +0000 Subject: [PATCH] Fixes #163, #162, removed Doctrine_Record::__call() --- lib/Doctrine/Record.php | 66 ++++++++++++++++++++++++++++------- tests/QuerySelectTestCase.php | 7 ++++ tests/RecordTestCase.php | 8 +++-- 3 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 tests/QuerySelectTestCase.php diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 315de3cdd..c3b80494c 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1385,23 +1385,63 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite } } } + public function setAttribute($attr, $value) { + $this->table->setAttribute($attr, $value); + } + public function setTableName($tableName) { + $this->table->setTableName($tableName); + } + public function setInheritanceMap($map) { + $this->table->setInheritanceMap($map); + } + public function setEnumValues($column, $values) { + $this->table->setEnumValues($column, $values); + } /** - * __call - * @param string $m - * @param array $a + * addListener + * + * @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener + * @return Doctrine_DB */ - public function __call($m,$a) { - if(method_exists($this->table, $m)) - return call_user_func_array(array($this->table, $m), $a); + public function addListener($listener, $name = null) { + $this->table->addListener($listener, $name = null); + return $this; + } + /** + * getListener + * + * @return Doctrine_DB_EventListener_Interface|Doctrine_Overloadable + */ + public function getListener() { + return $this->table->getListener(); + } + /** + * setListener + * + * @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener + * @return Doctrine_DB + */ + public function setListener($listener) { + $this->table->setListener($listener); + return $this; + } + /** + * call + * + * @param string|array $callback valid callback + * @param string $column column name + * @param mixed arg1 ... argN optional callback arguments + * @return Doctrine_Record + */ + public function call($callback, $column) { + $args = func_get_args(); + array_shift($args); - if( ! function_exists($m)) - throw new Doctrine_Record_Exception("unknown callback '$m'"); + if(isset($args[0])) { + $column = $args[0]; + $args[0] = $this->get($column); - if(isset($a[0])) { - $column = $a[0]; - $a[0] = $this->get($column); - - $newvalue = call_user_func_array($m, $a); + $newvalue = call_user_func_array($callback, $args); $this->data[$column] = $newvalue; } diff --git a/tests/QuerySelectTestCase.php b/tests/QuerySelectTestCase.php new file mode 100644 index 000000000..439ee1f94 --- /dev/null +++ b/tests/QuerySelectTestCase.php @@ -0,0 +1,7 @@ + diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index e1bb07de7..ab8a144e8 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -21,7 +21,9 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $this->assertFalse(isset($user['id'])); $this->assertFalse($user->contains('id')); } - + public function testUnknownColumn() { + + } public function testNotNullConstraint() { $null = new NotNullTest(); @@ -287,9 +289,9 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { public function testCallback() { $user = new User(); $user->name = " zYne "; - $user->trim('name'); + $user->call('trim', 'name'); $this->assertEqual($user->name, 'zYne'); - $user->substr('name',0,1); + $user->call('substr', 'name', 0, 1); $this->assertEqual($user->name, 'z'); }