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
Exemplo n.º 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;
 }
Exemplo n.º 2
0
 public function testStateIncomplete()
 {
     $key = new Key('foo', ['path' => [['kind' => 'foo']]]);
     $this->assertEquals($key->state(), key::STATE_INCOMPLETE);
 }