diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2019-08-11 23:51:55 +0200 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2020-04-25 15:59:23 +0200 |
commit | f39c5a2a702036750b4d7c32d02e7f92955a4eed (patch) | |
tree | 267e1488312d8c336ef937bbe6baeddc9441f694 /src/Wallabag/CoreBundle/Operator/PHP | |
parent | 24230a5130005e274e1d8d3fe8eaca13cb978b9c (diff) | |
download | wallabag-f39c5a2a702036750b4d7c32d02e7f92955a4eed.tar.gz wallabag-f39c5a2a702036750b4d7c32d02e7f92955a4eed.tar.zst wallabag-f39c5a2a702036750b4d7c32d02e7f92955a4eed.zip |
Add new Helper to process Ignore Origin rules and RulerZ operator
This commits adds a new helper like RuleBasedTagger for processing
ignore origin rules. It also adds a new custom RulerZ operator for the
'~' pattern matching rule.
Renames 'pattern' with '_all' in IgnoreOriginRule entity.
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag/CoreBundle/Operator/PHP')
-rw-r--r-- | src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php b/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php new file mode 100644 index 00000000..532e2bb3 --- /dev/null +++ b/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php | |||
@@ -0,0 +1,23 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Operator\PHP; | ||
4 | |||
5 | /** | ||
6 | * Provides a "~" operator used for ignore origin rules. | ||
7 | * | ||
8 | * It asserts that a subject matches a given regexp pattern, in a | ||
9 | * case-insensitive way. | ||
10 | * | ||
11 | * This operator will be used to compile ignore origin rules in PHP, usable | ||
12 | * directly on Entry objects for instance. | ||
13 | * It's registered in RulerZ using a service (wallabag.operator.array.pattern_matches); | ||
14 | */ | ||
15 | class PatternMatches | ||
16 | { | ||
17 | public function __invoke($subject, $pattern) | ||
18 | { | ||
19 | $count = preg_match("`$pattern`i", $subject); | ||
20 | |||
21 | return \is_int($count) && $count > 0; | ||
22 | } | ||
23 | } | ||