protected function createKey($id = null) { $key = new \Google_Service_Datastore_Key(['path' => [['kind' => 'Book']]]); // If we have an ID, set it in the path if ($id) { $key->getPath()[0]->setId($id); } return $key; }
/** * @param \Google_Service_Datastore_Key $key * @return \Google_Service_Datastore_KeyPathElement */ public static function getLastPath($key) { $path = $key->getPath(); return $path[count($path) - 1]; }
/** * @param \Google_Service_Datastore_Key $key * @return Builder */ public static function fromKey($key) { $keyBuilder = new self(); $keyBuilder->parent = $key->getPath(); /** @var \Google_Service_Datastore_KeyPathElement $latestPath */ $latestPath = array_pop($keyBuilder->parent); $keyBuilder->kind = $latestPath->getKind(); $keyBuilder->id = $latestPath->getId(); $keyBuilder->name = $latestPath->getName(); return $keyBuilder; }