aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Operator/Doctrine/NotMatches.php
blob: b7f9da57f532f85d3e4656c018f00c129d1f3a9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

namespace Wallabag\CoreBundle\Operator\Doctrine;

/**
 * Provides a "notmatches" operator used for tagging rules.
 *
 * It asserts that a given pattern is not contained in a subject, in a
 * case-insensitive way.
 *
 * This operator will be used to compile tagging rules in DQL, usable
 * by Doctrine ORM.
 * It's registered in RulerZ using a service (wallabag.operator.doctrine.notmatches);
 */
class NotMatches
{
    public function __invoke($subject, $pattern)
    {
        if ($pattern[0] === "'") {
            $pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1));
        }

        return sprintf('UPPER(%s) NOT LIKE UPPER(%s)', $subject, $pattern);
    }
}