public final function dataRefresh() { list($data) = Model::factoryData(['id' => $this->id], $this->table, $this->database); // Database data object unique to this object $this->_data = new Data($data, $this->table, Schema::get($this->database)); Data::updateCache($this->_data); // Call replacement constructor after storing in the cache list (to prevent recursion) $this->dataClearCache(); $this->_init(); return $this; }
public function __call($name, $args) { // If we use Model::COUNT_ONLY on empty container, return 0 if (count($this->container) == 0 && is_numeric($args[1]) && $args[1] & Model::COUNT_ONLY) { return 0; } // Foreign keys if ($this->container[0] instanceof Model and !method_exists($this->container[0], $name) and $this->container[0]->_data->externalKeyExists($name)) { if (is_numeric($args[1]) && $args[1] & Model::COUNT_ONLY) { return Data::groupJoinCount($this, $name, $args[0]); } return Data::groupJoin($this, $name, $args[0]); } // Otherwise... $list = []; foreach ($this->container as $item) { $value = call_user_func_array([$item, $name], $args); if ($value instanceof Collection) { $list = array_merge($list, $value->toArray()); } else { $list[] = $value; } } // Return new list or count depending on options passed if (is_numeric($args[1]) && $args[1] & Model::COUNT_ONLY) { return count($list); } else { return new static($list); } }
public static function updateCache(Data $db) { $db->lock(); $key = $db->data['id'] . ':' . $db->table . ':' . $db->schema->namespace; return static::$__instance[$key] = $db; }