Search code examples
phpsymfonysymfony4flysystemoneupuploaderbundle

How to configure OneUpUploaderBundle and OneUpFlysystemBundle to work in Symfony 4.1


Introduction

I am trying out Syfony 4.1 with OneUpUploaderBundle and OneUpFlysystemBundle.

Problem

My configuraton worked fine in Symfony 3.4 yet with Symfony 4.1 i can not figure out how to inject OnUpUploaderBundle in my code in controler.

Configuration

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

Part of 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

Code

// 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

Error 1

if modified my service like so

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

current error

Cannot instantiate interface League\Flysystem\FilesystemInterface

Error 2

if modified my service like so

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

current error

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


Solution

  • Right config that works:

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