1up-lab / OneupFlysystemBundle

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

Possible issue with Symfony 3.4.13 #174

Closed mdrewek closed 3 years ago

mdrewek commented 6 years ago

I have the following setup:

# config.yml
oneup_flysystem:
    adapters:
        data_adapter:
            local:
                directory: "/path/to/data-dir"
    filesystems:
        data_filesystem:
            adapter: data_adapter
            alias: data_filesystem
# services.yml
services:
    _defaults:
        autowire: true
        autoconfigure: true
        bind:
            $dataFileSystem: "@oneup_flysystem.data_filesystem_filesystem"
class MyController extends Controller
{
  public function someAction(Flysystem\FilesystemInterface $dataFileSystem)
  {
  }
}

With Symfony 3.4.12, it works fine. Whenever I upgrade to 3.4.13, I get the following issue;

Controller "MyController::someAction()" requires that you provide a value for the "$dataFileSystem" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

mdrewek commented 6 years ago

Let me add some words on why I use bind: rather than using Flysystem\FilesystemInterface as method type hint for DI (or aliasing the type): I use different file systems with FlySystem within one bundle. So binding these to different variable names always worked for me. I did not yet try to switch to the Mount Manager, which might be a good idea.

bytehead commented 6 years ago

This seems to be an issue rather related to Symfony than to this bundle.

bytehead commented 6 years ago

Does this kind of binding work for other arguments, e.g. a demo controller or the like?

mdrewek commented 6 years ago

Yes, I use this for different Monolog channels, for instance. So I can inject $batchLogger which has type hint LoggerInterface, but is then bound to batch channel. For Monolog, this works with all Symfony 3.4 versions. For FlySystem, it does not work for Symfony 3.4.13, but with versions before.

From your perspective, what's the recommended way to have DI inject one particular File System into a Service via autowiring?

faizanakram99 commented 5 years ago

@mdrewek

You probably need to add League\Flysystem\FilesystemInterface as an alias to League\Flysystem\Filesystem service,

something like this

services:
    _defaults:
        autowire: true
        autoconfigure: true
        oneup_flysystem.data_filesystem_filesystem:
          alias: League\Flysystem\FilesystemInterface
          public: true # only needed to make it accessible from service container
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.