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

Port commands for Symfony 4.2 (follows #876) #877

Merged
merged 6 commits into from Nov 30, 2018

Conversation

dunglas
Copy link
Contributor

@dunglas dunglas commented Nov 15, 2018

Follows (and needs) #876.

It works, but it introduces several BC breaks:

  • Commands doesn't extend ContainerAwareCommand anymore (as this class is deprecated)
  • Some constructor parameters are now mandatory (because we use DI instead of injection the container)

Making the commands fully BC would be possible by using hacks like this one to introduce some conditional inheritance, but I'm not sure that it is worth it: ContainerAwareCommand commands were designed to be initialized by the framework itself.

Also, to prevent future similar issues, I marked these commands @final, and the abstract DoctrineCommand as @internal.

@dunglas dunglas changed the title Port commands for Symfony 4.2 (follows ) Port commands for Symfony 4.2 (follows #876) Nov 16, 2018
Resources/config/orm.xml Outdated Show resolved Hide resolved
Resources/config/orm.xml Outdated Show resolved Hide resolved
@dunglas
Copy link
Contributor Author

dunglas commented Nov 16, 2018

It looks like dependencies are not injected for SF 2.8 and 3.2, any idea of what's going on (@chalasr maybe)?

@kimhemsoe kimhemsoe added this to the 1.9.2 milestone Nov 16, 2018
Resources/config/dbal.xml Outdated Show resolved Hide resolved
Resources/config/orm.xml Outdated Show resolved Hide resolved
@dunglas
Copy link
Contributor Author

dunglas commented Nov 23, 2018

All green

@kimhemsoe kimhemsoe self-assigned this Nov 23, 2018
@kimhemsoe
Copy link
Member

Is this ready?

@dunglas
Copy link
Contributor Author

dunglas commented Nov 29, 2018

it is. Just beware of the tiny BC break: commands don't extend ContainerAwareCommand anymore.

@alcaeus
Copy link
Member

alcaeus commented Nov 29, 2018

it is. Just beware of the tiny BC break: commands don't extend ContainerAwareCommand anymore.

Are we still exposing the methods from ContainerAwareCommand or are those no longer there? Wondering about the impact of the BC break. How did Symfony take care of this?

@chalasr
Copy link
Contributor

chalasr commented Nov 30, 2018

@alcaeus no, they are not exposed anymore.

Symfony core commands stopped extending this class in 3.4 but kept a BC layer until 4.0 which was:

  • all added constructor args are nullable at first, triggering deprecation notices if given null
  • the setContainer() and getContainer() methods are copy-pasted into commands and deprecated with notice
  • calls to getContainer are preserved in case dependencies are not wired via constructor args

It could be worth using the same approach here.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

We either need to make master 2.0.x-dev before merging this or make these changes backwards compatible. These classes are covered by the BC promise.

@dunglas
Copy link
Contributor Author

dunglas commented Nov 30, 2018

@chalasr, as far as I understand, what you suggest limit the BC break, but doesn’t prevent it totally: $command instanceof ContainerAwareCommand will now be false, and it may break existing code.

To limit the BC break, I’ve marked the commands as final (but it hasn’t been done in an earlier release, it’s kind of useless for the next version).

Bumping the major version just for that looks a bit overkill, but it’s the only solution I have in mind to be fully semver compliant.

@chalasr
Copy link
Contributor

chalasr commented Nov 30, 2018

@dunglas Yea, that would just considerably reduce the impact

@alcaeus would the suggested layer be enough to merge this in 1.x? We can’t avoid the type change

@alcaeus
Copy link
Member

alcaeus commented Nov 30, 2018

Agree on making the classes "final" using @final - since it's documentation only it's just a suggestion so no BC break. We should follow up on that by making them final in the next major release unless there's a good point not to do so. This would help prevent such situations in the future.

I also agree that tagging a major version for this is overkill, but I'm worried about breaking BC. This could happen if someone extended the commands in their projects and relied on $this->getContainer() being present, in which case they'd have a fatal error after upgrading. It could also happen if someone instantiated the commands themselves without passing the now required constructor options. We should definitely prepare a BC layer for the latter, maybe we can even build a replacement for getContainer(). I can live with the inheritance chain being "broken".

@kimhemsoe
Copy link
Member

@weaverryan Is this BC break ok with you guys?

@chalasr
Copy link
Contributor

chalasr commented Nov 30, 2018

BC layer added, PR rebased. Ready on my side (build failure seems unrelated)

Copy link
Contributor

@Majkl578 Majkl578 left a comment

Choose a reason for hiding this comment

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

Please fix coding standard violations. I restarted the stage manually, you can see it here: https://travis-ci.org/doctrine/DoctrineBundle/jobs/461744294

*/
public function setContainer(ContainerInterface $container = null)
{
@trigger_error(sprintf('The "%s()" method is deprecated and will be removed in DoctrineBundle 2.0.', __METHOD__), E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

As per Doctrine's Deprecation Policy, silenced deprecations should not be used - @deprecated annotation should be used instead.

Copy link
Member

Choose a reason for hiding this comment

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

Since we're dealing with a Symfony Bundle here, it makes sense to use the Symfony way of dealing with deprecations, don't you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that silenced deprecations are used elsewhere in the code base already.

Copy link
Contributor

Choose a reason for hiding this comment

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

don't you think?

Not convinced, just like with CS - it sits under Doctrine GH org. We had this discussion many times already, with @Ocramius too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I won't fight here, deprecation notices removed.

@chalasr
Copy link
Contributor

chalasr commented Nov 30, 2018

@Majkl578 CS fixed, thanks.
The remaining failure https://travis-ci.org/doctrine/DoctrineBundle/jobs/461761448 is due to the incompatibility between symfony/doctrine-bridge:4.1 and symfony/messenger:4.2, not related to this PR.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Thanks @chalasr!

@kimhemsoe kimhemsoe merged commit 82d2c63 into doctrine:master Nov 30, 2018
@kimhemsoe
Copy link
Member

Thanks @dunglas and @chalasr

@dunglas dunglas deleted the commands-sf42 branch November 30, 2018 13:58
@dunglas
Copy link
Contributor Author

dunglas commented Nov 30, 2018

@kimhemsoe thanks for the merge! Can you tag a release too please (Symfony 4.2 has been released, so the current version triggers deprecations).

@kimhemsoe
Copy link
Member

@dunglas Done :)

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.

None yet

6 participants