Google\Cloud\Datastore\Key::state PHP Method

state() public method

Use Key::STATE_NAMED and Key::STATE_INCOMPLETE to check value. Example: An incomplete key does not have an ID on its last path element. $key = $datastore->key('parent', 1234) ->pathElement('child'); if ($key->state() === Key::STATE_INCOMPLETE) { echo 'Key is incomplete!'; } A named key has a kind and an identifier on each path element. $key = $datastore->key('parent', 1234) ->pathElement('child', 4321); if ($key->state() === Key::STATE_NAMED) { echo 'Key is named!'; }
public state ( ) : boolean
return boolean
    public function state()
    {
        $end = $this->pathEnd();
        return isset($end['id']) || isset($end['name']) ? self::STATE_NAMED : self::STATE_INCOMPLETE;
    }

Usage Example

コード例 #1
0
 /**
  * Use another Key's path as the current Key's ancestor
  *
  * Given key path will be prepended to any path elements on the current key.
  *
  * Example:
  * ```
  * $parent = $datastore->key('Person', 'Dad');
  * $key->ancestorKey($parent);
  * ```
  *
  * @param Key $key The ancestor Key.
  * @return Key
  * @throws InvalidArgumentException
  */
 public function ancestorKey(Key $key)
 {
     if ($key->state() !== self::STATE_NAMED) {
         throw new InvalidArgumentException('Cannot use an incomplete key as an ancestor');
     }
     $path = $key->path();
     $this->path = array_merge($path, $this->path);
     return $this;
 }
All Usage Examples Of Google\Cloud\Datastore\Key::state