addded tests for template. added optimization for __call and calling template functions in Record
This commit is contained in:
parent
cebd4928b6
commit
7a26255739
@ -119,6 +119,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
*/
|
||||
private $_oid;
|
||||
|
||||
/**
|
||||
* @var array $_methods array that contains methods that are already checked for
|
||||
*/
|
||||
|
||||
protected $_methods;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param Doctrine_Table|null $table a Doctrine_Table object or null,
|
||||
@ -213,7 +219,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
{ }
|
||||
/**
|
||||
* construct
|
||||
* Empty tempalte method to provide concrete Record classes with the possibility
|
||||
* Empty template method to provide concrete Record classes with the possibility
|
||||
* to hook into the constructor procedure
|
||||
*
|
||||
* @return void
|
||||
@ -1511,9 +1517,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if ( isset( $this->_methods[$method])) {
|
||||
$methodArray = $this->_methods[$method];
|
||||
$template = $methodArray["template"];
|
||||
$template->setInvoker($this);
|
||||
return call_user_func_array( array( $template, $method ), $methodArray["args"]);
|
||||
}
|
||||
foreach ($this->_table->getTemplates() as $template) {
|
||||
if (method_exists($template, $method)) {
|
||||
$template->setInvoker($this);
|
||||
$this->_methods[$method] = array("template" => $template, "args" => $args);
|
||||
|
||||
return call_user_func_array(array($template, $method), $args);
|
||||
}
|
||||
|
@ -69,6 +69,13 @@ class Doctrine_Template_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->assertTrue($user->Email[0] instanceof ConcreteEmail);
|
||||
}
|
||||
|
||||
public function testShouldCallMethodInTemplate()
|
||||
{
|
||||
$user = new ConcreteUser();
|
||||
$this->assertEqual("foo", $user->foo());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// move these to ../templates?
|
||||
@ -87,6 +94,11 @@ class UserTemplate extends Doctrine_Template
|
||||
$this->hasMany('EmailTemplate as Email', array('local' => 'id',
|
||||
'foreign' => 'user_id'));
|
||||
}
|
||||
|
||||
public function foo()
|
||||
{
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
class EmailTemplate extends Doctrine_Template
|
||||
{
|
||||
|
@ -310,7 +310,7 @@ $test->addTestCase(new Doctrine_Import_Schema_Xml_TestCase());
|
||||
$test->addTestCase(new Doctrine_Export_Schema_Yml_TestCase());
|
||||
$test->addTestCase(new Doctrine_Export_Schema_Xml_TestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Template_TestCase());
|
||||
$test->addTestCase(new Doctrine_Template_TestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Import_Builder_TestCase());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user