Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Config] allow changing the path separator #22253

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

Merged
merged 1 commit into from
Jan 21, 2018

Conversation

bburnichon
Copy link
Contributor

@bburnichon bburnichon commented Apr 3, 2017

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

In bundles configuration, no dots are allowed in key names, but as a standalone config, there is no such limitation that should be enforced.

By using current NodeBuilder it should be possible to change path separator used (for example: /)

@bburnichon bburnichon changed the title Config allow dots in node names [Config] allow dots in node names Apr 4, 2017
@bburnichon bburnichon changed the base branch from 2.7 to master April 4, 2017 15:00
@bburnichon bburnichon force-pushed the config-allow-dots branch 2 times, most recently from 9f680c6 to bcf4039 Compare April 5, 2017 09:50
@nicolas-grekas nicolas-grekas modified the milestone: 3.4 Apr 10, 2017
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.

missing tests and CHANGELOG entry

@@ -23,6 +23,10 @@
*/
abstract class BaseNode implements NodeInterface
{
const DEFAULT_PATH_SEPARATOR = '.';

private $pathSeparator;
Copy link
Member

Choose a reason for hiding this comment

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

since all other props are protected, should we make this one protected also, and use it directly in child nodes?

Copy link
Member

Choose a reason for hiding this comment

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

I would keep it private if it does not need to be protected. It is easier for our BC policy

protected $root;
protected $builder;
Copy link
Member

Choose a reason for hiding this comment

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

this should be deprecated instead with an annotation (no need for runtime BC layer since this is useless, WDYT?)

@@ -21,6 +22,7 @@
*/
abstract class NodeDefinition implements NodeParentInterface
{
private $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR;
Copy link
Member

Choose a reason for hiding this comment

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

protected?

{
if (false !== strpos($name, '.')) {
throw new \InvalidArgumentException('The name must not contain ".".');
Copy link
Member

Choose a reason for hiding this comment

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

this should be kept, but the dot replaced by the pathSeparator

Copy link
Contributor Author

@bburnichon bburnichon Jul 12, 2017

Choose a reason for hiding this comment

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

Why not, but this is the only place where the name is checked. In prototyped node, name property is not enforced and make Node inconsistent. See 7be490f

Copy link
Member

Choose a reason for hiding this comment

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

@bburnichon would you mind reverting this change (and using the $pathSeparator of course). Better not remove an existing check.

/**
* @throws \RuntimeException if root node is not defined.
*/
private function assertTreeHasRootNode()
Copy link
Member

Choose a reason for hiding this comment

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

I think doing removing this an doing the check inline would be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is currently called twice. It is done this way to keep code DRY.

@nicolas-grekas nicolas-grekas changed the title [Config] allow dots in node names [Config] allow changing the path separator Jul 12, 2017
@bburnichon bburnichon changed the base branch from master to 3.4 July 12, 2017 15:43
@bburnichon bburnichon force-pushed the config-allow-dots branch 3 times, most recently from 69db47b to 669122c Compare July 13, 2017 09:15
@ogizanagi ogizanagi self-requested a review September 25, 2017 12:08
@nicolas-grekas
Copy link
Member

Rebase needed (we don't merge PRs when they contain merge commit)

@bburnichon
Copy link
Contributor Author

Tests are failing on Form Component which I did not change. Is it a known issue?

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.

(tests back to green)


/**
* @param string $name The name of the node
* @param NodeInterface $parent The parent of this node
* Constructor.
Copy link
Member

Choose a reason for hiding this comment

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

Didn't we recently remove all comments like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it was reintroduced by my rebase. I will remove it.

/**
* @return NodeDefinition[]
*/
public function getChildrenNodeDefinitions();
Copy link
Member

Choose a reason for hiding this comment

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

This reads weird to me, what about getChildNodeDefinitions() or getChildNodesDefinitions()?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we really need this interface or if we shouldn't rather check for the method to exist. We could then add this method to the ParentNodeDefinitionInterface in 4.0.

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 don't have strong opinion about how to name this method. Actually, I already had a hard time finding this one. The same is true for the whole interface.
In case checking for the method to exist, how would you mark deprecation notice though?

*/
public function setPathSeparator($separator)
{
if ($this instanceof ChildrenAwareNodeDefinitionInterface) {
Copy link
Member

@nicolas-grekas nicolas-grekas Oct 9, 2017

Choose a reason for hiding this comment

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

if ($this instanceof ArrayNodeDefinition) { would be enough for the purpose, isn't it?
about the method, my preference is getChildNodeDefinitions

@xabbuh
Copy link
Member

xabbuh commented Oct 9, 2017

We will also need to update the UPGRADE-3.4.md (explain that implementing the interface without the added method is deprecated) and UPGRADE-4.0.md (mention the added method) files.

UPGRADE-4.0.md Outdated
Config
------

* Implementing `ParentNodeDefinitionInterface` without the `getChildNodeDefinitions()` is now forbidden.
Copy link
Member

Choose a reason for hiding this comment

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

I would rewrite this to be like this:

Added the getChildNodeDefinitions() method to ParentNodeDefinitionInterface.

@bburnichon
Copy link
Contributor Author

Twig and VarDumper failure don't seem to be related to my PR. Are failures expected?

@xabbuh
Copy link
Member

xabbuh commented Oct 10, 2017

The Twig failure should be fixable by rebasing on the latest 3.4 branch and the VarDumper tests are currently failing on the 3.4 branch too.

@nicolas-grekas
Copy link
Member

Moving to 4.1 as 3.4 is now in beta, thus closed for new feats.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 24, 2017
@bburnichon bburnichon changed the base branch from 3.4 to master October 25, 2017 08:04
@bburnichon
Copy link
Contributor Author

Failures do not seem linked to my changes.

@bburnichon bburnichon force-pushed the config-allow-dots branch 2 times, most recently from 2e54486 to 5f29f79 Compare October 30, 2017 09:10
@bburnichon
Copy link
Contributor Author

Rebased after merge of deprecation and removal of TreeBuilder::$builder

@bburnichon bburnichon force-pushed the config-allow-dots branch 2 times, most recently from 18664f4 to 14d6f78 Compare November 21, 2017 14:07
@nicolas-grekas
Copy link
Member

@bburnichon please rebase: we don't merge PR with merge commits.

@bburnichon
Copy link
Contributor Author

Sorry I did update via github interface.

@javiereguiluz
Copy link
Member

I like this feature, but I wonder if "path separator" is the best name for this option. Path is strongly related to "file paths". Maybe "name separator" or "key separator" or "children separator" etc.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 11, 2018

@javiereguiluz "path" is the correct term, already used a lot in the component:

$ grep path src/Symfony/Component/Config/ -ri | wc -l
219

@nicolas-grekas
Copy link
Member

Thank you @bburnichon.

@nicolas-grekas nicolas-grekas merged commit 15e05e1 into symfony:master Jan 21, 2018
nicolas-grekas added a commit that referenced this pull request Jan 21, 2018
This PR was merged into the 4.1-dev branch.

Discussion
----------

[Config] allow changing the path separator

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

In bundles configuration, no dots are allowed in key names, but as a standalone config, there is no such limitation that should be enforced.

By using current `NodeBuilder` it should be possible to change path separator used (for example: `/`)

Commits
-------

15e05e1 Add feature allowing change of Path Separator
@bburnichon bburnichon deleted the config-allow-dots branch January 24, 2018 15:49
@fabpot fabpot mentioned this pull request May 7, 2018
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.

6 participants