ENHANCEMENT: #5248 improved the handling of attaching invalid extensions to dataobjects.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@115174 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Will Rossiter 2010-12-19 23:04:44 +00:00
parent 517a51194b
commit 0b54ce3450
2 changed files with 26 additions and 8 deletions

View File

@ -538,7 +538,12 @@ abstract class Object {
// load statics now for DataObject classes
if(ClassInfo::is_subclass_of($class, 'DataObject')) {
DataObjectDecorator::load_extra_statics($class, $extension);
if(is_subclass_of($extensionClass, 'DataObjectDecorator')) {
DataObjectDecorator::load_extra_statics($class, $extension);
}
else {
user_error("$extensionClass cannot be applied to $class without being a DataObjectDecorator", E_USER_ERROR);
}
}
}
@ -550,12 +555,26 @@ abstract class Object {
// _cache_statics_prepared setting must come first to prevent infinite loops when we call
// get_static below
self::$_cache_statics_prepared[$class] = true;
// load statics now for DataObject classes
if(is_subclass_of($class, 'DataObject')) {
$extensions = Object::uninherited_static($class, 'extensions');
if($extensions) foreach($extensions as $extension) {
DataObjectDecorator::load_extra_statics($class, $extension);
if($extensions) {
foreach($extensions as $extension) {
$extensionClass = $extension;
if(preg_match('/^([^(]*)/', $extension, $matches)) {
$extensionClass = $matches[1];
}
if(is_subclass_of($extensionClass, 'DataObjectDecorator')) {
DataObjectDecorator::load_extra_statics($class, $extension);
}
else {
user_error("$extensionClass cannot be applied to $class without being a DataObjectDecorator", E_USER_ERROR);
}
}
}
}
}

View File

@ -99,9 +99,9 @@ class RestfulServiceTest extends SapphireTest {
}
function testHttpErrorWithoutCache() {
$connection = new RestfulService(Director::absoluteBaseURL(), 0);
$connection = new RestfulServiceTest_MockRestfulService(Director::absoluteBaseURL(), 0);
$response = $connection->request('RestfulServiceTest_Controller/httpErrorWithoutCache?usetestmanifest=1&flush=1');
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->getCachedBody());
$this->assertContains("<error>HTTP Error</error>", $response->getBody());
@ -271,5 +271,4 @@ class RestfulServiceTest_MockRestfulService extends RestfulService {
return $response;
}
}
?>
}