Permalink
Browse files

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

  • Loading branch information...
1 parent fdea532 commit 6dd6a5c1881d96194761eef45f0a1a83f6f9bfa2 @andrewandante andrewandante committed with halkyon Oct 9, 2012
View
@@ -508,10 +508,17 @@ public static function add_extension($extension) {
*
* @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
@@ -278,7 +278,7 @@ public function setUpOnce() {
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 @@ public function tearDownOnce() {
// Remove extensions added for testing
foreach($this->extensionsToRemove as $class => $extensions) {
foreach($extensions as $extension) {
- Object::remove_extension($class, $extension);
+ $class::remove_extension($extension);
}
}
@@ -242,7 +242,7 @@ public function testHasAndAddExtension() {
// @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 @@ public function testRemoveExtension() {
"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 @@ public function testRemoveExtension() {
);
// 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()"
@@ -12,7 +12,7 @@ public function setUp() {
$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() {
@@ -478,7 +478,7 @@ public function testExtendedCan() {
$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,15 +487,15 @@ public function testExtendedCan() {
$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');
$this->assertTrue($member4->canView());
$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 @@ protected function addExtensions($extensions) {
*/
protected function removeExtensions($extensions) {
if($extensions) foreach($extensions as $extension) {
- Object::remove_extension('Member', $extension);
+ Member::remove_extension($extension);
}
return $extensions;
}

0 comments on commit 6dd6a5c

Please sign in to comment.