Skip to content
This repository
Browse code

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 U authored April 12, 2012

Showing 1 changed file with 20 additions and 20 deletions. Show diff stats Hide diff stats

  1. 40  model/DataObject.php
40  model/DataObject.php
@@ -235,10 +235,10 @@ public static function custom_database_fields($class) {
235 235
 	 * Will check all applicable ancestor classes and aggregate results.
236 236
 	 */
237 237
 	static function is_composite_field($class, $name, $aggregated = true) {
238  
-		if(!isset(self::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
  238
+		if(!isset(DataObject::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
239 239
 		
240  
-		if(isset(self::$_cache_composite_fields[$class][$name])) {
241  
-			return self::$_cache_composite_fields[$class][$name];
  240
+		if(isset(DataObject::$_cache_composite_fields[$class][$name])) {
  241
+			return DataObject::$_cache_composite_fields[$class][$name];
242 242
 			
243 243
 		} else if($aggregated && $class != 'DataObject' && ($parentClass=get_parent_class($class)) != 'DataObject') {
244 244
 			return self::is_composite_field($parentClass, $name);
@@ -250,9 +250,9 @@ static function is_composite_field($class, $name, $aggregated = true) {
250 250
 	 * Will check all applicable ancestor classes and aggregate results.
251 251
 	 */
252 252
 	static function composite_fields($class, $aggregated = true) {
253  
-		if(!isset(self::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
  253
+		if(!isset(DataObject::$_cache_composite_fields[$class])) self::cache_composite_fields($class);
254 254
 		
255  
-		$compositeFields = self::$_cache_composite_fields[$class];
  255
+		$compositeFields = DataObject::$_cache_composite_fields[$class];
256 256
 		
257 257
 		if($aggregated && $class != 'DataObject' && ($parentClass=get_parent_class($class)) != 'DataObject') {
258 258
 			$compositeFields = array_merge($compositeFields, 
@@ -280,7 +280,7 @@ private static function cache_composite_fields($class) {
280 280
 			}
281 281
 		}
282 282
 		
283  
-		self::$_cache_composite_fields[$class] = $compositeFields;
  283
+		DataObject::$_cache_composite_fields[$class] = $compositeFields;
284 284
 	}
285 285
 	
286 286
 	/**
@@ -2122,7 +2122,7 @@ public function hasOwnTableDatabaseField($field) {
2122 2122
 			return 'Int';
2123 2123
 		}
2124 2124
 		// get cached fieldmap
2125  
-		$fieldMap = isset(self::$cache_has_own_table_field[$this->class]) ? self::$cache_has_own_table_field[$this->class] : null;
  2125
+		$fieldMap = isset(DataObject::$cache_has_own_table_field[$this->class]) ? DataObject::$cache_has_own_table_field[$this->class] : null;
2126 2126
 		
2127 2127
 		// if no fieldmap is cached, get all fields
2128 2128
 		if(!$fieldMap) {
@@ -2144,7 +2144,7 @@ public function hasOwnTableDatabaseField($field) {
2144 2144
 			}
2145 2145
 
2146 2146
 			// set cached fieldmap
2147  
-			self::$cache_has_own_table_field[$this->class] = $fieldMap;
  2147
+			DataObject::$cache_has_own_table_field[$this->class] = $fieldMap;
2148 2148
 		}
2149 2149
 
2150 2150
 		// Remove string-based "constructor-arguments" from the DBField definition
@@ -2167,14 +2167,14 @@ public static function has_own_table($dataClass) {
2167 2167
 		// which causes PHP < 5.3 to segfault in rare circumstances, see PHP bug #46753
2168 2168
 		if($dataClass == 'DataObject' || !in_array('DataObject', ClassInfo::ancestry($dataClass))) return false;
2169 2169
 		
2170  
-		if(!isset(self::$cache_has_own_table[$dataClass])) {
  2170
+		if(!isset(DataObject::$cache_has_own_table[$dataClass])) {
2171 2171
 			if(get_parent_class($dataClass) == 'DataObject') {
2172  
-				self::$cache_has_own_table[$dataClass] = true;
  2172
+				DataObject::$cache_has_own_table[$dataClass] = true;
2173 2173
 			} else {
2174  
-				self::$cache_has_own_table[$dataClass] = Object::uninherited_static($dataClass, 'db') || Object::uninherited_static($dataClass, 'has_one');
  2174
+				DataObject::$cache_has_own_table[$dataClass] = Object::uninherited_static($dataClass, 'db') || Object::uninherited_static($dataClass, 'has_one');
2175 2175
 			}
2176 2176
 		}
2177  
-		return self::$cache_has_own_table[$dataClass];
  2177
+		return DataObject::$cache_has_own_table[$dataClass];
2178 2178
 	}
2179 2179
 	
2180 2180
 	/**
@@ -2648,7 +2648,7 @@ public function flushCache($persistent = true) {
2648 2648
 
2649 2649
 		$classes = ClassInfo::ancestry($this->class);
2650 2650
 		foreach($classes as $class) {
2651  
-			if(isset(self::$_cache_get_one[$class])) unset(self::$_cache_get_one[$class]);
  2651
+			if(isset(DataObject::$_cache_get_one[$class])) unset(DataObject::$_cache_get_one[$class]);
2652 2652
 		}
2653 2653
 		
2654 2654
 		$this->extend('flushCache');
@@ -2660,23 +2660,23 @@ public function flushCache($persistent = true) {
2660 2660
 	 * Flush the get_one global cache and destroy associated objects.
2661 2661
 	 */
2662 2662
 	static function flush_and_destroy_cache() {
2663  
-		if(self::$_cache_get_one) foreach(self::$_cache_get_one as $class => $items) {
  2663
+		if(DataObject::$_cache_get_one) foreach(DataObject::$_cache_get_one as $class => $items) {
2664 2664
 			if(is_array($items)) foreach($items as $item) {
2665 2665
 				if($item) $item->destroy();
2666 2666
 			}
2667 2667
 		}
2668  
-		self::$_cache_get_one = array();
  2668
+		DataObject::$_cache_get_one = array();
2669 2669
 	}
2670 2670
 	
2671 2671
 	/**
2672 2672
 	 * Reset all global caches associated with DataObject.
2673 2673
 	 */
2674 2674
 	static function reset() {
2675  
-		self::$cache_has_own_table = array();
2676  
-		self::$cache_has_own_table_field = array();
2677  
-		self::$_cache_get_one = array();
2678  
-		self::$_cache_composite_fields = array();
2679  
-		self::$_cache_get_class_ancestry = array();
  2675
+		DataObject::$cache_has_own_table = array();
  2676
+		DataObject::$cache_has_own_table_field = array();
  2677
+		DataObject::$_cache_get_one = array();
  2678
+		DataObject::$_cache_composite_fields = array();
  2679
+		DataObject::$_cache_get_class_ancestry = array();
2680 2680
 	}
2681 2681
 
2682 2682
 	/**

0 notes on commit ae5bd7d

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