-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Feature Request] Allow to re-use an already existing S3Client instance #46
Comments
Thank you for this suggestion @Kocal! Indeed, such an approach of defining everything through the configuration would be very convenient in Symfony. It's super cool that you have managed to find the solution 👍 Although it is possible to provide your own S3 client without hacking the core code. It would be enough to create a plugin that registers a custom storage adapter. The registered adapter can directly use namespace CKSource\CKFinder\Plugin\MyCustomS3AdapterPlugin;
use CKSource\CKFinder\CKFinder;
use CKSource\CKFinder\Plugin\PluginInterface;
use PDO;
class MyCustomS3AdapterPlugin implements PluginInterface
{
public function setContainer(CKFinder $app)
{
$backendFactory = $app->getBackendFactory();
// Register a backend adapter named "my_s3".
$backendFactory->registerAdapter('my_s3', function ($backendConfig) {
$filesystemConfig = [
'visibility' => $backendConfig['visibility'] ?? 'private',
];
$prefix = isset($backendConfig['root']) ? trim($backendConfig['root'], '/ ') : null;
// Based on how $client is passed in your code (and assuming it's an object)
$client = ($backendConfig['client'] ?? null);
return $this->createBackend($backendConfig, new AwsS3($client, $backendConfig['bucket'], $prefix), $prefix), $filesystemConfig);
});
}
public function getDefaultConfig()
{
return [];
}
} Then you can simply reference such adapter in the config by |
Thanks for your response, I didn't know about CKFinder plugins system! 😅 However I have one question about the plugin location, I see in your example and in the documentation that the namespace should be That's so weird, I would expect to write a class that implements Thanks! |
@Kocal: No, placing plugin in $container->get('ckfinder.connector')->registerPlugin($pluginInstance);
That's a cool idea for improvement 👍 |
@zaak Hum okay, I will trust you, but to me it really looks like the documentation says that the plugin needs to be under For the auto-registration of |
@Kocal: Good point, this might be confusing from Symfony's perspective (or any other integration in a modern PHP app). The documentation assumes CKFinder is hosted as a standalone application. |
Hi!
First, thank you for taking over the maintenance of this bundle, we all thought it was abandoned and would prevent us to migrate to Symfony 6 (due to dependencies issues between
symfony/cache
andleague/cached-adapter
IIRC).This is why I've forked the projet and added many features (patches, taking a
S3Client
instance from the Container, using a PSR-6 cache pool, PHPStan, ...), and used it in our application.So, in the futur we plan to drop my fork and re-use this bundle, but before that we need to find a way to prevent the
BackendFactory
to create aS3Client
by itself, and use aS3Client
instance from the Symfony Container.I implemented this feature in Kocal/ckfinder-symfony-bundle#17 and Kocal/ckfinder-symfony-bundle#19, but I'm not super proud of it because I think it can be done in a better way.
Implementations idea
1. Configuration in the bundle
Ideally, we want to configure it at the
backend
configuration level, with a keyclient
that will take a string representing a service identifier.2. Dealing with the
BackendFactory
Then we need to pass this
S3Client
instance to theBackendFactory
.In my fork, I've used a
ServiceLocator
:ConnectorFactory
: https://github.com/Kocal/ckfinder-symfony-bundle/blob/main/src/DependencyInjection/CKSourceCKFinderExtension.php#L95-L97 and https://github.com/Kocal/ckfinder-symfony-bundle/blob/main/src/Factory/ConnectorFactory.php#L32BackendFactory
, see https://github.com/Kocal/ckfinder-symfony-bundle/blob/main/src/Patcher/BackendAwsS3ClientPatcher.php#L35But it means that
BackendFactory
from the CKFinder PHP Connector should be updated on your side, since I don't think we want to re-introduce a patching system here.Do you think this would be possible? Injecting a service reference in bundles in pretty common, e.g. with The PHP League's Flysystem bundle:
or with LiipImagineBundle:
Thanks!
The text was updated successfully, but these errors were encountered: