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

pathElement() 공개 메소드

If the previous pathElement is incomplete (has no name or ID specified), an InvalidArgumentException will be thrown. Once an incomplete pathElement is given, the key cannot be extended any further. Example: $key->pathElement('Person', 'Jane'); In cases where the identifier type is ambiguous, you can choose the type to be used. $key->pathElement('Robots', '1337', [ 'identifierType' => Key::TYPE_NAME ]);
또한 보기: https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement PathElement
public pathElement ( string $kind, string | integer $identifier = null, array $options = [] ) : Key
$kind string The kind.
$identifier string | integer [optional] The name or ID of the object.
$options array { Configuration Options @type string $identifierType [optional] If omitted, the type will be determined internally. Setting this to either `Key::TYPE_ID` or `Key::TYPE_NAME` will force the pathElement identifier type. }
리턴 Key
    public function pathElement($kind, $identifier = null, array $options = [])
    {
        $options += ['identifierType' => null];
        if (!empty($this->path) && $this->state() !== Key::STATE_NAMED) {
            throw new InvalidArgumentException('Cannot add pathElement because the previous element is missing an id or name');
        }
        $pathElement = $this->normalizeElement($kind, $identifier, $options['identifierType']);
        $this->path[] = $pathElement;
        return $this;
    }

Usage Example

예제 #1
0
 /**
  * Create a single Key instance
  *
  * @see https://cloud.google.com/datastore/reference/rest/v1/Key Key
  * @see https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement PathElement
  *
  * @param string $kind The kind.
  * @param string|int $identifier [optional] The ID or name.
  * @param array $options [optional] {
  *     Configuration Options
  *
  *     @type string $identifierType If omitted, type will be determined
  *           internally. In cases where any ambiguity can be expected (i.e.
  *           if you want to create keys with `name` but your values may
  *           pass PHP's `is_numeric()` check), this value may be
  *           explicitly set using `Key::TYPE_ID` or `Key::TYPE_NAME`.
  * }
  * @return Key
  */
 public function key($kind, $identifier = null, array $options = [])
 {
     $options += ['namespaceId' => $this->namespaceId];
     $key = new Key($this->projectId, $options);
     $key->pathElement($kind, $identifier, $options);
     return $key;
 }
All Usage Examples Of Google\Cloud\Datastore\Key::pathElement