• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flysystem Adapter for Google Cloud Storage

flysystem-google-cloud-storage

A Google Cloud Storage adapter for flysystem - a PHP filesystem abstraction.

Author Build Status StyleCI Software License Packagist Version Total Downloads

Installation

composer require superbalist/flysystem-google-storage

Integrations

Want to get started quickly? Check out some of these integrations:

Usage

use Google\Cloud\Storage\StorageClient;
use League\Flysystem\Filesystem;
use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;

/**
 * The credentials will be auto-loaded by the Google Cloud Client.
 *
 * 1. The client will first look at the GOOGLE_APPLICATION_CREDENTIALS env var.
 *    You can use ```putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');``` to set the location of your credentials file.
 *
 * 2. The client will look for the credentials file at the following paths:
 * - windows: %APPDATA%/gcloud/application_default_credentials.json
 * - others: $HOME/.config/gcloud/application_default_credentials.json
 *
 * If running in Google App Engine, the built-in service account associated with the application will be used.
 * If running in Google Compute Engine, the built-in service account associated with the virtual machine instance will be used.
 */

$storageClient = new StorageClient([
    'projectId' => 'your-project-id',
]);
$bucket = $storageClient->bucket('your-bucket-name');

$adapter = new GoogleStorageAdapter($storageClient, $bucket);

$filesystem = new Filesystem($adapter);

/**
 * The credentials are manually specified by passing in a keyFilePath.
 */

$storageClient = new StorageClient([
    'projectId' => 'your-project-id',
    'keyFilePath' => '/path/to/service-account.json',
]);
$bucket = $storageClient->bucket('your-bucket-name');

$adapter = new GoogleStorageAdapter($storageClient, $bucket);

$filesystem = new Filesystem($adapter);

// write a file
$filesystem->write('path/to/file.txt', 'contents');

// update a file
$filesystem->update('path/to/file.txt', 'new contents');

// read a file
$contents = $filesystem->read('path/to/file.txt');

// check if a file exists
$exists = $filesystem->has('path/to/file.txt');

// delete a file
$filesystem->delete('path/to/file.txt');

// rename a file
$filesystem->rename('filename.txt', 'newname.txt');

// copy a file
$filesystem->copy('filename.txt', 'duplicate.txt');

// delete a directory
$filesystem->deleteDir('path/to/directory');

// see http://flysystem.thephpleague.com/api/ for full list of available functionality

Google Storage specifics

When using a custom storage uri the bucket name will not prepended to the file path.

$storageClient = new StorageClient([
    'projectId' => 'your-project-id',
]);
$bucket = $storageClient->bucket('your-bucket-name');
$adapter = new GoogleStorageAdapter($storageClient, $bucket);

// uri defaults to "https://storage.googleapis.com"
$filesystem = new Filesystem($adapter);
$filesystem->getUrl('path/to/file.txt');
// "https://storage.googleapis.com/your-bucket-name/path/to/file.txt"

// set custom storage uri
$adapter->setStorageApiUri('http://example.com');
$filesystem = new Filesystem($adapter);
$filesystem->getUrl('path/to/file.txt');
// "http://example.com/path/to/file.txt"

// You can also prefix the file path if needed.
$adapter->setStorageApiUri('http://example.com');
$adapter->setPathPrefix('extra-folder/another-folder/');
$filesystem = new Filesystem($adapter);
$filesystem->getUrl('path/to/file.txt');
// "http://example.com/extra-folder/another-folder/path/to/file.txt"

More Repositories

1

laravel-google-cloud-storage

A Google Cloud Storage filesystem for Laravel
PHP
508
star
2

laravel-prometheus-exporter

A prometheus exporter for Laravel
PHP
155
star
3

laravel-pubsub

A Pub-Sub abstraction for Laravel
PHP
68
star
4

php-pubsub

A PHP abstraction for the pub-sub pattern
PHP
45
star
5

php-pubsub-kafka

A Kafka adapter for the php-pubsub package
PHP
30
star
6

php-pubsub-redis

A Redis adapter for the php-pubsub package
PHP
24
star
7

monolog-google-cloud-json-formatter

A Monolog extension for formatting log entries for Google Cloud Logging
PHP
15
star
8

php-pubsub-google-cloud

A Google Cloud adapter for the php-pubsub package
PHP
12
star
9

php-money

A money and currency library for handling arbitrary-precision arithmetic
PHP
11
star
10

laravel-zendesk

A Laravel Zendesk library for integrating with the Zendesk API
PHP
9
star
11

php-event-pubsub

An event protocol and implementation over pub/sub
PHP
8
star
12

python-pubsub

Python
6
star
13

laravel-event-pubsub

An event protocol and implementation over pub/sub for Laravel
PHP
6
star
14

laravel4-storage

A filesystem abstraction library for Laravel 4
PHP
4
star
15

laravel-ajax-redirector

A Laravel library for handling AJAX redirects
PHP
3
star
16

js-pubsub

A JS abstraction for the pub-sub pattern
JavaScript
3
star
17

js-pubsub-google-cloud

A Google Cloud adapter for the js-pubsub package
JavaScript
2
star
18

laravel-lusitanian-oauth-session-store

A Laravel session storage interface for the lusitanian/oauth library
PHP
2
star
19

js-pubsub-redis

A Redis adapter for the js-pubsub package
JavaScript
2
star
20

js-event-pubsub

An event protocol and implementation over pub/sub
JavaScript
2
star
21

js-pubsub-http

An HTTP adapter for the js-pubsub package
JavaScript
2
star
22

laravel-appboy

A Laravel library for sending push notifications via the Appboy API
PHP
1
star
23

simple-sms-panacea-mobile

An adapter for the simple-sms Laravel library for sending SMSs via the Panacea Mobile API
PHP
1
star
24

laravel4-event-pubsub

An event protocol and implementation over pub/sub for Laravel 4
PHP
1
star
25

panaceaapi

The Panacea Mobile PHP class for easy deployment and integration
PHP
1
star
26

php-panaceamobile

An API client for sending SMSs via the Panacea Mobile API
PHP
1
star
27

spreeza-dust-recursive-loader

Webpack loader for processing dust templates recursively.
JavaScript
1
star
28

laravel4-psr6-cache-bridge

A PSR6 cache implementation for Laravel 4
PHP
1
star
29

js-pubsub-manager

A manager & factory for the js-pubsub package
JavaScript
1
star
30

php-pubsub-http

An HTTP adapter for the php-pubsub package
PHP
1
star
31

lint-review-images

Images built for use with lint-review
Dockerfile
1
star
32

laravel4-pubsub

A Pub-Sub abstraction for Laravel 4
PHP
1
star
33

php-appboy

A PHP client for sending push notifications via the Appboy API
PHP
1
star
34

js-pubsub-rest-proxy

An HTTP server which acts as a gateway for publishing messages via a js-pubsub adapter
JavaScript
1
star