Skip to content

Trim constant values in XmlFileLoader #20252

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 2 commits into from
Closed

Trim constant values in XmlFileLoader #20252

wants to merge 2 commits into from

Conversation

lstrojny
Copy link
Contributor

@lstrojny lstrojny commented Oct 19, 2016

Q A
Branch? 2.7, 2.8, 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n.A.
License MIT
Doc PR n.A.

When an XML config file gets long, it's nice to put the constant name into the next line like this:

<parameter key="som_very_very_long_constant_name" type="constant">
    Some\Namespace\That\Is\Sufficiently\Long\To\Require\A\LineBreak::someLongishConstantName
</parameter>

If that’s the case, constant() will try and find a constant including the spaces. While it is theoretically possible to have a constant in PHP that starts or ends with a space, it’s impossible for class constants and only doable using define(" FOO ", …);. So that’s probably an edge case we can ignore.

When an XML config file gets long, it's nice to put the constant name into the next line like this:
```xml
        <parameter key="som_very_very_long_constant_name" type="constant">
            Some\Namespace\That\Is\Sufficiently\Long\To\Require\A\LineBreak::someLongishConstantName
        </parameter>
```

If that’s the case, `constant()` will try and find a constant including the spaces. While it is theoretically possible to have a constant in PHP that starts or ends with a space, it’s impossible for class constants and only doable using `define(" FOO ", …);`. So that’s probably an edge case we can ignore.
@@ -391,7 +391,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
$arguments[$key] = $arg->nodeValue;
break;
case 'constant':
$arguments[$key] = constant($arg->nodeValue);
$arguments[$key] = constant(trim(arg->nodeValue));
Copy link
Contributor

Choose a reason for hiding this comment

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

$arg ;-)

@lstrojny
Copy link
Contributor Author

@ro0NL 👍

@keradus
Copy link
Member

keradus commented Oct 19, 2016

you forgot to commit utest for a change ;)

@fabpot
Copy link
Member

fabpot commented Oct 21, 2016

LGTM, should be merged in 2.7.

@Tobion
Copy link
Contributor

Tobion commented Oct 21, 2016

👍

1 similar comment
@xabbuh
Copy link
Member

xabbuh commented Oct 22, 2016

👍

@fabpot
Copy link
Member

fabpot commented Oct 22, 2016

Thank you @lstrojny.

fabpot added a commit that referenced this pull request Oct 22, 2016
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #20252).

Discussion
----------

Trim constant values in XmlFileLoader

| Q             | A
| ------------- | ---
| Branch?       | 2.7, 2.8, 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n.A.
| License       | MIT
| Doc PR        | n.A.

When an XML config file gets long, it's nice to put the constant name into the next line like this:
```xml
<parameter key="som_very_very_long_constant_name" type="constant">
    Some\Namespace\That\Is\Sufficiently\Long\To\Require\A\LineBreak::someLongishConstantName
</parameter>
```

If that’s the case, `constant()` will try and find a constant including the spaces. While it is theoretically possible to have a constant in PHP that starts or ends with a space, it’s impossible for class constants and only doable using `define(" FOO ", …);`. So that’s probably an edge case we can ignore.

Commits
-------

f09e621 Trim constant values in XmlFileLoader
@fabpot fabpot closed this Oct 22, 2016
This was referenced Oct 27, 2016
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.

7 participants