Firestore/src/SnapshotTrait.php
private function getDocumentReference(
        ConnectionInterface $connection,
        ValueMapper $mapper,
        $projectId,
        $database,
        $name
    ) {
        if ($this->isRelative($name)) {
            try {
                $name = $this->fullName($projectId, $database, $name);
            } catch (ValidationException $e) {
                // The GAPIC parser does not support special characters in paths,
                // but Firestore does. If an exception is raised by the parser,
                // we'll check for special characters. If they exist, we'll
                // manually construct a document path.
                $hasSpecialChars = preg_match('/[!@#$%^&*(),.?":{}|<>]/', $name) === 1;

                //@codeCoverageIgnoreStart
                if (!$hasSpecialChars) {
                    throw $e;
                }
                //@codeCoverageIgnoreEnd

                $base = $this->databaseName($projectId, $database);
                $name = $base .'/documents/'. $name;
            }
        }

        if (!$this->isDocument($name)) {
            throw new \InvalidArgumentException('Given path is not a valid document path.');
        }

        return new DocumentReference(
            $connection,
            $mapper,
            $this->getCollectionReference(
                $connection,
                $mapper,
                $projectId,
                $database,
                $this->parentPath($name)
            ),
            $name
        );
    }
private function getDocumentReference(
        ConnectionInterface $connection,
        ValueMapper $mapper,
        $projectId,
        $database,
        $name
    ) {
        if ($this->isRelative($name)) {
            try {
                $name = $this->fullName($projectId, $database, $name);
            } catch (ValidationException $e) {
                // The GAPIC parser does not support special characters in paths,
                // but Firestore does. If an exception is raised by the parser,
                // we'll check for special characters. If they exist, we'll
                // manually construct a document path.
                $hasSpecialChars = preg_match('/[!@#$%^&*(),.?":{}|<>]/', $name) === 1;

                //@codeCoverageIgnoreStart
                if (!$hasSpecialChars) {
                    throw $e;
                }
                //@codeCoverageIgnoreEnd

                $base = $this->databaseName($projectId, $database);
                $name = $base .'/documents/'. $name;
            }
        }

        if (!$this->isDocument($name)) {
            throw new \InvalidArgumentException('Given path is not a valid document path.');
        }

        return new DocumentReference(
            $connection,
            $mapper,
            $this->getCollectionReference(
                $connection,
                $mapper,
                $projectId,
                $database,
                $this->parentPath($name)
            ),
            $name
        );
    }
private function getDocumentReference ( ConnectionInterface $ connection , ValueMapper $ mapper , $ projectId , $ database , $ name ) { if ( $ this -> isRelative ( $ name ) ) { try { $ name = $ this -> fullName ( $ projectId , $ database , $ name ) ; } catch ( ValidationException $ e ) { // The GAPIC parser does not support special characters in paths, // but Firestore does. If an exception is raised by the parser, // we'll check for special characters. If they exist, we'll // manually construct a document path. $ hasSpecialChars = preg_match ( '/[!@#$%^&*(),.?":{}|<>]/' , $ name ) === 1 ; //@codeCoverageIgnoreStart if ( ! $ hasSpecialChars ) { throw $ e ; } //@codeCoverageIgnoreEnd $ base = $ this -> databaseName ( $ projectId , $ database ) ; $ name = $ base . '/documents/' . $ name ; } } if ( ! $ this -> isDocument ( $ name ) ) { throw new \ InvalidArgumentException ( 'Given path is not a valid document path.' ) ; } return new DocumentReference ( $ connection , $ mapper , $ this -> getCollectionReference ( $ connection , $ mapper , $ projectId , $ database , $ this -> parentPath ( $ name ) ) , $ name ) ; }
Creates a DocumentReference object.

@param ConnectionInterface $connection A connection to Cloud Firestore.
@param ValueMapper $mapper A Firestore value mapper.
@param string $projectId The current project id.
@param string $database The database id.
@param string $name The document name, in absolute form, or relative to the database.
@return DocumentReference
@throws InvalidArgumentException if an invalid path is provided.
Creates a DocumentReference object .