Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to manually disconnect for Sftp driver #1758

Closed
wants to merge 1 commit into from

Conversation

hasfoug
Copy link

@hasfoug hasfoug commented Feb 19, 2024

Exposed ConnectionProvider in SftpAdapter via geter, added disconnect method in SftpConnectionProvider

Related issues:
#1660
#1757

@@ -47,6 +47,11 @@ public function __construct(
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
}

public function getConnectionProvider(): ConnectionProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flysystem is not a DI, this should be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankdejonge But how then i should call disconnect from SftpAdapter if ConnectionProvider is private? Do you suggest that we should rather add a public disconnect method in SftpAdapter as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hasfoug the connection provider is injected in, so you can get the same instance somewhere else.

Copy link

@ttruong15 ttruong15 Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankdejonge unfortunately the connection provider is injected in but for Laravel the way it's call the connection provider is a local variable and there's no way to access it.

Here's where it's being called:

vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php

` /**
* Create an instance of the sftp driver.
*
* @param array $config
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
public function createSftpDriver(array $config)
{
$provider = SftpConnectionProvider::fromArray($config);

    $root = $config['root'] ?? '/';

    $visibility = PortableVisibilityConverter::fromArray(
        $config['permissions'] ?? []
    );

    $adapter = new SftpAdapter($provider, $root, $visibility);

    return new FilesystemAdapter($this->createFlysystem($adapter, $config), $adapter, $config);
}`

So here $provider is a local variable so we have no way off accessing the provider.  So if i want to expose the provider in Laravel I have to implement my own Storage system just to override this method to expose the provider. Such a pain.

@frankdejonge
Copy link
Member

Superseded by #1763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants