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

Change usage of basename where possible #1480

Merged
merged 3 commits into from
Oct 4, 2018
Merged

Change usage of basename where possible #1480

merged 3 commits into from
Oct 4, 2018

Conversation

tcyrus
Copy link
Contributor

@tcyrus tcyrus commented Jul 6, 2018

DirectoryIterator::getFilename returns the same value as DirectoryIterator::getBasename (no argument) while being locale safe (See getgrav/grav#2087). DirectoryIterator::getBasename calls basename using the argument provided and returns the result, so calling basename on the result can be replaced with passing the argument to DirectoryIterator::getBasename. I replaced one call to getBasename with getFilename as well as simplifying basename calls on DirectoryIterator::getBasename. I also simplified some usage of pathinfo, another locale aware function.

There is still an issue with locale safety (basename is still called by DirectoryIterator::getBasename). I have mentioned some possible solutions in my issue to the main Grav repository (getgrav/grav#2084).

continue;
}

$lang = basename($file->getBasename(), '.yaml');
$lang = $file->getBasename('.yaml');
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 you say that the method is not locale friendly? How is this better than basename($file->getFilename(), '.yaml');?

Copy link
Contributor Author

@tcyrus tcyrus Jul 9, 2018

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'))

Copy link
Contributor Author

@tcyrus tcyrus Jul 9, 2018

Choose a reason for hiding this comment

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

It also matches up with the usage of DirectoryIterator::getBasename in the main grav repository (See here and here). This specific change was to aviod redundancy and keep consistency with the rest of the codebase.

@mahagr
Copy link
Member

mahagr commented Jul 20, 2018

Looks good to me!

@tcyrus
Copy link
Contributor Author

tcyrus commented Sep 17, 2018

@mahagr, whats the status of this PR?

@mahagr
Copy link
Member

mahagr commented Sep 19, 2018

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?

@tcyrus
Copy link
Contributor Author

tcyrus commented Oct 1, 2018

@mahagr, Just a reminder. It's been about 2 weeks.

@mahagr mahagr merged commit 85bb59e into getgrav:develop Oct 4, 2018
@tcyrus tcyrus deleted the patch-1 branch October 4, 2018 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants