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>
This commit is contained in:
Kevin Decherf
2019-08-11 23:51:55 +02:00
parent 24230a5130
commit f39c5a2a70
6 changed files with 300 additions and 4 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace Wallabag\CoreBundle\Operator\PHP;
/**
* Provides a "~" operator used for ignore origin rules.
*
* It asserts that a subject matches a given regexp pattern, in a
* case-insensitive way.
*
* This operator will be used to compile ignore origin rules in PHP, usable
* directly on Entry objects for instance.
* It's registered in RulerZ using a service (wallabag.operator.array.pattern_matches);
*/
class PatternMatches
{
public function __invoke($subject, $pattern)
{
$count = preg_match("`$pattern`i", $subject);
return \is_int($count) && $count > 0;
}
}