4

介绍

我正在尝试Syfony 4.1使用OneUpUploaderBundleand OneUpFlysystemBundle

问题

我的配置运行良好,Symfony 3.4Symfony 4.1 我无法弄清楚如何在控制器的代码中注入 OnUploaderBundle。

配置

OneUploader.yaml

oneup_uploader:
    mappings:
        gallery:
            storage:
                type: flysystem
                filesystem: oneup_flysystem.gallery_filesystem

            frontend: blueimp
            enable_progress: true
            namer: app.upload_unique_namer

            max_size: 104857600

OneUpFlysystem.yaml

oneup_flysystem:
    adapters:
        my_adapter:
            local:
                directory: '%kernel.root_dir%/../data'

    filesystems:
        default_filesystem:
            adapter: my_adapter
            alias: League\Flysystem\Filesystem

services.yaml 的一部分

app.upload_listener:
    class: App\EventListener\UploadListener
    arguments: ['@doctrine.orm.entity_manager', '@session', '@service_container']
    tags:
        - { name: kernel.event_listener, event: oneup_uploader.pre_upload.gallery, method: onUpload }
        - { name: kernel.event_listener, event: oneup_uploader.post_upload.gallery, method: onPostUpload }

app.allowed_mime_type_listener:
    class: App\EventListener\AllowedMimeTypeValidationListener
    arguments: ['@service_container']
    tags:
        - { name: kernel.event_listener, event: oneup_uploader.validation.gallery, method: onValidate }

app.upload_unique_namer:
    class: App\Uploader\Naming\UploadUniqueNamer
    arguments: ['@service_container']
    public: true

// SEE sections ERROR 1 and ERROR 2
// FOR relevant config details
oneup_flysystem.gallery_filesystem:
    class: [...]
    public: true

代码

// previously, to reference upoad root path node
// i could just write following in controller and it worked

$filesystem = $this->get('oneup_flysystem.gallery_filesystem');

$complete_file_path = $ultraHelpers->getDownloadableFilePath($file_id);
$exists = $filesystem->has($complete_file_path);

// Now i am stumped how to get the same effect in symfony 4.1

错误 1

如果像这样修改我的服务

oneup_flysystem.gallery_filesystem:
    class: League\Flysystem\FilesystemInterface
    public: true

当前错误

无法实例化接口 League\Flysystem\FilesystemInterface

错误 2

如果像这样修改我的服务

oneup_flysystem.gallery_filesystem:
    class: League\Flysystem\Filesystem
    public: true

当前错误

(1/1) RuntimeException 无法自动装配服务“oneup_flysystem.gallery_filesystem”:方法“League\Flysystem\Filesystem::__construct()”的参数“$adapter”引用接口“League\Flysystem\AdapterInterface”但不存在此类服务。您可能应该将此接口别名为现有的“oneup_flysystem.my_adapter_adapter”服务。

4

2 回答 2

1

似乎您在配置中错过了缩进。试着改变它

filesystems:
    default_filesystem:
        adapter: my_adapter
        alias: League\Flysystem\Filesystem
于 2018-08-09T12:22:35.310 回答
1

正确的配置有效:

oneup_flysystem.gallery_filesystem:
    alias: League\Flysystem\Filesystem
    public: true
于 2018-08-11T15:57:22.083 回答