function createKeyForTestItem() { $path = new Google_Service_Datastore_KeyPathElement(); $path->setKind("URLLinks"); $key = new Google_Service_Datastore_Key(); $key->setPath([$path]); return $key; }
function createKeyForTestItem() { $path = new Google_Service_Datastore_KeyPathElement(); $path->setKind("testkind"); $path->setName("testkeyname"); $key = DatastoreService::getInstance()->createKey(); $key->setPath([$path]); return $key; }
/** * Fetch 1-many Entities, using the Key parts provided * * @param array $arr_key_parts * @param $str_setter * @return mixed */ protected function fetchByKeyPart(array $arr_key_parts, $str_setter) { $arr_keys = []; foreach ($arr_key_parts as $str_key_part) { $obj_key = new \Google_Service_Datastore_Key(); $obj_element = new \Google_Service_Datastore_KeyPathElement(); $obj_element->setKind($this->obj_schema->getKind()); $obj_element->{$str_setter}($str_key_part); $obj_key->setPath([$obj_element]); $arr_keys[] = $obj_key; } // Build, run & map the request return $this->fetchByKeys($arr_keys); }
/** * Fetches a unique key from Datastore */ public function createUniqueKeyRequest() { // retrieve a unique ID from datastore $path = new \Google_Service_Datastore_KeyPathElement(); $path->setKind(self::KIND); $key = new \Google_Service_Datastore_Key(); $key->setPath([$path]); $idRequest = new \Google_Service_Datastore_AllocateIdsRequest(); $idRequest->setKeys([$key]); return $idRequest; }
/** * 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; }
/** * @param \Google_Service_Datastore_Key|\Google_Service_Datastore_KeyPathElement|Path\Builder|Builder $parentKey_or_parentPath * @return $this * @throws ParameterException */ public function withParent($parentKey_or_parentPath) { if ($parentKey_or_parentPath instanceof Builder) { $this->parent = $parentKey_or_parentPath->getPath(); } else { if ($parentKey_or_parentPath instanceof Path\Builder) { $this->parent = $parentKey_or_parentPath->build(); } else { if ($parentKey_or_parentPath instanceof \Google_Service_Datastore_Key) { $this->parent = $parentKey_or_parentPath->getPath(); } else { if ($parentKey_or_parentPath instanceof \Google_Service_Datastore_KeyPathElement) { $this->parent = $parentKey_or_parentPath; } else { throw new ParameterException(__METHOD__, [\Google_Service_Datastore_Key::class, \Google_Service_Datastore_KeyPathElement::class, Path\Builder::class, Builder::class]); } } } } return $this; }
/** * 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; }
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; }
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; }