BUGFIX #4285: Fixed application of decorators when add_extension not used.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81676 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-07-13 03:56:26 +00:00
parent 79912f6ba6
commit 6a52153b9f
4 changed files with 36 additions and 20 deletions

View File

@ -44,7 +44,8 @@ abstract class Object {
$statics = array(),
$cached_statics = array(),
$extra_statics = array(),
$replaced_statics = array();
$replaced_statics = array(),
$_cache_statics_prepared = array();
private static
$classes_constructed = array(),
@ -171,6 +172,11 @@ abstract class Object {
*/
public static function get_static($class, $name, $uncached = false) {
if(!isset(self::$cached_statics[$class][$name]) || $uncached) {
if(!isset(self::$_cache_statics_prepared[$class])) {
Object::prepare_statics($class);
}
//if($class == 'DataObjectDecoratorTest_MyObject') Debug::message("$class - $name");
$extra = $builtIn = $break = $replacedAt = false;
$ancestry = array_reverse(ClassInfo::ancestry($class));
@ -234,6 +240,10 @@ abstract class Object {
* @param mixed $value
*/
public static function set_static($class, $name, $value) {
if(!isset(self::$_cache_statics_prepared[$class])) {
Object::prepare_statics($class);
}
self::$statics[$class][$name] = $value;
self::$cached_statics[$class][$name] = true;
}
@ -397,6 +407,28 @@ abstract class Object {
}
}
/**
* Prepare static variables before processing a {@link get_static} or {@link set_static}
* call.
*/
private static function prepare_statics($class) {
// _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::get_static($class, 'extensions');
if($extensions) foreach($extensions as $extension) {
if(preg_match('/^([^(]*)/', $extension, $matches)) {
$extensionClass = $matches[1];
DataObjectDecorator::load_extra_statics($class, $extensionClass);
}
}
}
}
/**
* Remove an extension from a class.
* Keep in mind that this won't revert any datamodel additions

View File

@ -1955,10 +1955,4 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
// Workaround for issues with extensions defined directly on the class in trunk
if(method_exists('DataObjectDecorator', 'load_extra_statics')) {
DataObjectDecorator::load_extra_statics('SiteTree', 'Hierarchy');
DataObjectDecorator::load_extra_statics('SiteTree', 'Versioned');
}
?>

View File

@ -617,9 +617,4 @@ class File extends DataObject {
}
// Workaround for issues with extensions defined directly on the class in trunk
if(method_exists('DataObjectDecorator', 'load_extra_statics')) {
DataObjectDecorator::load_extra_statics('File', 'Hierarchy');
}
?>

View File

@ -388,9 +388,4 @@ class Group extends DataObject {
}
}
// Workaround for issues with extensions defined directly on the class in trunk
if(method_exists('DataObjectDecorator', 'load_extra_statics')) {
DataObjectDecorator::load_extra_statics('Group', 'Hierarchy');
}
?>