diff --git a/core/Object.php b/core/Object.php index 864366eab..519182f44 100755 --- a/core/Object.php +++ b/core/Object.php @@ -41,10 +41,11 @@ abstract class Object { */ private static - $statics = array(), - $cached_statics = array(), - $extra_statics = array(), - $replaced_statics = array(); + $statics = array(), + $cached_statics = array(), + $extra_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; } @@ -396,6 +406,28 @@ abstract class Object { DataObjectDecorator::load_extra_statics($class, $extensionClass); } } + + /** + * 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. diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index b2254f611..f0220e877 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -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'); -} - ?> \ No newline at end of file diff --git a/filesystem/File.php b/filesystem/File.php index 1753946ac..7488ea0a4 100755 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -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'); -} - ?> diff --git a/security/Group.php b/security/Group.php index cff104f01..6994c6662 100644 --- a/security/Group.php +++ b/security/Group.php @@ -387,10 +387,5 @@ class Group extends DataObject { return false; } } - -// 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'); -} ?>