private function createEntityWithKey(\stdClass $obj_result)
{
if (isset($obj_result->entity->key->path)) {
$arr_path = $obj_result->entity->key->path;
// Key for 'self' (the last part of the KEY PATH)
$obj_path_end = array_pop($arr_path);
// Kind
if (isset($obj_path_end->kind)) {
if ($obj_path_end->kind == $this->obj_schema->getKind()) {
$bol_schema_match = TRUE;
$obj_gds_entity = $this->obj_schema->createEntity();
} else {
// Attempt to handle a non-schema-match
$bol_schema_match = FALSE;
$obj_gds_entity = (new \GDS\Entity())->setKind($obj_path_end->kind);
}
} else {
throw new \RuntimeException("No Kind for end(path) for Entity?");
}
// ID or Name
if (isset($obj_path_end->id)) {
$obj_gds_entity->setKeyId($obj_path_end->id);
} elseif (isset($obj_path_end->name)) {
$obj_gds_entity->setKeyName($obj_path_end->name);
} else {
throw new \RuntimeException("No KeyID or KeyName for Entity?");
}
// Ancestors?
$int_path_elements = count($arr_path);
if ($int_path_elements > 0) {
$arr_anc_path = [];
foreach ($arr_path as $obj_kpe) {
$arr_anc_path[] = ['kind' => $obj_kpe->kind, 'id' => isset($obj_kpe->id) ? $obj_kpe->id : null, 'name' => isset($obj_kpe->name) ? $obj_kpe->name : null];
}
$obj_gds_entity->setAncestry($arr_anc_path);
}
} else {
throw new \RuntimeException("No path for Entity Key?");
}
// Return whether or not the Schema matched
return [$obj_gds_entity, $bol_schema_match];
}