diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-12-06 14:31:26 +0100 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-12-06 14:31:26 +0100 |
commit | a7f1921f7db312b5def3839393357f443dcbb52c (patch) | |
tree | 0522e03891433e9fdc9eb64d52b2d9651aadf1f7 /src/Wallabag/CoreBundle/Operator | |
parent | 2e15e30bf0e634bbbc3a9678904953d015490ed2 (diff) | |
parent | 752b90d1f2e279d3662d5431b09c7587df2937ca (diff) | |
download | wallabag-a7f1921f7db312b5def3839393357f443dcbb52c.tar.gz wallabag-a7f1921f7db312b5def3839393357f443dcbb52c.tar.zst wallabag-a7f1921f7db312b5def3839393357f443dcbb52c.zip |
Merge pull request #1478 from K-Phoen/rule-based-tags
Rule based tags
Diffstat (limited to 'src/Wallabag/CoreBundle/Operator')
-rw-r--r-- | src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php | 25 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Operator/PHP/Matches.php | 21 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php b/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php new file mode 100644 index 00000000..e6bb03b1 --- /dev/null +++ b/src/Wallabag/CoreBundle/Operator/Doctrine/Matches.php | |||
@@ -0,0 +1,25 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Operator\Doctrine; | ||
4 | |||
5 | /** | ||
6 | * Provides a "matches" operator used for tagging rules. | ||
7 | * | ||
8 | * It asserts that a given pattern is contained in a subject, in a | ||
9 | * case-insensitive way. | ||
10 | * | ||
11 | * This operator will be used to compile tagging rules in DQL, usable | ||
12 | * by Doctrine ORM. | ||
13 | * It's registered in RulerZ using a service (wallabag.operator.doctrine.matches); | ||
14 | */ | ||
15 | class Matches | ||
16 | { | ||
17 | public function __invoke($subject, $pattern) | ||
18 | { | ||
19 | if ($pattern[0] === "'") { | ||
20 | $pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1)); | ||
21 | } | ||
22 | |||
23 | return sprintf('UPPER(%s) LIKE UPPER(%s)', $subject, $pattern); | ||
24 | } | ||
25 | } | ||
diff --git a/src/Wallabag/CoreBundle/Operator/PHP/Matches.php b/src/Wallabag/CoreBundle/Operator/PHP/Matches.php new file mode 100644 index 00000000..987ed2a5 --- /dev/null +++ b/src/Wallabag/CoreBundle/Operator/PHP/Matches.php | |||
@@ -0,0 +1,21 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Operator\PHP; | ||
4 | |||
5 | /** | ||
6 | * Provides a "matches" operator used for tagging rules. | ||
7 | * | ||
8 | * It asserts that a given pattern is contained in a subject, in a | ||
9 | * case-insensitive way. | ||
10 | * | ||
11 | * This operator will be used to compile tagging rules in PHP, usable | ||
12 | * directly on Entry objects for instance. | ||
13 | * It's registered in RulerZ using a service (wallabag.operator.array.matches); | ||
14 | */ | ||
15 | class Matches | ||
16 | { | ||
17 | public function __invoke($subject, $pattern) | ||
18 | { | ||
19 | return stripos($subject, $pattern) !== false; | ||
20 | } | ||
21 | } | ||