PHP调用私有方法Kreait \ Firebase \ ServiceAccount :: fromJsonFile()错误

时间:2020-06-15 23:36:10

标签: php firebase

我似乎对Kreait库存在问题,因为它在PHP中而不是JS中使用Firebase。

运行此代码,它将返回此错误

Fatal error: Uncaught Error: Call to private method Kreait\Firebase\ServiceAccount::fromJsonFile() from context '' in /Users//Documents/GitHub/phpvers/index.php:15
Stack trace:
#0 {main}
  thrown in /Users//Documents/GitHub/phpvers/index.php on line 15

看过类似的问题,但似乎与我的问题无关。

完整代码如下:

<?php
/**
 * Created by PhpStorm.
 * User: SYSTEM
 * Date: 18-Jul-18
 * Time: 22:15
 */

require_once './vendor/autoload.php';

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;


$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/shit/file.json');

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

$database = $firebase->getDatabase();

die(print_r($database)); 

我已经复制并粘贴了此代码,以尝试查看是否是我的代码不起作用,但似乎仍然有问题。

GitHub存储库位于此处:https://github.com/arthimann/firebase-php/blob/master/index.php

我正在使用Firebase SDK,该文档位于此处:https://firebase-php.readthedocs.io/

最多,谢谢

1 个答案:

答案 0 :(得分:6)

通过对该问题进行更多的研究来解决此问题!总是这样:P

我更改了此代码:

if let getalarm = getReminderDetail.alarms?.first {
   if getalarm.proximity == .enter {locationmode = "enter"}
   if getalarm.proximity == .leave {locationmode = "leave"}
}
reminderReminderIden.append(reminderGetdetail(
   re_location_title: getReminderDetail.alarms?.first?.structuredLocation?.title ?? "",
   re_location_mode: locationmode,
   re_location_latitude: getReminderDetail.alarms?.first?.structuredLocation?.geoLocation?.coordinate.latitude ?? 0.0,
   re_location_longitude: getReminderDetail.alarms?.first?.structuredLocation?.geoLocation?.coordinate.longitude ?? 0.0,
   re_location_radius: getReminderDetail.alarms?.first?.structuredLocation?.radius ?? 0.0))
}

到以下内容:

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/shit/file.json');

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

$database = $firebase->getDatabase();