Permalink
Browse files

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

  • Loading branch information...
andrewandante authored and halkyon committed Oct 9, 2012
1 parent 6dd6a5c commit 0c8de0a1de4e5c3a3ac3e0ae74c1073d546c0554
@@ -135,7 +135,8 @@ public function applicablePagesHelper($ids, $methodName, $checkStagePages = true
}
}
- if(Object::has_extension($this->managedClass, 'Versioned')) {
+ $managed_class = $this->managedClass;
+ if($managed_class::has_extension('Versioned')) {
// Get the pages that only exist on live (deleted from stage)
if($checkLivePages && $onlyOnLive) {
$SQL_ids = implode(', ', array_keys($onlyOnLive));
@@ -85,7 +85,7 @@ public function handleAction($request) {
foreach($ids as $k => $v) if(!is_numeric($v)) unset($ids[$k]);
if($ids) {
- if(class_exists('Translatable') && Object::has_extension('SiteTree','Translatable')) {
+ if(class_exists('Translatable') && SiteTree::has_extension('Translatable')) {
Translatable::disable_locale_filter();
}
@@ -98,11 +98,12 @@ public function handleAction($request) {
)
);
- if(class_exists('Translatable') && Object::has_extension('SiteTree','Translatable')) {
+ if(class_exists('Translatable') && SiteTree::has_extension('Translatable')) {
Translatable::enable_locale_filter();
}
- if(Object::has_extension($this->recordClass, 'Versioned')) {
+ $record_class = $this->recordClass;
+ if($record_class::has_extension('Versioned')) {
// If we didn't query all the pages, then find the rest on the live site
if(!$pages || $pages->Count() < sizeof($ids)) {
foreach($ids as $id) $idsFromLive[$id] = true;
@@ -1035,8 +1035,10 @@ public function getEditForm($id = null, $fields = null) {
if(!$fields->dataFieldByName('ClassName')) {
$fields->push(new HiddenField('ClassName'));
}
+
+ $tree_class = $this->stat('tree_class');
if(
- Object::has_extension($this->stat('tree_class'), 'Hierarchy')
+ $tree_class::has_extension('Hierarchy')
&& !$fields->dataFieldByName('ParentID')
) {
$fields->push(new HiddenField('ParentID'));
View
@@ -422,10 +422,17 @@ public static function add_static_var($class, $name, $value, $replace = false) {
/**
* Return TRUE if a class has a specified extension
*
- * @param string $class
* @param string $requiredExtension the class name of the extension to check for.
*/
- public static function has_extension($class, $requiredExtension) {
+ public static function has_extension($requiredExtension) {
+ $class = get_called_class();
+
+ if(func_num_args() > 1) {
+ Deprecation::notice('3.1.0', "Object::has_extension() deprecated. Call has_extension() on the class");
+ $class = func_get_arg(0);
+ $extension = func_get_arg(1);
+ }
+
$requiredExtension = strtolower($requiredExtension);
$extensions = Config::inst()->get($class, 'extensions');
View
@@ -275,7 +275,7 @@ public function setUpOnce() {
// Remove any illegal extensions that are present
foreach($this->illegalExtensions as $class => $extensions) {
foreach($extensions as $extension) {
- if (Object::has_extension($class, $extension)) {
+ if ($class::has_extension($extension)) {
if(!isset($this->extensionsToReapply[$class])) $this->extensionsToReapply[$class] = array();
$this->extensionsToReapply[$class][] = $extension;
$class::remove_extension($extension);
@@ -288,7 +288,7 @@ public function setUpOnce() {
foreach($this->requiredExtensions as $class => $extensions) {
$this->extensionsToRemove[$class] = array();
foreach($extensions as $extension) {
- if(!Object::has_extension($class, $extension)) {
+ if(!$class::has_extension($extension)) {
if(!isset($this->extensionsToRemove[$class])) $this->extensionsToReapply[$class] = array();
$this->extensionsToRemove[$class][] = $extension;
$class::add_extension($extension);
@@ -69,7 +69,7 @@ public function Field($properties = array()) {
if($this->form->getRecord() && $this->form->getRecord()->exists()) {
$record = $this->form->getRecord();
- if(class_exists('Translatable') && Object::has_extension('SiteTree', 'Translatable') && $record->Locale){
+ if(class_exists('Translatable') && SiteTree::has_extension('Translatable') && $record->Locale){
$iframe = "iframe?locale=".$record->Locale;
}else{
$iframe = "iframe";
View
@@ -192,11 +192,11 @@ public function testGetExtensions() {
public function testHasAndAddExtension() {
// ObjectTest_ExtendTest1 is built in via $extensions
$this->assertTrue(
- Object::has_extension('ObjectTest_ExtensionTest', 'OBJECTTEST_ExtendTest1'),
+ ObjectTest_ExtensionTest::has_extension('OBJECTTEST_ExtendTest1'),
"Extensions are detected when set on Object::\$extensions on has_extension() without case-sensitivity"
);
$this->assertTrue(
- Object::has_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest1'),
+ ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest1'),
"Extensions are detected when set on Object::\$extensions on has_extension() without case-sensitivity"
);
$this->assertTrue(
@@ -207,7 +207,7 @@ public function testHasAndAddExtension() {
// ObjectTest_ExtendTest2 is built in via $extensions (with parameters)
$this->assertTrue(
- Object::has_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest2'),
+ ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest2'),
"Extensions are detected with static has_extension() when set on Object::\$extensions with"
. " additional parameters"
);
@@ -217,7 +217,7 @@ public function testHasAndAddExtension() {
. " additional parameters"
);
$this->assertFalse(
- Object::has_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest3'),
+ ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest3'),
"Other extensions available in the system are not present unless explicitly added to this object"
. " when checking through has_extension()"
);
@@ -230,7 +230,7 @@ public function testHasAndAddExtension() {
// ObjectTest_ExtendTest3 is added manually
ObjectTest_ExtensionTest::add_extension('ObjectTest_ExtendTest3("Param")');
$this->assertTrue(
- Object::has_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest3'),
+ ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest3'),
"Extensions are detected with static has_extension() when added through add_extension()"
);
// a singleton() wouldn't work as its already initialized
@@ -249,13 +249,13 @@ public function testRemoveExtension() {
// manually add ObjectTest_ExtendTest2
ObjectTest_ExtensionRemoveTest::add_extension('ObjectTest_ExtendTest2');
$this->assertTrue(
- Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2'),
+ ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest2'),
"Extension added through \$add_extension() are added correctly"
);
ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest2');
$this->assertFalse(
- Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2'),
+ ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest2'),
"Extension added through \$add_extension() are detected as removed in has_extension()"
);
$this->assertFalse(
@@ -266,7 +266,7 @@ public function testRemoveExtension() {
// ObjectTest_ExtendTest1 is already present in $extensions
ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest1');
$this->assertFalse(
- Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest1'),
+ ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest1'),
"Extension added through \$extensions are detected as removed in has_extension()"
);
$objectTest_ExtensionRemoveTest = new ObjectTest_ExtensionRemoveTest();
@@ -9,7 +9,7 @@ class FulltextSearchableTest extends SapphireTest {
public function setUp() {
parent::setUp();
- $this->orig['File_searchable'] = Object::has_extension('File', 'FulltextSearchable');
+ $this->orig['File_searchable'] = File::has_extension('FulltextSearchable');
// TODO This shouldn't need all arguments included
File::remove_extension('FulltextSearchable(\'"Filename","Title","Content"\')');
@@ -26,17 +26,17 @@ public function tearDown() {
public function testEnable() {
FulltextSearchable::enable();
- $this->assertTrue(Object::has_extension('File', 'FulltextSearchable'));
+ $this->assertTrue(File::has_extension('FulltextSearchable'));
}
public function testEnableWithCustomClasses() {
FulltextSearchable::enable(array('File'));
- $this->assertTrue(Object::has_extension('File', 'FulltextSearchable'));
+ $this->assertTrue(File::has_extension('FulltextSearchable'));
// TODO This shouldn't need all arguments included
- Object::remove_extension('File', 'FulltextSearchable(\'"Filename","Title","Content"\')');
+ File::remove_extension('FulltextSearchable(\'"Filename","Title","Content"\')');
- $this->assertFalse(Object::has_extension('File', 'FulltextSearchable'));
+ $this->assertFalse(File::has_extension('File', 'FulltextSearchable'));
}
}

0 comments on commit 0c8de0a

Please sign in to comment.