1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Laravel Love. |
5
|
|
|
* |
6
|
|
|
* (c) Anton Komarev <[email protected]> |
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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Cog\Laravel\Love\Reacter\Facades; |
15
|
|
|
|
16
|
|
|
use Cog\Contracts\Love\Reactable\Models\Reactable as ReactableInterface; |
17
|
|
|
use Cog\Contracts\Love\Reacter\Facades\Reacter as ReacterFacadeInterface; |
18
|
|
|
use Cog\Contracts\Love\Reacter\Models\Reacter as ReacterInterface; |
19
|
|
|
use Cog\Laravel\Love\ReactionType\Models\ReactionType; |
20
|
|
|
|
21
|
|
|
final class Reacter implements |
22
|
|
|
ReacterFacadeInterface |
23
|
|
|
{ |
24
|
|
|
private ReacterInterface $reacter; |
25
|
|
|
|
26
|
|
|
public function __construct( |
27
|
|
|
ReacterInterface $reacter, |
28
|
|
|
) { |
29
|
|
|
$this->reacter = $reacter; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[] |
34
|
|
|
*/ |
35
|
|
|
public function getReactions(): iterable |
36
|
|
|
{ |
37
|
|
|
return $this->reacter->getReactions(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function reactTo( |
41
|
|
|
ReactableInterface $reactable, |
42
|
|
|
string $reactionTypeName, |
43
|
|
|
float | null $rate = null, |
44
|
|
|
): void { |
45
|
|
|
$this->reacter->reactTo( |
46
|
|
|
$reactable->getLoveReactant(), |
47
|
|
|
ReactionType::fromName($reactionTypeName), |
48
|
|
|
$rate, |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function unreactTo( |
53
|
|
|
ReactableInterface $reactable, |
54
|
|
|
string $reactionTypeName, |
55
|
|
|
): void { |
56
|
|
|
$this->reacter->unreactTo( |
57
|
|
|
$reactable->getLoveReactant(), |
58
|
|
|
ReactionType::fromName($reactionTypeName), |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function hasReactedTo( |
63
|
|
|
ReactableInterface $reactable, |
64
|
|
|
string | null $reactionTypeName = null, |
65
|
|
|
float | null $rate = null, |
66
|
|
|
): bool { |
67
|
|
|
$reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName); |
68
|
|
|
|
69
|
|
|
return $this->reacter->hasReactedTo( |
70
|
|
|
$reactable->getLoveReactant(), |
71
|
|
|
$reactionType, |
72
|
|
|
$rate, |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function hasNotReactedTo( |
77
|
|
|
ReactableInterface $reactable, |
78
|
|
|
string | null $reactionTypeName = null, |
79
|
|
|
float | null $rate = null, |
80
|
|
|
): bool { |
81
|
|
|
$reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName); |
82
|
|
|
|
83
|
|
|
return $this->reacter->hasNotReactedTo( |
84
|
|
|
$reactable->getLoveReactant(), |
85
|
|
|
$reactionType, |
86
|
|
|
$rate, |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|