我想覆盖SonataMediaBundle的图像提供程序,但是,当我覆盖它时,当调用构造函数时,我会得到错误:
Catchable Fatal Error: Argument 8 passed to ApplicationSonataMediaBundleProviderNewImageProvider::__construct() must be an instance of ImagineImageImagineInterface, none given
这是构造函数:
/**
* @param string $name
* @param GaufretteFilesystem $filesystem
* @param SonataMediaBundleCDNCDNInterface $cdn
* @param SonataMediaBundleGeneratorGeneratorInterface $pathGenerator
* @param SonataMediaBundleThumbnailThumbnailInterface $thumbnail
* @param array $allowedExtensions
* @param array $allowedMimeTypes
* @param ImagineImageImagineInterface $adapter
* @param SonataMediaBundleMetadataMetadataBuilderInterface $metadata
*/
public function __construct($name, Filesystem $filesystem, CDNInterface $cdn, GeneratorInterface $pathGenerator, ThumbnailInterface $thumbnail, array $allowedExtensions = array(), array $allowedMimeTypes = array(), ImagineInterface $adapter, MetadataBuilderInterface $metadata = null)
{
parent::__construct($name, $filesystem, $cdn, $pathGenerator, $thumbnail, $allowedExtensions, $allowedMimeTypes, $metadata);
$this->imagineAdapter = $adapter;
}
正如您所看到的,参数8需要一个接口。现在,在我的服务中,我不会通过第八个论点:
sonata.media.provider.image:
class: %application_sonata_media.image_class%
arguments:
- [sonata.media.provider.image]
- [@sonata.media.filesystem.local]
- [@sonata.media.cdn.server]
- [@sonata.media.generator.default]
- [@sonata.media.thumbnail.format]
- [@sonata.media.buzz.browser]
- [@sonata.media.metadata.proxy]
tags:
- { name: sonata.media.provider }
calls:
- [ setTemplates, [ { helper_thumbnail: SonataMediaBundle:Provider:thumbnail.html.twig, helper_view: SonataMediaBundle:Provider:view_youtube.html.twig } ] ]
我试着用不同的方式传递它,例如(=给定的数组):
arguments:
- [sonata.media.provider.image]
- [@sonata.media.filesystem.local]
- [@sonata.media.cdn.server]
- [@sonata.media.generator.default]
- [@sonata.media.thumbnail.format]
- [@sonata.media.buzz.browser]
- [@sonata.media.metadata.proxy]
- [imagine_interface]
我甚至尝试创建一个新的服务来加载interbase:
test.imagine:
class: ImagineImageImagineInterface
sonata.media.provider.image:
class: %application_sonata_media.image_class%
arguments:
- [sonata.media.provider.image]
- [@sonata.media.filesystem.local]
- [@sonata.media.cdn.server]
- [@sonata.media.generator.default]
- [@sonata.media.thumbnail.format]
- [@sonata.media.buzz.browser]
- [@sonata.media.metadata.proxy]
- [@test.imagine]
tags:
- { name: sonata.media.provider }
calls:
- [ setTemplates, [ { helper_thumbnail: SonataMediaBundle:Provider:thumbnail.html.twig, helper_view: SonataMediaBundle:Provider:view_youtube.html.twig } ] ]
然后我得到了错误:
Cannot instantiate interface ImagineImageImagineInterface
现在我没主意了。我还能尝试什么?
Sonata基本提供程序的构造函数中有两个可选参数-$allowedExtensions和$allowedMimeTypes。
因为将数组传递给类,所以存在一个隐藏的错误,即只填充前7个参数(其中第8个参数是必需的)。
添加其他参数的方向是正确的,但它们的类型是错误的。您的最后一次修改不起作用,因为您无法从接口提供服务-错误告诉相同的]
试试这个(用合适的图像适配器):
sonata.media.provider.image:
class: ServerBaseBundleProviderImageProvider
arguments:
- sonata.media.provider.image
- @sonata.media.filesystem.local
- @sonata.media.cdn.server
- @sonata.media.generator.default
- @sonata.media.thumbnail.format
- []
- []
- @sonata.media.adapter.image.gd
- @sonata.media.metadata.proxy
tags:
- { name: sonata.media.provider }
calls:
- [ setTemplates, [ { helper_thumbnail: SonataMediaBundle:Provider:thumbnail.html.twig, helper_view: SonataMediaBundle:Provider:view_youtube.html.twig } ] ]
sonata中有一些已经实现的适配器:
- sona.media.adapter.image.gd
- 奏鸣曲.media.adapter.image.imagik
- 奏鸣曲.media.adapter.image.gmagik
你也可以看看这个。它描述了覆盖服务的方式。我认为这是一种更明确的方法。例如,为了覆盖生成器类,我这样使用它:
myown.media.provider.file:
class: ApplicationMediaBundleProviderDemoProvider
parent: sonata.media.provider.file
tags:
- { name: sonata.media.provider }
calls:
- [setGenerator, ["@my_own_generator"]]