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

doctrine service is public #712

Merged
merged 1 commit into from
Oct 8, 2017

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Oct 6, 2017

As used by Symfony's ControllerTrait, make the doctrine service public.

@@ -56,14 +56,14 @@

<service id="doctrine.dbal.connection.configuration" class="%doctrine.dbal.configuration.class%" public="false" abstract="true" />

<service id="doctrine" class="%doctrine.class%">
<service id="doctrine" class="%doctrine.class%" public="true">
Copy link
Member

Choose a reason for hiding this comment

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

This file doesn't specify defaults, so the service will be public by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Services are going to be private by default in Symfony 4.0.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, I didn't think of that.

<argument type="service" id="service_container" />
<argument>%doctrine.connections%</argument>
<argument>%doctrine.entity_managers%</argument>
<argument>%doctrine.default_connection%</argument>
<argument>%doctrine.default_entity_manager%</argument>
</service>
<service id="Doctrine\Common\Persistence\ManagerRegistry" alias="doctrine" public="false" />
<service id="Doctrine\Common\Persistence\ManagerRegistry" alias="doctrine" public="true" />
Copy link
Member

Choose a reason for hiding this comment

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

Why make this service public? As far as I've seen, the new service aliases in Symfony (e.g. TranslatorInterface, RouterInterface) are all private.

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 guess that without this the auto-wiring wouldn't work 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Autowiring doesn't rely on public services. Private services can't be fetched using Container::get, but they can be used as references within the service configuration if I'm not mistaken. Maybe @fabpot could clear this up?

Copy link
Member

Choose a reason for hiding this comment

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

this one must indeed be reverted.

@fabpot
Copy link
Member

fabpot commented Oct 6, 2017

Should be done in 1.6.x, right?

@sroze sroze force-pushed the doctrine-service-is-public branch from 81c68f9 to c9adf6c Compare October 6, 2017 14:44
@sroze sroze changed the base branch from master to 1.6.x October 6, 2017 14:44
@sroze
Copy link
Contributor Author

sroze commented Oct 6, 2017

@fabpot good point; rebased and changed PR target 👍

@stof
Copy link
Member

stof commented Oct 6, 2017

a bunch of other services must stay public too, as they are the main services of the bundle:

  • the connection and entity manager services
  • the doctrine.orm.entity_manager and database_connection aliases for default entity manager and connection

DoctrineBundle is already quite good at marking services as private where needed, so most existing public services should stay public (the exception are the form and validator ones, which were public only by requirement of Symfony < 3.3, and so can become private when using Symfony 4.x)

@sroze
Copy link
Contributor Author

sroze commented Oct 6, 2017

@fabpot already PRed the change for the connections and entity managers in #703.
Pushed a change to make sure the alias is public if it's what you meant @stof.

@sroze
Copy link
Contributor Author

sroze commented Oct 6, 2017

The doctrine.dbal.connection_factory and abstract doctrine.dbal.connection are the only remaining services dbal not to have a public attribute... should we explicitly make them public? Could do the same for the orm.xml file... 🤔

@stof
Copy link
Member

stof commented Oct 6, 2017

well, for the abstract service, this is useless, as child services have their visibility set explicitly.

The connection factory does not need to be public either (Symfony 3.4 and 4.0 support using private services in service factories, but old versions of Symfony were buggy in this case).

You still need to ensure that the database_connection alias is public, and to revert the visibility change on the ManagerRegistry autowiring alias.

And tests are broken

@sroze sroze force-pushed the doctrine-service-is-public branch 2 times, most recently from 5bd8bd7 to 2f24d33 Compare October 6, 2017 15:38
@sroze sroze force-pushed the doctrine-service-is-public branch from 2f24d33 to e0a9109 Compare October 6, 2017 15:38
@sroze
Copy link
Contributor Author

sroze commented Oct 6, 2017

@stof updated, added tests and they are green (HHVM failing but not related) 👍

@sroze
Copy link
Contributor Author

sroze commented Oct 8, 2017

Should we merge this? /cc @fabpot

@fabpot fabpot merged commit 96a074a into doctrine:1.6.x Oct 8, 2017
@sroze sroze deleted the doctrine-service-is-public branch October 8, 2017 16:45
@mikeSimonson mikeSimonson added this to the 1.8.0 milestone Oct 31, 2017
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.

5 participants