aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Operator/PHP/PatternMatches.php
blob: 532e2bb39907d2474e7dadcdca189a9235167fb6 (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
<?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;
    }
}