forked from greydnls/spec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChain.php
More file actions
67 lines (53 loc) · 1.63 KB
/
Chain.php
File metadata and controls
67 lines (53 loc) · 1.63 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace Bakame\Specification;
final class Chain implements Composite
{
private function __construct(private Specification $specification)
{
}
public function specification(): Specification
{
return $this->specification;
}
public static function one(Specification $specification): self
{
return new self($specification);
}
public static function all(Specification ...$specification): self
{
return new self(new All(...$specification));
}
public static function any(Specification ...$specification): self
{
return new self(new Any(...$specification));
}
public static function none(Specification ...$specification): self
{
return new self(new None(...$specification));
}
public function isSatisfiedBy(mixed $subject): bool
{
return $this->specification->isSatisfiedBy($subject);
}
public function and(Specification ...$specification): Composite
{
return self::all($this->specification, ...$specification);
}
public function andNot(Specification ...$specification): Composite
{
return self::all($this->specification, new None(...$specification));
}
public function or(Specification ...$specification): Composite
{
return self::any($this->specification, ...$specification);
}
public function orNot(Specification ...$specification): Composite
{
return self::any($this->specification, new None(...$specification));
}
public function not(): Composite
{
return self::none($this->specification);
}
}