wallabag/src/Operator/Doctrine/Matches.php

26 lines
611 B
PHP
Raw Normal View History

2015-11-13 13:37:58 +00:00
<?php
2024-02-19 00:30:12 +00:00
namespace Wallabag\Operator\Doctrine;
2015-11-13 13:37:58 +00:00
/**
* Provides a "matches" operator used for tagging rules.
*
* It asserts that a given pattern is 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;
*/
2015-11-13 13:37:58 +00:00
class Matches
{
public function __invoke($subject, $pattern)
{
2017-10-09 14:47:15 +00:00
if ("'" === $pattern[0]) {
2015-11-13 13:37:58 +00:00
$pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1));
}
return sprintf('UPPER(%s) LIKE UPPER(%s)', $subject, $pattern);
}
}