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

FIX: Class names referenced in Config should be case-insensitive #3381

Closed

Conversation

sminnee
Copy link
Member

@sminnee sminnee commented Aug 13, 2014

The config system maps top-level key name to a PHP class. PHP classes are case-insensitive,
but without this patch, the Config system was case-sensitive on this variable. I think this
should be considered a bug.

The following patch makes the "class" key case-insensitive, but leave the "name" key, as
case-sensitive, mirroring the semantics of PHP classes and static variables, respectively.

Arguably, the entire config system could be case-insensitive, but I haven't done that in
this patch.

The config system maps top-level key name to a PHP class. PHP classes are case-insensitive,
but without this patch, the Config system was case-sensitive on this variable. I think this
should be considered a bug.

The following patch makes the "class" key case-insensitive, but leave the "name" key, as
case-sensitive, mirroring the semantics of PHP classes and static variables, respectively.

Arguably, the entire config system could be case-insensitive, but I haven't done that in
this patch.
@sminnee
Copy link
Member Author

sminnee commented Aug 13, 2014

I'd be keen to get @hafriedlander input on this, since he is God of The Config System.

@dhensby
Copy link
Contributor

dhensby commented Feb 28, 2015

+1 for this @hafriedlander

I think this is a bug fix and can stay against 3.1

@tractorcow
Copy link
Contributor

How do you feel about using a case-fixing mechanism instead of strtolower? See https://github.com/micmania1/silverstripe-framework/blob/replace-static-manifest/core/ClassInfo.php#L163 for @micmania1 's solution.

Is there a place we could strategically place this in the code so that we have to do as few case corrections as possible? Places such as get_called_class() automatically normalise class casing, so there are certainly times it's not necessary.

I personally feel that storing the config in the correct case is going to deviate the least amount from what the current behaviour is, and is less likely to introduce regressions.

@micmania1
Copy link
Contributor

The issue with my solution is that it only resolves class names - not made up configuration in yaml. I'd be able to remove my fix if it was agreed that this is the best way to go.

@dhensby
Copy link
Contributor

dhensby commented Jul 30, 2015

fixes #3378

@dhensby
Copy link
Contributor

dhensby commented Jul 30, 2015

strtolower has to be the least CPU cycles to get this "feature" working.. I prefer it over reflection or normalising the class names

@sminnee
Copy link
Member Author

sminnee commented Jul 30, 2015

Maybe this would be better in 3.2 instead, just because of the regression risk issue that Damian pointed out.

@dhensby
Copy link
Contributor

dhensby commented Jul 30, 2015

very much related: #3949

@dhensby
Copy link
Contributor

dhensby commented Jul 30, 2015

I think this is a patch and should stay in 3.1 myself. Under what circumstances could this cause a problem to existing code?

@tractorcow
Copy link
Contributor

@sminnee @dhensby fixed this in #3949 but opted to use a "fix case" method rather than treating all classes as lowercase for matching. Should we use the same solution here?

@dhensby
Copy link
Contributor

dhensby commented Aug 28, 2015

Makes sense to make it consistent with #3949

@sminnee ?

@sminnee sminnee changed the base branch from 3.1 to master September 5, 2016 05:35
@tractorcow
Copy link
Contributor

Superceded by new config api, which stores all per-class config with a lowercase key https://github.com/silverstripe/silverstripe-config/blob/1.0/src/Collections/MemoryConfigCollection.php#L82

@tractorcow tractorcow closed this Nov 9, 2017
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.

None yet

4 participants