|
5 | 5 | use Illuminate\Support\Facades\DB; |
6 | 6 | use LycheeVerify\Contract\Status; |
7 | 7 | use LycheeVerify\Contract\VerifyInterface; |
8 | | -use LycheeVerify\Exceptions\SupporterOnlyOperationException; |
9 | 8 | use LycheeVerify\Validators\ValidatePro; |
10 | 9 | use LycheeVerify\Validators\ValidateSignature; |
11 | 10 | use LycheeVerify\Validators\ValidateSupporter; |
|
14 | 13 |
|
15 | 14 | class Verify implements VerifyInterface |
16 | 15 | { |
| 16 | + use VerifyTrait; |
17 | 17 | private string $config_email; |
18 | 18 | private string $license_key; |
19 | 19 | private ValidateSignature $validateSignature; |
@@ -58,94 +58,6 @@ public function get_status(): Status |
58 | 58 | return Status::FREE_EDITION; |
59 | 59 | } |
60 | 60 |
|
61 | | - /** |
62 | | - * Check the status of the installation and validate. |
63 | | - * |
64 | | - * @param Status $required_status (default to SUPPORTER_EDITION) |
65 | | - * |
66 | | - * @return bool |
67 | | - */ |
68 | | - public function check(Status $required_status = Status::SUPPORTER_EDITION): bool |
69 | | - { |
70 | | - if ($required_status === Status::FREE_EDITION) { |
71 | | - return true; |
72 | | - } |
73 | | - |
74 | | - $status = $this->get_status(); |
75 | | - |
76 | | - return match ($status) { |
77 | | - Status::SIGNATURE_EDITION => true, |
78 | | - Status::PRO_EDITION => in_array($required_status, [Status::PRO_EDITION, Status::SUPPORTER_EDITION], true), |
79 | | - Status::SUPPORTER_EDITION => in_array($required_status, [Status::SUPPORTER_EDITION], true), |
80 | | - default => false, |
81 | | - }; |
82 | | - } |
83 | | - |
84 | | - /** |
85 | | - * Returns true if the user is a supporter (or plus registered user). |
86 | | - * |
87 | | - * @return bool |
88 | | - */ |
89 | | - public function is_supporter(): bool |
90 | | - { |
91 | | - return $this->check(Status::SUPPORTER_EDITION); |
92 | | - } |
93 | | - |
94 | | - /** |
95 | | - * Return true of the user is a plus registered user. |
96 | | - * |
97 | | - * @return bool |
98 | | - */ |
99 | | - public function is_pro(): bool |
100 | | - { |
101 | | - return $this->check(Status::PRO_EDITION); |
102 | | - } |
103 | | - |
104 | | - /** |
105 | | - * Return true if the user is a signature user. |
106 | | - * |
107 | | - * @return bool |
108 | | - */ |
109 | | - public function is_signature(): bool |
110 | | - { |
111 | | - return $this->check(Status::SIGNATURE_EDITION); |
112 | | - } |
113 | | - |
114 | | - /** |
115 | | - * Authorize the operation if the installation is verified. |
116 | | - * Otherwise throw an exception. |
117 | | - * |
118 | | - * @param Status $required_status (default to SUPPORTER_EDITION) |
119 | | - * |
120 | | - * @return void |
121 | | - * |
122 | | - * @throws SupporterOnlyOperationException |
123 | | - */ |
124 | | - public function authorize(Status $required_status = Status::SUPPORTER_EDITION): void |
125 | | - { |
126 | | - if (!$this->check($required_status)) { |
127 | | - throw new SupporterOnlyOperationException($required_status); |
128 | | - } |
129 | | - } |
130 | | - |
131 | | - /** |
132 | | - * Fork depending whether the installation is verified or not. |
133 | | - * |
134 | | - * @template T |
135 | | - * |
136 | | - * @param T|\Closure(): T $valIfTrue what happens or Value if we features are enabled |
137 | | - * @param T|\Closure(): T $valIfFalse what happens or Value if we features are disabled |
138 | | - * @param Status $required_status |
139 | | - * |
140 | | - * @return T |
141 | | - */ |
142 | | - public function when(mixed $valIfTrue, mixed $valIfFalse, Status $required_status = Status::SUPPORTER_EDITION): mixed |
143 | | - { |
144 | | - $retValue = $this->check($required_status) ? $valIfTrue : $valIfFalse; |
145 | | - |
146 | | - return is_callable($retValue) ? $retValue() : $retValue; |
147 | | - } |
148 | | - |
149 | 61 | /** |
150 | 62 | * Validate installation. |
151 | 63 | * |
|
0 commit comments