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

[Config] Deprecate TreeBuilder::root #31027

Merged
merged 1 commit into from Apr 9, 2019

Conversation

Projects
None yet
8 participants
@gharlan
Copy link
Contributor

gharlan commented Apr 8, 2019

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass?
Fixed tickets #29876
License MIT
Doc PR

Alternative idea to #31015. Or is the root method still needed?

It would look like this:

Screenshot 2019-04-09 01 15 04

@gharlan gharlan changed the title Deprecate TreeBuilder::root [Config] Deprecate TreeBuilder::root Apr 8, 2019

@javiereguiluz javiereguiluz added the Config label Apr 9, 2019

@gharlan gharlan force-pushed the gharlan:deprecate-tree-builder-root branch from 8f24200 to 0d4689b Apr 9, 2019

@xabbuh xabbuh added this to the next milestone Apr 9, 2019

@xabbuh

xabbuh approved these changes Apr 9, 2019

@xabbuh
Copy link
Member

xabbuh left a comment

Oh, please mention the deprecation in the component changelog file as well as in the upgrade files for 4.3 and 5.0.

@gharlan gharlan force-pushed the gharlan:deprecate-tree-builder-root branch from 0d4689b to ff6bc79 Apr 9, 2019

@gharlan

This comment has been minimized.

Copy link
Contributor Author

gharlan commented Apr 9, 2019

Status: Needs Review

@chalasr

chalasr approved these changes Apr 9, 2019

@xabbuh

xabbuh approved these changes Apr 9, 2019

@fabpot

fabpot approved these changes Apr 9, 2019

@fabpot

This comment has been minimized.

Copy link
Member

fabpot commented Apr 9, 2019

Thank you @gharlan.

@fabpot fabpot merged commit ff6bc79 into symfony:master Apr 9, 2019

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Apr 9, 2019

feature #31027 [Config] Deprecate TreeBuilder::root (gharlan)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Config] Deprecate TreeBuilder::root

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   |
| Fixed tickets | #29876
| License       | MIT
| Doc PR        | —

Alternative idea to #31015. Or is the `root` method still needed?

It would look like this:

![Screenshot 2019-04-09 01 15 04](https://user-images.githubusercontent.com/330436/55762865-fbd85900-5a64-11e9-9680-0870c85d1c09.png)

Commits
-------

ff6bc79 Deprecate TreeBuilder::root

@gharlan gharlan deleted the gharlan:deprecate-tree-builder-root branch Apr 9, 2019

@sstok

This comment has been minimized.

Copy link
Contributor

sstok commented Apr 14, 2019

This makes compatibility for older versions much harder as you still need to call root() in those cases, while passing the name to the constructor was was already possible.

$treeBuilder = new TreeBuilder('rollerworks_password_strength');
$rootNode = $treeBuilder->root('rollerworks_password_strength'); // BC for Symfony < 4.2

What about checking if a name was already set in the constructor, and it equals the passed name.
In this case, return $this->root and do nothing, otherwise throw an deprecation instead.

To ensure forward compatibility you still need to check if the root() method exists. But least you don't get any deprecation warnings.

$treeBuilder = new TreeBuilder('rollerworks_password_strength');

if (method_exists($treeBuilder, 'root')) {
    $rootNode = $treeBuilder->root('rollerworks_password_strength'); // BC for Symfony < 4.2
} else {
    $rootNode = $treeBuilder->getRootNode();
}
@gharlan

This comment has been minimized.

Copy link
Contributor Author

gharlan commented Apr 14, 2019

As far as I know many libs already use method_exists.

@sstok

This comment has been minimized.

Copy link
Contributor

sstok commented Apr 14, 2019

Ah I completely missed #27476 😛

#27476 (comment) gives a good suggestion

$treeBuilder = new TreeBuilder("my_node");
$rootNode = method_exists($treeBuilder, "getRootNode")
    ? $treeBuilder->getRootNode()
    : $treeBuilder->root("my_node");

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.