首页 > 解决方案 > 尝试检索数据时未找到 google Firestore 的 php sdk 抛出错误“Google\Firestore\V1beta1\StructuredQuery\CollectionSelector”

问题描述

当我尝试从集合中提取数据时,我已经安装了 google fire 商店“google/cloud-firestore”的 php sdk,它会引发此错误

未捕获的错误:在 vendor/google/gax/src/Serializer.php:276 中找不到类“Google\Firestore\V1beta1\StructuredQuery\CollectionSelector”

我的实际代码是

// custom logic, just pulling the config array this part is working fine   
$option = $ins->integration('firebase')->get_options();
       
$firestore = new FirestoreClient($option);
$chats =  $firestore->collection('chats'); // this is where the error occurred 
    

完整的错误跟踪是

Fatal error:  Uncaught Error: Class 'Google\Firestore\V1beta1\StructuredQuery\CollectionSelector' not found in /vendor/google/gax/src/Serializer.php:276
Stack trace:
#0 /vendor/google/gax/src/Serializer.php(314): Google\GAX\Serializer->decodeElement(Object(Google\Protobuf\FieldDescriptor), Array)
#1 /vendor/google/gax/src/Serializer.php(103): Google\GAX\Serializer->decodeMessageImpl(Object(Google\Firestore\V1beta1\StructuredQuery), Object(Google\Protobuf\Descriptor), Array)
#2 /vendor/google/cloud-firestore/Connection/Grpc.php(168): Google\GAX\Serializer->decodeMessage(Object(Google\Firestore\V1beta1\StructuredQuery), Array)
#3 /vendor/google/cloud-firestore/Query.php(166): Google\Cloud\Firestore\Connection\Grpc-> in /vendor/google/gax/src/Serializer.php on line 276

在 Serializer 类中,引发错误的函数是这个

private function decodeElement(FieldDescriptor $field, $data)
    {
        switch ($field->getType()) {
            case GPBType::MESSAGE:
                if ($data instanceof \Google\Protobuf\Internal\Message) {
                    return $data;
                }
                $messageType = $field->getMessageType();
                $klass = $messageType->getClass();
                
                $msg = new $klass();   // this class is not found 'Google\Firestore\V1beta1\StructuredQuery\CollectionSelector'

                return $this->decodeMessageImpl($msg, $messageType, $data);
            default:
                return $data;
        }
    }

我转储了 $klass 和 $data 变量,这是输出

string(59) "Google\Firestore\V1beta1\StructuredQuery\CollectionSelector"
array(1) {
  ["collectionId"]=>
  string(5) "chats"
}

标签: phpfirebasegoogle-cloud-firestore

解决方案


这真的很奇怪,但我刚刚删除了供应商目录,并使用 --no-cache 标志重新运行作曲家,现在它可以工作了


推荐阅读