#Firebase Symfony2 Bundle
A Symfony2 Bundle for the Firebase PHP client.
Execute the following from the project root directory
composer require kreait/firebase-bundle
Then, enable the bundle by adding the following line in the `app/AppKernel.php file of your project:
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Kreait\FirebaseBundle\KreaitFirebaseBundle(),
);
// ...
}
}
Add the following to app/config/config.yml
kreait_firebase:
connections:
main:
host: prefix-suffix-1234.firebaseio.com
Setup complete!
Following configuration
kreait_firebase:
connections:
main:
scheme: https
host: prefix-suffix-1234.firebaseio.com
secret: <your firebase secret>
references:
users: data/users
images: data/images
will automagically register the following services
- kreait_firebase.connection.main (instance of Kreait\Firebase\Firebase)
- kreait_firebase.reference.users (instance of Kreait\Firebase\Reference)
- kreait_firebase.reference.images (instance of Kreait\Firebase\Reference)
Please see https://github.com/kreait/firebase-php#documentation for the full documentation
$firebase = $this->container->get('kreait_firebase.connection.main');
$users = $this->container->get('kreait_firebase.reference.users');
To use authentication, you have to include the firebase token generator into your project
composer require firebase/token-generator
You also need to set the Firebase secret in your configuration.
Then, in your code, you can authenticate a request like this:
$firebase = $this->container->get('kreait_firebase.connection.main');
$tokenGenerator = $firebase->getConfiguration()->getAuthTokenGenerator();
$adminToken = $tokenGenerator->createAdminToken();
$firebase->setAuthToken($adminToken);
This procedure is quite cumbersome at the moment, but will be made more conveniant in an upcoming release.