Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENHANCEMENT: refer to cache statics explicitly via DataObject (os6175)

Unify the usage across the class. Since the intention is to have a
single site-wide cache, calling via DataObject seems to be a better
option - self could theoretically end up calling a redefined field from
a subclass.
  • Loading branch information...
commit ae5bd7d65e18ba2bb8cf2f32a6f03d61dee05b2c 1 parent 5186a0c
@mateusz mateusz authored
Showing with 20 additions and 20 deletions.
  1. +20 −20 model/DataObject.php
View
40 model/DataObject.php
@@ -235,10 +235,10 @@ public static function custom_database_fields($class) {
* Will check all applicable ancestor classes and aggregate results.
*/
static function is_composite_field($class, $name, $aggregated = true) {
- if(!isset(self::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
+ if(!isset(DataObject::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
- if(isset(self::$_cache_composite_fields[$class][$name])) {
- return self::$_cache_composite_fields[$class][$name];
+ if(isset(DataObject::$_cache_composite_fields[$class][$name])) {
+ return DataObject::$_cache_composite_fields[$class][$name];
} else if($aggregated && $class != 'DataObject' && ($parentClass=get_parent_class($class)) != 'DataObject') {
return self::is_composite_field($parentClass, $name);
@@ -250,9 +250,9 @@ static function is_composite_field($class, $name, $aggregated = true) {
* Will check all applicable ancestor classes and aggregate results.
*/
static function composite_fields($class, $aggregated = true) {
- if(!isset(self::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
+ if(!isset(DataObject::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
- $compositeFields = self::$_cache_composite_fields[$class];
+ $compositeFields = DataObject::$_cache_composite_fields[$class];
if($aggregated && $class != 'DataObject' && ($parentClass=get_parent_class($class)) != 'DataObject') {
$compositeFields = array_merge($compositeFields,
@@ -280,7 +280,7 @@ private static function cache_composite_fields($class) {
}
}
- self::$_cache_composite_fields[$class] = $compositeFields;
+ DataObject::$_cache_composite_fields[$class] = $compositeFields;
}
/**
@@ -2122,7 +2122,7 @@ public function hasOwnTableDatabaseField($field) {
return 'Int';
}
// get cached fieldmap
- $fieldMap = isset(self::$cache_has_own_table_field[$this->class]) ? self::$cache_has_own_table_field[$this->class] : null;
+ $fieldMap = isset(DataObject::$cache_has_own_table_field[$this->class]) ? DataObject::$cache_has_own_table_field[$this->class] : null;
// if no fieldmap is cached, get all fields
if(!$fieldMap) {
@@ -2144,7 +2144,7 @@ public function hasOwnTableDatabaseField($field) {
}
// set cached fieldmap
- self::$cache_has_own_table_field[$this->class] = $fieldMap;
+ DataObject::$cache_has_own_table_field[$this->class] = $fieldMap;
}
// Remove string-based "constructor-arguments" from the DBField definition
@@ -2167,14 +2167,14 @@ public static function has_own_table($dataClass) {
// which causes PHP < 5.3 to segfault in rare circumstances, see PHP bug #46753
if($dataClass == 'DataObject' || !in_array('DataObject', ClassInfo::ancestry($dataClass))) return false;
- if(!isset(self::$cache_has_own_table[$dataClass])) {
+ if(!isset(DataObject::$cache_has_own_table[$dataClass])) {
if(get_parent_class($dataClass) == 'DataObject') {
- self::$cache_has_own_table[$dataClass] = true;
+ DataObject::$cache_has_own_table[$dataClass] = true;
} else {
- self::$cache_has_own_table[$dataClass] = Object::uninherited_static($dataClass, 'db') || Object::uninherited_static($dataClass, 'has_one');
+ DataObject::$cache_has_own_table[$dataClass] = Object::uninherited_static($dataClass, 'db') || Object::uninherited_static($dataClass, 'has_one');
}
}
- return self::$cache_has_own_table[$dataClass];
+ return DataObject::$cache_has_own_table[$dataClass];
}
/**
@@ -2648,7 +2648,7 @@ public function flushCache($persistent = true) {
$classes = ClassInfo::ancestry($this->class);
foreach($classes as $class) {
- if(isset(self::$_cache_get_one[$class])) unset(self::$_cache_get_one[$class]);
+ if(isset(DataObject::$_cache_get_one[$class])) unset(DataObject::$_cache_get_one[$class]);
}
$this->extend('flushCache');
@@ -2660,23 +2660,23 @@ public function flushCache($persistent = true) {
* Flush the get_one global cache and destroy associated objects.
*/
static function flush_and_destroy_cache() {
- if(self::$_cache_get_one) foreach(self::$_cache_get_one as $class => $items) {
+ if(DataObject::$_cache_get_one) foreach(DataObject::$_cache_get_one as $class => $items) {
if(is_array($items)) foreach($items as $item) {
if($item) $item->destroy();
}
}
- self::$_cache_get_one = array();
+ DataObject::$_cache_get_one = array();
}
/**
* Reset all global caches associated with DataObject.
*/
static function reset() {
- self::$cache_has_own_table = array();
- self::$cache_has_own_table_field = array();
- self::$_cache_get_one = array();
- self::$_cache_composite_fields = array();
- self::$_cache_get_class_ancestry = array();
+ DataObject::$cache_has_own_table = array();
+ DataObject::$cache_has_own_table_field = array();
+ DataObject::$_cache_get_one = array();
+ DataObject::$_cache_composite_fields = array();
+ DataObject::$_cache_get_class_ancestry = array();
}
/**

0 comments on commit ae5bd7d

Please sign in to comment.
Something went wrong with that request. Please try again.