我正在尝试配置一个KnpGaufretteBundle用于Google Cloud Storage
存储我的文件。这是配置:
## definition of the GCS service
app.google_cloud_storage.service:
class: \Google_Service_Storage
factory_class: Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GoogleCloudStorageAdapterFactory
factory_method: 'create'
arguments:
- "123@developer.gserviceaccount.com"
- "http://localhost/file.p12"
- "pwd"
## config of knp_gaufrette
knp_gaufrette:
stream_wrapper: ~
adapters:
gcs_minn_images:
google_cloud_storage:
service_id: 'app.google_cloud_storage.service'
bucket_name: 'minn-images'
filesystems:
gcs_minn_images_fs:
adapter: gcs_minn_images
我得到的错误信息是:
GoogleCloudStorageAdapterFactory.php 第 16 行中的 ContextErrorException:可捕获的致命错误:传递给 Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GoogleCloudStorageAdapterFactory::create() 的参数 1 必须是 Symfony\Component\DependencyInjection\ContainerBuilder 的实例,给定字符串,调用/home/amine/NetBeansProjects/tuto/app/cache/dev/appDevDebugProjectContainer.php 在第 724 行并定义
根据报错信息,我给了一个字符串,而不是ContainerBuilder。伟大的!让我们将 ContainerBuilder 添加到参数中,如下所示:
## definition of the GCS service
app.google_cloud_storage.service:
class: \Google_Service_Storage
factory_class: Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GoogleCloudStorageAdapterFactory
factory_method: 'create'
arguments:
- @service_container
- "123@developer.gserviceaccount.com"
- "http://localhost/file.p12"
- "pwd"
结果又是一个错误:
可捕获的致命错误:传递给 Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GoogleCloudStorageAdapterFactory::create() 的参数 1 必须是 Symfony\Component\DependencyInjection\ContainerBuilder 的实例,给定 appDevDebugProjectContainer 的实例,在 /home/amine/NetBeansProjects 中调用/tuto/app/cache/dev/appDevDebugProjectContainer.php 在第 724 行并定义
所以现在,错误告诉我我提供了一个 appDevDebugProjectContainer 的实例而不是 ContainerBuilder!
好的,让我们看一下/home/amine/NetBeansProjects/tuto/app/cache/dev/appDevDebugProjectContainer.php
第 724 行...
class appDevDebugProjectContainer extends Container{
// ...
/**
* Gets the 'app.google_cloud_storage.service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \Google_Service_Storage A Google_Service_Storage instance.
*/
protected function getApp_GoogleCloudStorage_ServiceService()
{
return $this->services['app.google_cloud_storage.service'] =\Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\GoogleCloudStorageAdapterFactory::create($this, '123@developer.gserviceaccount.com', 'http://localhost/file.p12', 'pwd');
}
我真的迷路了......那么,有没有配置谷歌云存储的完整示例?