Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/StringExpressionLanguageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function getFunctions(): array
ExpressionFunction::fromPhp('strip_tags', 'stripHtml'),
ExpressionFunction::fromPhp('json_decode', 'decode'),
ExpressionFunction::fromPhp('preg_replace', 'replaceByExpression'),
new TestPattern('testPattern'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

On pourrait pas nommer la fonction isMatchingPattern ?
Je trouve ça plus explicite que le testPattern

new CapitalizeWords('capitalizeWords'),
ExpressionFunction::fromPhp('rtrim', 'removeWhitespaces'),
ExpressionFunction::fromPhp('explode', 'splitIntoArray'),
Expand Down
32 changes: 32 additions & 0 deletions src/TestPattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Kiboko\Component\StringExpressionLanguage;

class TestPattern
{
public function __construct($name)
{
}

private function compile(string $pattern, string $subject): bool
{
return <<<PHP
\$result = preg_match({$pattern}, {$subject});
if (!\$result) {
return false;
} else {
return true;
}
PHP;
}

private function evaluate(array $context, string $pattern, string $subject): bool
{
$result = preg_match($pattern, $subject);
if (!$result) {
return false;
} else {
return true;
}
}
}