Firestore/src/DocumentSnapshot.php
public function get($fieldPath)
    {
        $res = null;

        if (is_string($fieldPath)) {
            $parts = explode('.', $fieldPath);
        } elseif ($fieldPath instanceof FieldPath) {
            $parts = $fieldPath->path();
        } else {
            throw new \InvalidArgumentException('Given path was not a string or instance of FieldPath.');
        }

        $len = count($parts);

        $fields = $this->data;
        foreach ($parts as $idx => $part) {
            if ($idx === $len-1 && isset($fields[$part])) {
                $res = $fields[$part];
                break;
            } else {
                if (!isset($fields[$part])) {
                    throw new \InvalidArgumentException(sprintf(
                        'Field path `%s` does not exist.',
                        $fieldPath
                    ));
                }

                $fields = $fields[$part];
            }
        }

        return $res;
    }
public function get($fieldPath)
    {
        $res = null;

        if (is_string($fieldPath)) {
            $parts = explode('.', $fieldPath);
        } elseif ($fieldPath instanceof FieldPath) {
            $parts = $fieldPath->path();
        } else {
            throw new \InvalidArgumentException('Given path was not a string or instance of FieldPath.');
        }

        $len = count($parts);

        $fields = $this->data;
        foreach ($parts as $idx => $part) {
            if ($idx === $len-1 && isset($fields[$part])) {
                $res = $fields[$part];
                break;
            } else {
                if (!isset($fields[$part])) {
                    throw new \InvalidArgumentException(sprintf(
                        'Field path `%s` does not exist.',
                        $fieldPath
                    ));
                }

                $fields = $fields[$part];
            }
        }

        return $res;
    }
public function get ( $ fieldPath ) { $ res = null ; if ( is_string ( $ fieldPath ) ) { $ parts = explode ( '.' , $ fieldPath ) ; } elseif ( $ fieldPath instanceof FieldPath ) { $ parts = $ fieldPath -> path ( ) ; } else { throw new \ InvalidArgumentException ( 'Given path was not a string or instance of FieldPath.' ) ; } $ len = count ( $ parts ) ; $ fields = $ this -> data ; foreach ( $ parts as $ idx => $ part ) { if ( $ idx === $ len - 1 && isset ( $ fields [ $ part ] ) ) { $ res = $ fields [ $ part ] ; break ; } else { if ( ! isset ( $ fields [ $ part ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Field path `%s` does not exist.' , $ fieldPath ) ) ; } $ fields = $ fields [ $ part ] ; } } return $ res ; }
Get a field by field path.

A field path is a string containing the path to a specific field, at the
top level or nested, delimited by `.`. For instance, the value `hello` in
the structured field `{ "foo" : { "bar" : "hello" }}` would be accessible
using a field path of `foo.bar`.

Example:
```
$value = $snapshot->get('wallet.cryptoCurrency.bitcoin');
```

```
// Field names containing dots or symbols can be targeted using a FieldPath instance:
use Google\Cloud\Firestore\FieldPath;

$value = $snapshot->get(new FieldPath(['wallet', 'cryptoCurrency', 'my.coin']));
```

@param string|FieldPath $fieldPath The field path to return.
@return mixed
@throws \InvalidArgumentException if the field path does not exist.
Get a field by field path .