/**
* Create an Elgg* object from a given entity row.
*
* Handles loading all tables into the correct class.
*
* @see get_entity_as_row()
* @see add_subtype()
* @see get_entity()
*
* @access private
*
* @param stdClass $row The row of the entry in the entities table.
* @return ElggEntity|false
* @throws ClassException
* @throws InstallationException
*/
public function rowToElggStar($row)
{
if (!$row instanceof stdClass) {
return $row;
}
if (!isset($row->guid) || !isset($row->subtype)) {
return $row;
}
$class_name = $this->subtype_table->getClassFromId($row->subtype);
if ($class_name && !class_exists($class_name)) {
$this->logger->error("Class '{$class_name}' was not found, missing plugin?");
$class_name = '';
}
if (!$class_name) {
$map = ['object' => ElggObject::class, 'user' => ElggUser::class, 'group' => ElggGroup::class, 'site' => ElggSite::class];
if (isset($map[$row->type])) {
$class_name = $map[$row->type];
} else {
throw new InstallationException("Entity type {$row->type} is not supported.");
}
}
$entity = new $class_name($row);
if (!$entity instanceof ElggEntity) {
throw new ClassException("{$class_name} must extend " . ElggEntity::class);
}
return $entity;
}