diff --git a/core/Object.php b/core/Object.php index b84516607..2e49fbd76 100755 --- a/core/Object.php +++ b/core/Object.php @@ -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); + } + } } } } diff --git a/tests/api/RestfulServiceTest.php b/tests/api/RestfulServiceTest.php index 76f943a4a..0da14a7a0 100644 --- a/tests/api/RestfulServiceTest.php +++ b/tests/api/RestfulServiceTest.php @@ -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("HTTP Error", $response->getBody()); @@ -271,5 +271,4 @@ class RestfulServiceTest_MockRestfulService extends RestfulService { return $response; } -} -?> +} \ No newline at end of file