]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php
Add new Helper to process Ignore Origin rules and RulerZ operator
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Operator / PHP / PatternMatches.php
diff --git a/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php b/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php
new file mode 100644 (file)
index 0000000..532e2bb
--- /dev/null
@@ -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;
+    }
+}