From 6dd6a5c1881d96194761eef45f0a1a83f6f9bfa2 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Wed, 10 Oct 2012 10:30:40 +1300 Subject: [PATCH] APICHANGE: Use late static binding for Object::remove_extension() --- core/Object.php | 11 +++++++++-- dev/SapphireTest.php | 4 ++-- tests/core/ObjectTest.php | 6 +++--- tests/search/FulltextSearchableTest.php | 2 +- tests/security/MemberTest.php | 8 ++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/core/Object.php b/core/Object.php index a473be809..f301de427 100755 --- a/core/Object.php +++ b/core/Object.php @@ -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 diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index a96782106..1e24a323a 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -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); } } diff --git a/tests/core/ObjectTest.php b/tests/core/ObjectTest.php index b2ed8df57..af7ce36bc 100644 --- a/tests/core/ObjectTest.php +++ b/tests/core/ObjectTest.php @@ -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()" diff --git a/tests/search/FulltextSearchableTest.php b/tests/search/FulltextSearchableTest.php index 88694bcd6..87268a851 100644 --- a/tests/search/FulltextSearchableTest.php +++ b/tests/search/FulltextSearchableTest.php @@ -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() { diff --git a/tests/security/MemberTest.php b/tests/security/MemberTest.php index e676145d5..8efca2a89 100644 --- a/tests/security/MemberTest.php +++ b/tests/security/MemberTest.php @@ -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; }