Skip to content

Commit

Permalink
Regex Statement
Browse files Browse the repository at this point in the history
  • Loading branch information
J0rdyV committed Jul 8, 2024
1 parent fad0693 commit 3805f7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Component/Statement/RegexStatement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Misery\Component\Statement;

class RegexStatement implements PredeterminedStatementInterface
{
public const NAME = 'REGEX';

use StatementTrait;

private function whenField(Field $field, array $item): bool
{
$field->repopulateFromItem($item);

return
isset($item[$field->getField()]) &&
is_string($item[$field->getField()]) &&
preg_match($field->getValue(), $item[$field->getField()])
;
}
}
3 changes: 3 additions & 0 deletions src/Component/Statement/StatementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static function buildFromOperator(string $operator, array $context = []):
case 'DATE':
$statement = DateStatement::prepare(new SetValueAction());
break;
case 'REGEX':
$statement = RegexStatement::prepare(new SetValueAction());
break;
case 'CHARLEN_GT':
$context['condition'] = 'greater_than';
$statement = CharlenStatement::prepare(new SetValueAction(), $context);
Expand Down

0 comments on commit 3805f7a

Please sign in to comment.