如何配置 OneUpUploaderBundle 和 OneUpFlysystemBundle 在 Symfony 4.1 中工作

How to configure OneUpUploaderBundle and OneUpFlysystemBundle to work in Symfony 4.1

简介

我正在尝试 Syfony 4.1 OneUpUploaderBundleOneUpFlysystemBundle

问题

我的配置在 Symfony 3.4 中运行良好,但在 Symfony 4.1 中运行良好 我不知道如何在我的控制器代码中注入 OnUpUploaderBundle。

配置

OneUpUploader.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

当前错误

Cannot instantiate interface League\Flysystem\FilesystemInterface

错误 2

如果像这样修改我的服务

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

当前错误

(1/1) RuntimeException Cannot autowire service "oneup_flysystem.gallery_filesystem": argument "$adapter" of method "League\Flysystem\Filesystem::__construct()" references interface "League\Flysystem\AdapterInterface" but no such service exists. You should maybe alias this interface to the existing "oneup_flysystem.my_adapter_adapter" service.

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

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

有效的正确配置:

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