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

Case insensitive validation inList option #2034

Closed
ghost opened this issue Oct 11, 2013 · 4 comments
Closed

Case insensitive validation inList option #2034

ghost opened this issue Oct 11, 2013 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 11, 2013

Created by Dmitri De Klerk, 17th Sep 2013. (originally Lighthouse ticket #3521):


I dono if this is the place to post this,

This is more of an enhancement than a bug or issue.

Validation::inList(string $check, array $list);

The above function will be awesome if it had another optional parameter, ignorecase

e.g.

/**

  • Checks if a value is in a given list.
    *
  • @param string $check Value to check
  • @param array $list List to check against
  • @param boolean $strict Defaults to true, set to false to disable strict type check
  • @param boolean $ignorecase Defaults to false, set to true to enable ignore case check
  • @return boolean Success
    */
    public static function inList($check, $list, $strict = true, $ignorecase = false) {
    if ( $ignorecase ) {
    return in_array($check, $list, $strict);
    } else {
    return in_array(strtolower($check), array_map('strtolower', $list), $strict);
    }
    }

One can probably argue, then why don't you just make the array $list all lowercase, and then
you can just do a strtolower call, before doing the in_array check.

we'll if that's the case, then we can atleast have a strtolower on the $check string, with the ignore case option.

Just a thought!

@ghost
Copy link
Author

ghost commented Oct 11, 2013

11th Jan 2013, Mark Story said:


Perhaps a separate method could work as well? 2 boolean parameters in a row feels like too many to me. Perhaps inListInsensitive?

@ghost
Copy link
Author

ghost commented Oct 11, 2013

11th Jan 2013, Dmitri De Klerk said:


yes, that's perfect!

@ghost
Copy link
Author

ghost commented Oct 11, 2013

17th Sep 2013, euromark said:


PR: #1649

EDIT: Updated PR that also addresses "multiple()": #1655

"This is more of an enhancement than a bug or issue."

Actually, by bringing it up, you made me find bugs there in the code that need to be addressed. So it is more relevant than you initially thought.

@dereuromark
Copy link
Member

Closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant