Skip to content

Allow a service to be passed as DSN #46562

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

Closed
wants to merge 4 commits into from
Closed

Conversation

jackthomasatl
Copy link
Contributor

@jackthomasatl jackthomasatl commented Jun 2, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR

Add a compiler pass so that you can reuse the existing doctrine connection when configuring Symfony Lock

lock.yaml:

framework:
    lock:
        enabled: true
        resources:
            default: '@doctrine.dbal.default_connection'

@carsonbot carsonbot added this to the 5.4 milestone Jun 2, 2022
@jackthomasatl jackthomasatl changed the title 5.4 Symfony/Lock: Add compiler pass to allow a service to be passed as DSN Jun 2, 2022
@jackthomasatl
Copy link
Contributor Author

Also, Any idea what's up w/ Tests? Looks like its some postgress issue unrelated to my work.

Jack Thomas added 2 commits June 3, 2022 16:23
@jackthomasatl jackthomasatl changed the title Symfony/Lock: Add compiler pass to allow a service to be passed as DSN Symfony/Lock: Allow a service to be passed as DSN Jun 3, 2022
@jackthomasatl
Copy link
Contributor Author

So this does not get lost.... How does my username get attached as a contributor? I signed up for symfony community with my email address... what do I need to do to link my username?

$storeDefinition = new Definition(interface_exists(StoreInterface::class) ? StoreInterface::class : PersistingStoreInterface::class);
$storeDefinition->setFactory([StoreFactory::class, 'createStore']);
$storeDefinition->setArguments([$resourceStore]);
$storeDefinition->setArguments([$storeDsn]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm gonna assume this was a bug up front.... We were processing env vars but never passing the processed output into store factory. Fixed that as part of this.

Copy link
Member

Choose a reason for hiding this comment

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

this was not a bug, arguments should get the unresolved DSN

Copy link
Contributor Author

@jackthomasatl jackthomasatl Jun 10, 2022

Choose a reason for hiding this comment

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

I see. StoreFactory supports passing in quite a few types, but there's no way to reference anything, the current config is limited to passing a string.

The best I've come up with is a compiler pass or redefining the service definitions for lock. Can we figure out a way to pass a reference too?

@jackthomasatl
Copy link
Contributor Author

Also. Is there a more standardized way to do the @ -> service conversion? I've seen examples like this elsewhere, but feels like this conversion could be standardized.

@jackthomasatl jackthomasatl changed the title Symfony/Lock: Allow a service to be passed as DSN [Lock]: Allow a service to be passed as DSN Jun 7, 2022
@jackthomasatl jackthomasatl changed the title [Lock]: Allow a service to be passed as DSN [Lock] Allow a service to be passed as DSN Jun 7, 2022
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

This would be unexpected to me. We don't use such syntax nor feature anywhere else.
Let's find a more boring way if this is really needed.
Should be for 6.2 btw.

$storeDefinition = new Definition(interface_exists(StoreInterface::class) ? StoreInterface::class : PersistingStoreInterface::class);
$storeDefinition->setFactory([StoreFactory::class, 'createStore']);
$storeDefinition->setArguments([$resourceStore]);
$storeDefinition->setArguments([$storeDsn]);
Copy link
Member

Choose a reason for hiding this comment

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

this was not a bug, arguments should get the unresolved DSN

@nicolas-grekas nicolas-grekas modified the milestones: 5.4, 6.2 Jun 9, 2022
@nicolas-grekas nicolas-grekas added Feature and removed Bug labels Jun 9, 2022
@carsonbot carsonbot changed the title [Lock] Allow a service to be passed as DSN Allow a service to be passed as DSN Jun 9, 2022
@jackthomasatl
Copy link
Contributor Author

jackthomasatl commented Jun 14, 2022

I believe if not mistaken that service arguments in yaml use the @sum.service convention. @nicolas-grekas

If you can propose a solution I'll get it implemented.

@jackthomasatl
Copy link
Contributor Author

Syntax used during service definition

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

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas
Copy link
Member

Let's close as I feel like this is a niche need. Redefining the service as you did is fine for such use cases.

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

Successfully merging this pull request may close these issues.

4 participants