Skip to content

Commit

Permalink
I hate php 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmoss committed Jun 5, 2016
1 parent 2a7d5e2 commit e1bfe8f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/JamesMoss/Flywheel/QueryExecuter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function getFieldValue($doc, $field, &$found = false)
return $doc->{$field};
}

protected function matchDocument($doc, $field, $operator, $value)
public function matchDocument($doc, $field, $operator, $value)
{
$docVal = $this->getFieldValue($doc, $field, $found);

Expand Down Expand Up @@ -127,13 +127,17 @@ protected function filter($documents, $predicates)
return $pred[0] === Predicate::LOGICAL_OR;
});

// 5.3 hack for accessing $this inside closure.
$self = $this;

foreach($andPredicates as $predicate) {
if (is_array($predicate[1])) {
$documents = $this->filter($documents, $predicate[1]);
} else {
list($type, $field, $operator, $value) = $predicate;

$documents = array_values(array_filter($documents, function ($doc) use ($field, $operator, $value) {

$documents = array_values(array_filter($documents, function ($doc) use ($self, $field, $operator, $value) {
return $this->matchDocument($doc, $field, $operator, $value);
}));
}
Expand All @@ -147,7 +151,7 @@ protected function filter($documents, $predicates)
} else {
list($type, $field, $operator, $value) = $predicate;

$documents = array_values(array_filter($originalDocs, function ($doc) use ($field, $operator, $value) {
$documents = array_values(array_filter($originalDocs, function ($doc) use ($self, $field, $operator, $value) {
return $this->matchDocument($doc, $field, $operator, $value);
}));
}
Expand Down

0 comments on commit e1bfe8f

Please sign in to comment.