PHP与Firebase的连接如何工作? [英] How does PHP connection to firebase work?
问题描述
如果您有时间阅读 firebase-php 文档,您可以在这里看到使用助手库连接到 firebase 。但不幸的是,我认为连接只能通过phpunit来建立,换句话说,输出只能在终端中看到。因为当你在浏览器中运行php页面时,它会返回致命错误 。有谁知道如何使用助手库连接到 firebase 数据而不使用 phpunit ?提前感谢您。
使用lib非常简单,只需查看测试的源代码即可。 / b>
有两种测试:
- 一个真正的功能测试,它使用cURL请求到服务器,因此在测试过程中很慢with PHPUnit
- 嘲笑功能测试(存根),它模拟与服务器的连接,以及在测试期间更快的响应
现在,为了使用firebase-php,你只需要做和真实功能测试一样的事情。包含lib,使用登录凭据准备连接对象,然后调用所需的方法。 界面描述了您可以在firebaseLib类 - 这段代码应该让你开始: 如果您通过 然后,只需使用 如何获得授权令牌 If you have the time to read the firebase-php documentation, you can see there how to use the helper library to "connect" to firebase. But unfortunately, I think that the connection could only be established by phpunit, in other words, output can only be seen in the terminal. Since when you run the php pages in your browser, it will return fatal errors. Does anyone know how to use the helper library to connect to the firebase data without using phpunit? Thank you in advance. Using the lib is very easy, when you just look at the source code of the tests. There are two kinds of tests: Now, in order to use firebase-php, you would simply do the same things as in the real functionality test. Include the lib, prepare the connection object with login credentials and then call the method you want. The interface describes, which methods you can expect in the firebaseLib class -
or just look at the lib source itself. This piece of code should get you started:
If you fetch the library via Then simply require Composer's Autoloader with How to get the auth token 这篇关于PHP与Firebase的连接如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
或只查看 lib源代码本身
require'/path/to/libs/firebase-php/firebaseLib.php';
$ url ='...';
$ token ='...';
$ firebase = new Firebase($ url,$ token);
$ firebase-> get('something / from / somewhere');
composer
,你也可以声明自动加载的类图。
{
autoload:{
classmap :[vendor / ktamas77 / firebase-php / firebaseLib.php]
}
}
需要供应商/ autoload.php;
和新版Firebase
的Composer自动加载器自动加载类。
require '/path/to/libs/firebase-php/firebaseLib.php';
$url = '...';
$token = '...';
$firebase = new Firebase($url, $token);
$firebase->get('something/from/somewhere');
composer
, you might declare an autoloading classmap, too. The author hasn't done this, yet.{
"autoload": {
"classmap": ["vendor/ktamas77/firebase-php/firebaseLib.php"]
}
}
require "vendor/autoload.php";
and new Firebase
to autoload the class.