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

ancestorKey() public method

Given key path will be prepended to any path elements on the current key. Example: $parent = $datastore->key('Person', 'Dad'); $key->ancestorKey($parent);
public ancestorKey ( Key $key ) : Key
$key Key The ancestor Key.
return Key
    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;
    }

Usage Example

コード例 #1
0
ファイル: KeyTest.php プロジェクト: Radiergummi/anacronism
 /**
  * @expectedException InvalidArgumentException
  */
 public function testAncestorKeyIncompletePath()
 {
     $ancestor = $this->prophesize(Key::class);
     $ancestor->state()->willReturn(Key::STATE_INCOMPLETE);
     $key = new Key('foo');
     $key->ancestorKey($ancestor->reveal());
 }