Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit e7194a9

Browse files
author
Nik Barham
committed
Data objects now have internal store so that $external is not thrown away
when a new copy of data object is created.
1 parent 43d9fa7 commit e7194a9

File tree

2 files changed

+398
-371
lines changed

2 files changed

+398
-371
lines changed

src/Automatorm/Orm/Data.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ class Data
1616
protected $locked = true; // Can we use __set() - for updates/inserts
1717
protected $new = false; // Is this to be a new row? (used with Model::new_db())
1818

19+
protected static $instance = [];
20+
21+
public static function make(array $data, $table, Schema $schema)
22+
{
23+
$key = $data['id'] . ':' . $table . ':' . $schema->namespace;
24+
25+
if (isset(static::$instance[$key]))
26+
{
27+
$obj = static::$instance[$key];
28+
}
29+
else
30+
{
31+
$obj = static::$instance[$key] = new static($data, $table, $schema, true, false);
32+
}
33+
34+
return $obj;
35+
}
36+
37+
public static function updateCache(Data $db)
38+
{
39+
$db->lock();
40+
$key = $db->data['id'] . ':' . $db->table . ':' . $db->schema->namespace;
41+
static::$instance[$key] = $db;
42+
return $db;
43+
}
44+
1945
public function __construct(array $data, $table, Schema $schema, $locked = true, $new = false)
2046
{
2147
$this->database = $schema->database;

0 commit comments

Comments
 (0)