/** * Insert entity data into the database * * @param string $class Class name of object being created * @param array $data The data to insert * @return int The ID of newly inserted record */ protected function injectDbWithEntityData($class, $data = []) { $storage =& Memory::_getInternalStorage(); if (!isset($storage[$class])) { $storage[$class] = []; } $id = mt_rand(); $storage[$class][$id] = $data; return $id; }
protected static function findByIdInDb($id) { $id = (int) $id; $class = get_called_class(); // Get trait level storage $storage =& Memory::_getInternalStorage(); // Try to find in memory storage if (!isset($storage[$class]) || !isset($storage[$class][$id])) { return null; } // Create new instance $instance = static::factory($id); return $instance; }