symfony-docs icon indicating copy to clipboard operation
symfony-docs copied to clipboard

[Lock] Configure lock component via framework-bundle with a DBAL Connection

Open rvitaliy opened this issue 4 years ago • 7 comments

Hi all. i want to configure lock using mysql and current DBAL connection. But i cant understand how to configure it. refs: https://symfony.com/doc/current/components/lock.html#pdostore https://symfony.com/doc/current/reference/configuration/framework.html#lock manually is likes:

    Symfony\Component\Lock\Store\PdoStore:
        arguments:
            $connOrDsn: '@doctrine.dbal.default_connection'

    Symfony\Component\Lock\LockFactory:
        arguments:
            $store: '@Symfony\Component\Lock\Store\PdoStore'

Thanks!

rvitaliy avatar Jul 30 '20 15:07 rvitaliy

Hello,

using the following configuration you should be able to use the lock using the default doctrine connection.

    # config/packages/framework.yaml

    framework:
        lock:
            enabled: true
            resources:
                default:
                    - '%env(DATABASE_URL)%'

You can then inject Symfony\Component\Lock\LockFactory using autowiring and use for creating the locks.

$this->lockFactory->createLock('my-lock-id', 30);

ribeiropaulor avatar Aug 26 '20 08:08 ribeiropaulor

@ribeiropaulor Hi, thanks for your reply! It's not same, because with your example the Lock component create a new connection with database_url parameters and don't reuse the already created Connection in our container services.

rvitaliy avatar Aug 26 '20 08:08 rvitaliy

@rvitaliy You're right. It would be better to reuse the connection.

ribeiropaulor avatar Aug 26 '20 12:08 ribeiropaulor

Looking for a resolve on this issue myself, but shouldn't it be filed under the symfony repo rather than here in symfony-docs?

tomsykes avatar Jun 23 '21 13:06 tomsykes

@tomsykes maybe yes, now that we accurate that it's a feature request and not documentation problem. feel free to open an issue in the symfony repository

rvitaliy avatar Jun 23 '21 14:06 rvitaliy

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Jun 24 '22 12:06 carsonbot

Could I get a reply or should I close this?

carsonbot avatar Jul 08 '22 12:07 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar Aug 28 '22 14:08 carsonbot