PHP code example of galihlprakoso / flysystem-firebase-storage

1. Go to this page and download the library: Download galihlprakoso/flysystem-firebase-storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

galihlprakoso / flysystem-firebase-storage example snippets


use galihlprakoso\Adapters\FirebaseStorageAdapter;
use Kreait\Firebase\Factory;

$factory = (new Factory())->withServiceAccount('<path to your service account json file>');
$storageClient = $factory->createStorage();

$adapter = new FirebaseStorageAdapter($storageClient, '<bucket name>');

[
  'disks' => [
    //... another configuration    
    'firebase-storage' => [
        'driver' => 'firebase-storage',
        'service_account_json_name' => env('FIREBASE_STORAGE_SERVICE_ACCOUNT_JSON_NAME'),
        'bucket_name' => env('FIREBASE_STORAGE_BUCKET_NAME'),
    ],
  ]
]

Storage::extend('firebase-storage', function (Application $app, array $config) {
    $factory = (new Factory())->withServiceAccount(base_path('/' . $config['service_account_json_name']));
    $storageClient = $factory->createStorage();

    $adapter = new FirebaseStorageAdapter($storageClient, $config['bucket_name']);

    return new FilesystemAdapter(
        new Filesystem($adapter, $config),
        $adapter,
        $config
    );
});