1up-lab / OneupFlysystemBundle

A Flysystem integration for your Symfony projects.
MIT License
634 stars 118 forks source link

Cannot autowire service, missing argument reference (no service found) #169

Closed JakubKontra closed 4 years ago

JakubKontra commented 6 years ago

Hi guys, 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.

The best regards Jimmy

JakubKontra commented 6 years ago

If i add this in config


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

it works.. what? :(

Pictor13 commented 4 years ago

That's because of strict autowiring, from Symfony 4: https://symfonycasts.com/screencast/symfony4-upgrade/service-deprecations#strict-autowiring-mode

JakubKontra commented 4 years ago

Yea. Thanks