Skip to content

Commit

Permalink
Raw rule now supports an iterables like In rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Протопопов Валерий committed Sep 18, 2018
1 parent 911e519 commit 3be4dab
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Rule/Raw.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,25 @@ public function __construct(string $expression)
*/
public function makeCriterion($value, ParamGeneratorInterface $paramGenerator): ?Criterion
{
$params = [];
if (strpos($this->expression, ':value') === false) {
return new Criterion($this->expression, []);
}

$paramKey = $paramGenerator->generate('raw');

if (is_iterable($value)) {
if (count($value) === 0) {
return null;
}

$params = [];
foreach ($value as $i => $item) {
$params[$paramKey . '_' . $i] = $item;
}

if (strpos($this->expression, ':value') !== false) {
$params[$paramGenerator->generate('raw')] = $value;
$this->expression = str_replace(':value', key($params), $this->expression);
return new Criterion(str_replace(':value', join(',', array_keys($params)), $this->expression), $params);
}

return new Criterion($this->expression, $params);
return new Criterion(str_replace(':value', $paramKey, $this->expression), [$paramKey => $value]);
}
}

0 comments on commit 3be4dab

Please sign in to comment.