mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Improvement: Set the owner on an extension, before getting all the available method names.
This enhances the extensions to enable certain features like adding wrapper methods instead of having to have them on the object itself.
This commit is contained in:
parent
ce560e7b76
commit
debe8ba2a3
@ -816,7 +816,9 @@ abstract class Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(method_exists($extension, 'allMethodNames')) {
|
if(method_exists($extension, 'allMethodNames')) {
|
||||||
|
if ($extension instanceof Extension) $extension->setOwner($this);
|
||||||
$methods = $extension->allMethodNames(true);
|
$methods = $extension->allMethodNames(true);
|
||||||
|
if ($extension instanceof Extension) $extension->clearOwner();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(!isset(self::$built_in_methods[$extension->class])) {
|
if(!isset(self::$built_in_methods[$extension->class])) {
|
||||||
|
@ -166,6 +166,13 @@ class DataExtensionTest extends SapphireTest {
|
|||||||
$this->assertEquals("hello world", $do->testMethodApplied());
|
$this->assertEquals("hello world", $do->testMethodApplied());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExtensionAllMethodNamesHasOwner() {
|
||||||
|
/** @var DataExtensionTest_MyObject $do */
|
||||||
|
$do = DataExtensionTest_MyObject::create();
|
||||||
|
|
||||||
|
$this->assertTrue($do->hasMethod('getTestValueWithDataExtensionTest_MyObject'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testPageFieldGeneration() {
|
public function testPageFieldGeneration() {
|
||||||
$page = new DataExtensionTest_CMSFieldsBase();
|
$page = new DataExtensionTest_CMSFieldsBase();
|
||||||
$fields = $page->getCMSFields();
|
$fields = $page->getCMSFields();
|
||||||
@ -365,17 +372,31 @@ class DataExtensionTest_Faves extends DataExtension implements TestOnly {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataExtensionTest_AppliedToDO extends DataExtension implements TestOnly {
|
class DataExtensionTest_AppliedToDO extends DataExtension implements TestOnly
|
||||||
|
{
|
||||||
|
|
||||||
public function testMethodApplied() {
|
public function testMethodApplied()
|
||||||
|
{
|
||||||
return "hello world";
|
return "hello world";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DataExtensionTest_AllMethodNames extends DataExtension implements TestOnly
|
||||||
|
{
|
||||||
|
public function allMethodNames()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
strtolower('getTestValueWith'.$this->owner->ClassName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
DataExtensionTest_MyObject::add_extension('DataExtensionTest_Ext1');
|
DataExtensionTest_MyObject::add_extension('DataExtensionTest_Ext1');
|
||||||
DataExtensionTest_MyObject::add_extension('DataExtensionTest_Ext2');
|
DataExtensionTest_MyObject::add_extension('DataExtensionTest_Ext2');
|
||||||
DataExtensionTest_MyObject::add_extension('DataExtensionTest_Faves');
|
DataExtensionTest_MyObject::add_extension('DataExtensionTest_Faves');
|
||||||
|
DataExtensionTest_MyObject::add_extension('DataExtensionTest_AllMethodNames');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for CMS fields
|
* Base class for CMS fields
|
||||||
|
Loading…
Reference in New Issue
Block a user