Created
December 17, 2018 11:15
-
-
Save xeebeast/4882f86da91272e7c5fc65dd1c2f3a5f to your computer and use it in GitHub Desktop.
Google Cloud Storage Service Provier File For Lumen Projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Google\Cloud\Storage\StorageClient; | |
use Illuminate\Filesystem\FilesystemManager; | |
use Illuminate\Support\ServiceProvider; | |
use League\Flysystem\Filesystem; | |
use App\Adapters\GoogleStorageAdapter; | |
class GoogleCloudStorageServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Perform post-registration booting of services. | |
*/ | |
public function boot() | |
{ | |
$factory = $this->app->make( 'filesystem' ); | |
/* @var FilesystemManager $factory */ | |
$factory->extend( 'gcs', function ( $app, $config ) { | |
$storageClient = new StorageClient( [ | |
'projectId' => $config['project_id'], | |
'keyFilePath' => array_get( $config, 'key_file' ), | |
] ); | |
$bucket = $storageClient->bucket( $config['bucket'] ); | |
$pathPrefix = array_get( $config, 'path_prefix' ); | |
$storageApiUri = array_get( $config, 'storage_api_uri' ); | |
$adapter = new GoogleStorageAdapter( $storageClient, $bucket, $pathPrefix, $storageApiUri ); | |
return new Filesystem( $adapter ); | |
} ); | |
} | |
/** | |
* Register bindings in the container. | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment