1

could you help me with this please?

Cannot autowire service "App\Estimate\DocumentManager": argument "$flysystem" of method "__construct()" references class "League\Flysystem\Filesystem" but no such service exists. You should maybe alias this class to the existing "oneup_flysystem.estimateDocumentsFilesystem_filesystem" service.

my config file:

parameters:
    flysystem.local.estimate_documents.path: '%kernel.root_dir%/../public/uploads/estimate/documents'

services:
    app.estimate.document_manager:
        class: App\Estimate\DocumentManager
        lazy: true
        public: true
        arguments: ['@doctrine.orm.entity_manager', '@estimateDocumentsFilesystem', '@monolog.logger']

oneup_flysystem:
    filesystems:
        estimateDocumentsFilesystem:
            adapter: estimateDocumentsAdapter
            visibility: public
            alias: "estimate_documents_filesystem"

    adapters:
        estimateDocumentsAdapter:
            local:
                directory: "%flysystem.local.estimate_documents.path%"

class DocumentManager
{

    /**
     * @var EntityManager
     */
    private $manager;

    /**
     * @var Filesystem
     */
    private $flysystem;

    /**
     * @var Logger
     */
    private $logger;

    /**
     * DocumentManager constructor.
     *
     * @param EntityManagerInterface $manager
     * @param Filesystem $flysystem
     * @param Logger $logger
     */
    public function __construct(
        EntityManagerInterface $manager,
        Filesystem $flysystem,
        Logger $logger
    )
    {
        $this->manager = $manager;
        $this->flysystem = $flysystem;
        $this->logger = $logger;
    }
}

Thanks a lot. I can't understand where is problem.

// EDIT:

if I add thisIf i add this in config

services:
League\Flysystem\FilesystemInterface: '@estimate_documents_filesystem'

it works only for one filesystem what the f.. is wrong?

The best regards Jimmy

Jakub Kontra
  • 173
  • 1
  • 2
  • 14

3 Answers3

2

The answer given to disable autoconfigure is in my opinion a stupid answer, since the best practice of Symfony is to use it.

The problem is that the current version of the OneupFlysystemBundle doesn't correctly configure it's services to use Symfoyny's autowiring correctly.

Therefore, until this is fixed within the bundle, the correct workaround is to manually tag the interface to the correct service. In your services.yaml

League\Flysystem\FilesystemInterface: "@estimate_documents_filesystem"

(Note: if you're using the default configuration of this bundle and follow it's steps the service will be named "@oneup_flysystem.acme_filesystem", or by following Symfony best practices it should be "@oneup_flysystem.app_filesystem" if you have only one filesystem. If unsure, you can use bin/console debug:container to find the correct name of the service)

Rein Baarsma
  • 1,302
  • 9
  • 21
1

To have multiple file systems do as following:

services.yaml
   services:
        _defaults:
            bind:
                publicUploadFileSystem: '@oneup_flysystem.public_uploads_filesystem_filesystem'
oneup_flysystem.yaml
    oneup_flysystem:
        adapters:
            public_uploads_adapter:
                local:
                    directory: '%kernel.project_dir%/public/uploads'
        filesystems:
            public_uploads_filesystem:
                adapter: public_uploads_adapter

Tutorial: https://symfonycasts.com/screencast/symfony-uploads/flysystem-usage#play

  • this is returning: ` The service "App\Service\UploaderHelper" has a dependency on a non-existent service "oneup_flysystem.public_uploads_filesystem_filesystem". ` – ben.IT Jan 25 '21 at 14:44
-2

Need to turn off autowiring and autoconfigure. Add this:

autoconfigure:false
autowire:false

Full configuration:

App\Estimate\Document\DocumentManager:
    autoconfigure: false
    autowire: false
    arguments: ['@doctrine.orm.entity_manager', '@estimate_documents_filesystem', '@monolog.logger']

App\User\DocumentManager:
    autoconfigure: false
    autowire: false
    arguments: ['@doctrine.orm.entity_manager', '@user_avatars_filesystem', '@monolog.logger']
Jakub Kontra
  • 173
  • 1
  • 2
  • 14