Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Finder\Comparator;
13
 
14
/**
15
 * @author Fabien Potencier <fabien@symfony.com>
16
 */
17
class Comparator
18
{
19
    private string $target;
20
    private string $operator;
21
 
22
    public function __construct(string $target, string $operator = '==')
23
    {
24
        if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='])) {
25
            throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
26
        }
27
 
28
        $this->target = $target;
29
        $this->operator = $operator;
30
    }
31
 
32
    /**
33
     * Gets the target value.
34
     */
35
    public function getTarget(): string
36
    {
37
        return $this->target;
38
    }
39
 
40
    /**
41
     * Gets the comparison operator.
42
     */
43
    public function getOperator(): string
44
    {
45
        return $this->operator;
46
    }
47
 
48
    /**
49
     * Tests against the target.
50
     */
51
    public function test(mixed $test): bool
52
    {
53
        return match ($this->operator) {
54
            '>' => $test > $this->target,
55
            '>=' => $test >= $this->target,
56
            '<' => $test < $this->target,
57
            '<=' => $test <= $this->target,
58
            '!=' => $test != $this->target,
59
            default => $test == $this->target,
60
        };
61
    }
62
}