-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Like or Not Like - that's where the question #50
base: 2.0.x
Are you sure you want to change the base?
Conversation
$pattern = str_replace('%', '.*', $pattern); | ||
$pattern = str_replace('_', '.{1}', $pattern); | ||
$pattern = str_replace('SQLWILDCARDESCAPEDMANY', '\\%', $pattern); | ||
$pattern = str_replace('SQLWILDCARDESCAPEDONE', '\\_', $pattern); |
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.
this implementation is flawed: it will break for strings containing SQLWILDCARDESCAPEDONE
already.
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.
true, but what can be alternative?
use DOCTRINECOLLECTIONSSQLWILDCARDESCAPEDMANY
? 😉
$pattern = str_replace('_', '.{1}', $pattern); | ||
$pattern = str_replace('SQLWILDCARDESCAPEDMANY', '\\%', $pattern); | ||
$pattern = str_replace('SQLWILDCARDESCAPEDONE', '\\_', $pattern); | ||
$pattern = '/^' . $pattern . '$/'; |
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.
Because of your other changes, some of my comments disappeared without being fixed.
All the pattern building should be done outside the closure given that it does not depend on the object. This will avoid rebuilding it for each object of the collection
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.
disappeared, but I not forgot 😉
if I place it like:
$like = $comparison->getOperator() === Comparison::LIKE;
/// here the pattern building
return function ($object) use ($field, $value, $like) {
it will be good?
just not sure
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.
yes it will
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.
hope now is better 😄
|
||
if($pattern) { | ||
return (bool) ($like ? preg_match($pattern, $fieldValue) : !preg_match($pattern, $fieldValue)); | ||
} |
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.
instead of checking whether a preg_match or an equality should be used each time the function is called, you could check it outside, returning different functions
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.
yes, good idea
I just got idea, that we can use a random string instead of |
Any random string will still suffer from the same issue. The difference is that you will not know what is the forbidden value |
hm, hm, I wondered why it marked 🐛 ? I thought it is "new feature" 😄 |
New
Comparison::LIKE
andComparison::NOTLIKE
as alternative solution for #45 💃Support next wildcard characters:
%
- any character(s), any amount_
- any character, only one\%
- escape for%
\_
- escape for_