mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
79912f6ba6
commit
6a52153b9f
@ -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.
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
?>
|
@ -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');
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user