2017-06-29 52 views
1

我已經創建了自定義文件系統服務提供程序來設置我的谷歌雲存儲。我有多個桶,所以我在filesystems.php中創建了多個磁盤。但由於所有這些存儲桶都使用類似的設置,我想使用單個服務提供商。我們能做到嗎?自定義文件系統提供程序服務多個磁盤

ServicePrivider引導()

Storage::extend('gcs_images_1', function ($app, $config) { 
    $client = new StorageClient([ 
     'projectId' => $config['project_id'], 
     'keyFilePath' => storage_path($config['key_file']) 
    ]); 

    $bucket = $client->bucket($config['bucket']); 

    $pathPrefix = array_get($config, 'path_prefix'); 

    $storageApiUri = array_get($config, 'storage_api_uri'); 

    $adapter = new GoogleStorageAdapter($client, $bucket, $pathPrefix, $storageApiUri); 

    return new Filesystem($adapter); 
}); 

配置/ filesystems.php

'gcs_images_1' => [ 
      'driver' => 'gcs_images_1', 
      'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 
      'key_file' => env('GOOGLE_CLOUD_KEY_FILE'), 
      'bucket' => 'img', 
      'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), 
      'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null) 
     ], 
     'gcs_docs_1' => [ 
      'driver' => 'gcs_docs_1', 
      'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 
      'key_file' => env('GOOGLE_CLOUD_KEY_FILE'), 
      'bucket' => 'doc', 
      'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), 
      'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null) 
     ], 

回答

1

因此,畢竟解決方案很簡單。文件系統實例

 $fileSystems = array(); 
     foreach ($this->gcsDisks as $disk) { 
      $fileSystems[] = $this->getFileSystem($disk); 
     } 
     return $fileSystems; 

但還是比較清楚的方式返回數組做,這是值得歡迎的答案