Elgg\Database\EntityTable::rowToElggStar PHP Method

rowToElggStar() public method

Handles loading all tables into the correct class.
See also: get_entity_as_row()
See also: add_subtype()
See also: get_entity()
public rowToElggStar ( stdClas\stdClass $row ) : ElggEntit\ElggEntity | false
$row stdClas\stdClass The row of the entry in the entities table.
return ElggEntit\ElggEntity | false
    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;
    }