Google\Cloud\Datastore\Key::setLastElementIdentifier PHP 메소드

setLastElementIdentifier() 공개 메소드

This method is used internally when IDs are allocated to existing instances of a Key. It should not generally be used externally. Example: $key = $datastore->key('Person'); $key->setLastElementIdentifier('Bob', Key::TYPE_NAME);
public setLastElementIdentifier ( string $value, string $type = Key::TYPE_ID ) : void
$value string The value of the ID or Name.
$type string [optional] 'id' or 'name'. **Defaults to** `"id"`.
리턴 void
    public function setLastElementIdentifier($value, $type = Key::TYPE_ID)
    {
        $end = $this->pathEnd();
        $end[$type] = (string) $value;
        $elements = array_keys($this->path);
        $lastElement = end($elements);
        $this->path[$lastElement] = $end;
    }

Usage Example

예제 #1
0
 public function testSetLastElementIdentifierTypeName()
 {
     $key = new Key('foo', ['path' => [['kind' => 'foo', 'id' => 2], ['kind' => 'foo']]]);
     $key->setLastElementIdentifier(1, Key::TYPE_NAME);
     $this->assertEquals($key->path(), [['kind' => 'foo', 'id' => 2], ['kind' => 'foo', 'name' => 1]]);
 }