Switch from stdClass to arrays which works around issues caused in

http://dev.kohanaphp.com/issues/2459 -- I don't exactly know why, but
the solutions are equivalent so I'm not going to dig too far.
This commit is contained in:
Bharat Mediratta
2010-01-18 12:08:39 -08:00
parent 41a392611c
commit 284788d964

View File

@@ -18,27 +18,25 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class model_cache_Core {
private static $cache;
private static $cache = array();
static function get($model_name, $id, $field_name="id") {
if (TEST_MODE || empty(self::$cache->$model_name->$field_name->$id)) {
if (TEST_MODE || empty(self::$cache[$model_name][$field_name][$id])) {
$model = ORM::factory($model_name)->where($field_name, "=", $id)->find();
if (!$model->loaded()) {
throw new Exception("@todo MISSING_MODEL $model_name:$id");
}
self::$cache->$model_name->$field_name->$id = $model;
self::$cache[$model_name][$field_name][$id] = $model;
}
return self::$cache->$model_name->$field_name->$id;
return self::$cache[$model_name][$field_name][$id];
}
static function clear() {
self::$cache = new stdClass();
self::$cache = array();
}
static function set($model) {
self::$cache->{$model->object_name}
->{$model->primary_key}
->{$model->{$model->primary_key}} = $model;
self::$cache[$model->object_name][$model->primary_key][$model->{$model->primary_key}] = $model;
}
}