Skip to content

Commit 80efbeb

Browse files
committed
add delayed verification
1 parent 06022cc commit 80efbeb

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

config/verify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ValidateSupporter::class => 'ef1a42701af6dc36e052556a0ee1c762394f9428',
1515
ValidatePro::class => '482b48f1a026684b6c1754e45ca180ffc52483ff',
1616
ValidateSignature::class => '5a8a855d4b59c44c298daa66801c79f2aba20492',
17-
Verify::class => '4b8d56f2b19fc88546cc2effb23673fa3993b2b9',
17+
Verify::class => 'b83a0797bf778ab28bf0fcfdb2d81ba15dc5fc3e',
1818
VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed',
1919
VerifyProStatus::class => '212e6ada794587ee8e2b81cf76e243d134a7e823',
2020
VerifyServiceProvider::class => '923b63b15d25e69b95ed1d5ec1c82ba57f1a7d74',

src/Verify.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace LycheeVerify;
44

55
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
67
use LycheeVerify\Contract\Status;
78
use LycheeVerify\Contract\VerifyInterface;
89
use LycheeVerify\Exceptions\SupporterOnlyOperationException;
@@ -23,18 +24,54 @@ class Verify implements VerifyInterface
2324

2425
private ?Status $status;
2526

27+
private bool $initialized = false;
28+
2629
public function __construct(
2730
#[\SensitiveParameter] ?string $config_email = null,
2831
#[\SensitiveParameter] ?string $license_key = null,
2932
#[\SensitiveParameter] ?string $public_key = null,
3033
#[\SensitiveParameter] ?string $hash_supporter = null,
3134
#[\SensitiveParameter] ?string $hash_pro = null,
3235
) {
33-
$this->config_email = $config_email ?? DB::table('configs')->where('key', 'email')->first()?->value ?? ''; // @phpstan-ignore-line
34-
$this->license_key = $license_key ?? DB::table('configs')->where('key', 'license_key')->first()?->value ?? ''; // @phpstan-ignore-line
3536
$this->validateSignature = new ValidateSignature($public_key);
3637
$this->validatePro = new ValidatePro($hash_pro);
3738
$this->validateSupporter = new ValidateSupporter($hash_supporter);
39+
$this->init($config_email, $license_key);
40+
}
41+
42+
/**
43+
* To avoid crashing when the database does not exists we
44+
* add some safeties.
45+
*
46+
* @param string|null $config_email
47+
* @param string|null $license_key
48+
*
49+
* @return bool
50+
*/
51+
private function init(
52+
#[\SensitiveParameter] ?string $config_email = null,
53+
#[\SensitiveParameter] ?string $license_key = null,
54+
): bool {
55+
if ($config_email !== null || $license_key !== null) {
56+
// If both values are provided, no need to check the database
57+
$this->config_email = $config_email ?? '';
58+
$this->license_key = $license_key ?? '';
59+
$this->initialized = true;
60+
61+
return true;
62+
}
63+
64+
// Validate that the database is ready
65+
if (!Schema::hasTable('configs')) {
66+
return false;
67+
}
68+
69+
// Load the necessary config entries
70+
$this->config_email = DB::table('configs')->where('key', 'email')->first()?->value ?? ''; // @phpstan-ignore-line
71+
$this->license_key = DB::table('configs')->where('key', 'license_key')->first()?->value ?? ''; // @phpstan-ignore-line
72+
$this->initialized = true;
73+
74+
return true;
3875
}
3976

4077
/**
@@ -44,6 +81,10 @@ public function __construct(
4481
*/
4582
public function get_status(): Status
4683
{
84+
if (!$this->initialized && !$this->init()) {
85+
return Status::FREE_EDITION;
86+
}
87+
4788
return $this->status ??= $this->resolve_status();
4889
}
4990

0 commit comments

Comments
 (0)