function createKeyForTestItem()
{
    $path = new Google_Service_Datastore_KeyPathElement();
    $path->setKind("testkind");
    $path->setName("testkeyname");
    $key = DatastoreService::getInstance()->createKey();
    $key->setPath([$path]);
    return $key;
}
 /**
  * Generate the Key for the item.
  * @param $item
  */
 protected static function createKeyForItem($item)
 {
     $path = new Google_Service_Datastore_KeyPathElement();
     $path->setKind($item->getKindName());
     // Sanity check
     if ($item->key_id !== null && $item->key_name !== null) {
         throw new UnexpectedValueException('Only one of key_id or key_name should be set.');
     }
     if ($item->key_id !== null) {
         $path->setId($item->key_id);
     } else {
         if ($item->key_name !== null) {
             $path->setName($item->key_name);
         }
     }
     $key = DatastoreService::getInstance()->createKey();
     $key->setPath([$path]);
     return $key;
 }
 protected function createKey($item)
 {
     $path = new \Google_Service_Datastore_KeyPathElement();
     $path->setKind($item->getKindName());
     // Sanity check
     if (!empty($item->keyId) && !empty($item->keyName)) {
         throw new \UnexpectedValueException('Only one of key_id or key_name should be set.');
     }
     if (!empty($item->keyId)) {
         $path->setId($item->keyId);
     } else {
         if (!empty($item->keyName)) {
             $path->setName($item->keyName);
         }
     }
     $key = Service::getInstance()->createKey();
     $key->setPath([$path]);
     return $key;
 }
 /**
  * Create a Key Path Element from array
  *
  * @param array $arr_kpe
  * @return \Google_Service_Datastore_KeyPathElement
  */
 protected function createKeyPathElement(array $arr_kpe)
 {
     $obj_element = new \Google_Service_Datastore_KeyPathElement();
     $obj_element->setKind($arr_kpe['kind']);
     isset($arr_kpe['id']) && $obj_element->setId($arr_kpe['id']);
     isset($arr_kpe['name']) && $obj_element->setName($arr_kpe['name']);
     return $obj_element;
 }
 public function build()
 {
     $missing = [];
     if ($this->kind === null) {
         $missing[] = '$kind';
     }
     // Incomplete paths don't actually need a id or name
     // if ($this->id === null && $this->name === null) $missing[] = '$id or $name';
     if (!empty($missing)) {
         throw new MissingFieldsException(self::class, $missing);
     }
     $path = new \Google_Service_Datastore_KeyPathElement();
     $path->setKind($this->kind);
     if ($this->id !== null) {
         $path->setId($this->id);
     } else {
         if ($this->name !== null) {
             $path->setName($this->name);
         }
     }
     return $path;
 }