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

Now MetaDataFilter takess also regexp. For example whern you want to #507

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
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
11 changes: 10 additions & 1 deletion lib/Doctrine/ORM/Tools/Console/MetadataFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ public function accept()
$metadata = $it->current();

foreach ($this->filter as $filter) {
if (strpos($metadata->name, $filter) !== false) {
$pregResult = preg_match("/" . preg_quote($filter) . "/", $metadata->name);
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot use preg_qoute here, if you do so, $filter will not be treated as a regular expression (which was the intention of this pull request). And even if you do so, you still do not escape the delimiter, you would have to do this: preg_quote($filter, '/').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true. I realized that after I pushed the code. Some unit test might be helpfull here

Copy link
Member

Choose a reason for hiding this comment

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

Just remove the preg_quote()

if ($pregResult === false) {
return false;
}

if ($pregResult === 0) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

if you return false for both false and 0, there is no need to handle them separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know. There was one sugestiin that it should be treated diferently. My open question was: should I twrow an exception when error occurs?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please, Exception makes sense

}

if ($pregResult) {
return true;
}
}
Expand Down