forked from wallabag/wallabag
Added notmatches operator for tagging rule
This commit is contained in:
25
src/Wallabag/CoreBundle/Operator/Doctrine/NotMatches.php
Normal file
25
src/Wallabag/CoreBundle/Operator/Doctrine/NotMatches.php
Normal file
@ -0,0 +1,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.matches);
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
21
src/Wallabag/CoreBundle/Operator/PHP/NotMatches.php
Normal file
21
src/Wallabag/CoreBundle/Operator/PHP/NotMatches.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Operator\PHP;
|
||||
|
||||
/**
|
||||
* 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 PHP, usable
|
||||
* directly on Entry objects for instance.
|
||||
* It's registered in RulerZ using a service (wallabag.operator.array.matches);
|
||||
*/
|
||||
class NotMatches
|
||||
{
|
||||
public function __invoke($subject, $pattern)
|
||||
{
|
||||
return stripos($subject, $pattern) === false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user