-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Change usage of basename where possible #1480
Conversation
continue; | ||
} | ||
|
||
$lang = basename($file->getBasename(), '.yaml'); | ||
$lang = $file->getBasename('.yaml'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't you say that the method is not locale friendly? How is this better than basename($file->getFilename(), '.yaml');
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason that DirectoryIterator::getBasename
is not locale friendly is because it calls basename
underneath. getBasename
passes the argument provided to the internal call to basename
(See implementation). In other words:
(basename($file->getBasename(), '.yaml') === basename($file->getFilename(), '.yaml')) &&
(basename($file->getBasename(), '.yaml') === $file->getBasename('.yaml'))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! |
@mahagr, whats the status of this PR? |
I am not sure. There is no second review, so maybe it was just accidentally missed up. I am quite busy right now, if nothing happens, please remind me in a week, ok? |
@mahagr, Just a reminder. It's been about 2 weeks. |
DirectoryIterator::getFilename
returns the same value asDirectoryIterator::getBasename
(no argument) while being locale safe (See getgrav/grav#2087).DirectoryIterator::getBasename
callsbasename
using the argument provided and returns the result, so callingbasename
on the result can be replaced with passing the argument toDirectoryIterator::getBasename
. I replaced one call togetBasename
withgetFilename
as well as simplifyingbasename
calls onDirectoryIterator::getBasename
. I also simplified some usage ofpathinfo
, another locale aware function.There is still an issue with locale safety (
basename
is still called byDirectoryIterator::getBasename
). I have mentioned some possible solutions in my issue to the main Grav repository (getgrav/grav#2084).