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

Add multibyte support for attributeSource getOptionId method #22033

Merged
merged 4 commits into from
Apr 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getOptionText($value)
public function getOptionId($value)
{
foreach ($this->getAllOptions() as $option) {
if (strcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
if ($this->mbStrcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
return $option['value'];
}
}
Expand Down Expand Up @@ -166,4 +166,22 @@ public function toOptionArray()
{
return $this->getAllOptions();
}

/**
* Multibyte support strcasecmp function version
* @param string $str1
* @param string $str2
* @param null|string $encoding
* @return int|\\lt
*/
private function mbStrcasecmp($str1, $str2, $encoding = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello,
why do you add an optional parameter if it's never used? Or am I missing something?
Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @gomenca, do you have any update on this? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @aleron75 , you are right. I've just used this function in another places and used this parameter. I drop it.

{
if (null === $encoding) {
$encoding = mb_internal_encoding();
}
return strcmp(
mb_strtoupper($str1, $encoding),
mb_strtoupper($str2, $encoding)
);
}
}