-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathReactant.php
100 lines (84 loc) · 2.73 KB
/
Reactant.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* This file is part of Laravel Love.
*
* (c) Anton Komarev <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cog\Laravel\Love\Reactant\Facades;
use Cog\Contracts\Love\Reactant\Facades\Reactant as ReacterFacadeContract;
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantContract;
use Cog\Contracts\Love\Reactant\ReactionCounter\Models\ReactionCounter as ReactionCounterContract;
use Cog\Contracts\Love\Reactant\ReactionTotal\Models\ReactionTotal as ReactionTotalContract;
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableContract;
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
final class Reactant implements
ReacterFacadeContract
{
/**
* @var ReactantContract
*/
private $reactant;
public function __construct(ReactantContract $reactant)
{
$this->reactant = $reactant;
}
/**
* @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[]
*/
public function getReactions(): iterable
{
return $this->reactant->getReactions();
}
/**
* @return iterable|\Cog\Contracts\Love\Reactant\ReactionCounter\Models\ReactionCounter[]
*/
public function getReactionCounters(): iterable
{
return $this->reactant->getReactionCounters();
}
public function getReactionCounterOfType(
string $reactionTypeName
): ReactionCounterContract {
return $this->reactant->getReactionCounterOfType(
ReactionType::fromName($reactionTypeName)
);
}
public function getReactionTotal(): ReactionTotalContract
{
return $this->reactant->getReactionTotal();
}
public function isReactedBy(
?ReacterableContract $reacterable = null,
?string $reactionTypeName = null,
?float $rate = null
): bool {
if ($reacterable === null) {
return false;
}
$reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);
return $this->reactant->isReactedBy(
$reacterable->getLoveReacter(),
$reactionType,
$rate
);
}
public function isNotReactedBy(
?ReacterableContract $reacterable = null,
?string $reactionTypeName = null,
?float $rate = null
): bool {
if ($reacterable === null) {
return true;
}
$reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);
return $this->reactant->isNotReactedBy(
$reacterable->getLoveReacter(),
$reactionType,
$rate
);
}
}