APICHANGE: Use late static binding for Object::remove_extension()

This commit is contained in:
Andrew O'Neil 2012-10-10 10:30:40 +13:00 committed by Sean Harvey
parent fdea5321c7
commit 6dd6a5c188
5 changed files with 19 additions and 12 deletions

View File

@ -508,10 +508,17 @@ abstract class Object {
*
* @todo Add support for removing extensions with parameters
*
* @param string $class
* @param string $extension Classname of an {@link Extension} subclass, without parameters
*/
public static function remove_extension($class, $extension) {
public static function remove_extension($extension) {
$class = get_called_class();
if(func_num_args() > 1) {
Deprecation::notice('3.1.0', "Object::remove_extension() deprecated. Call remove_extension() on the class");
$class = func_get_arg(0);
$extension = func_get_arg(1);
}
Config::inst()->remove($class, 'extensions', Config::anything(), $extension);
// unset singletons to avoid side-effects

View File

@ -278,7 +278,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
if (Object::has_extension($class, $extension)) {
if(!isset($this->extensionsToReapply[$class])) $this->extensionsToReapply[$class] = array();
$this->extensionsToReapply[$class][] = $extension;
Object::remove_extension($class, $extension);
$class::remove_extension($extension);
$isAltered = true;
}
}
@ -319,7 +319,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
// Remove extensions added for testing
foreach($this->extensionsToRemove as $class => $extensions) {
foreach($extensions as $extension) {
Object::remove_extension($class, $extension);
$class::remove_extension($extension);
}
}

View File

@ -242,7 +242,7 @@ class ObjectTest extends SapphireTest {
// @todo At the moment, this does NOT remove the extension due to parameterized naming,
// meaning the extension will remain added in further test cases
Object::remove_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest3');
ObjectTest_ExtensionTest::remove_extension('ObjectTest_ExtendTest3');
}
public function testRemoveExtension() {
@ -253,7 +253,7 @@ class ObjectTest extends SapphireTest {
"Extension added through \$add_extension() are added correctly"
);
Object::remove_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2');
ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest2');
$this->assertFalse(
Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2'),
"Extension added through \$add_extension() are detected as removed in has_extension()"
@ -264,7 +264,7 @@ class ObjectTest extends SapphireTest {
);
// ObjectTest_ExtendTest1 is already present in $extensions
Object::remove_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest1');
ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest1');
$this->assertFalse(
Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest1'),
"Extension added through \$extensions are detected as removed in has_extension()"

View File

@ -12,7 +12,7 @@ class FulltextSearchableTest extends SapphireTest {
$this->orig['File_searchable'] = Object::has_extension('File', 'FulltextSearchable');
// TODO This shouldn't need all arguments included
Object::remove_extension('File', 'FulltextSearchable(\'"Filename","Title","Content"\')');
File::remove_extension('FulltextSearchable(\'"Filename","Title","Content"\')');
}
public function tearDown() {

View File

@ -478,7 +478,7 @@ class MemberTest extends FunctionalTest {
$this->assertFalse($member2->canEdit());
/* Apply a extension that denies viewing of the Member */
Object::remove_extension('Member', 'MemberTest_ViewingAllowedExtension');
Member::remove_extension('MemberTest_ViewingAllowedExtension');
Member::add_extension('MemberTest_ViewingDeniedExtension');
$member3 = $this->objFromFixture('Member', 'managementmember');
@ -487,7 +487,7 @@ class MemberTest extends FunctionalTest {
$this->assertFalse($member3->canEdit());
/* Apply a extension that allows viewing and editing but denies deletion */
Object::remove_extension('Member', 'MemberTest_ViewingDeniedExtension');
Member::remove_extension('MemberTest_ViewingDeniedExtension');
Member::add_extension('MemberTest_EditingAllowedDeletingDeniedExtension');
$member4 = $this->objFromFixture('Member', 'accountingmember');
@ -495,7 +495,7 @@ class MemberTest extends FunctionalTest {
$this->assertFalse($member4->canDelete());
$this->assertTrue($member4->canEdit());
Object::remove_extension('Member', 'MemberTest_EditingAllowedDeletingDeniedExtension');
Member::remove_extension('MemberTest_EditingAllowedDeletingDeniedExtension');
$this->addExtensions($extensions);
}
@ -619,7 +619,7 @@ class MemberTest extends FunctionalTest {
*/
protected function removeExtensions($extensions) {
if($extensions) foreach($extensions as $extension) {
Object::remove_extension('Member', $extension);
Member::remove_extension($extension);
}
return $extensions;
}