LicenseKeyRepository.php
994 Bytes
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
<?php
namespace ACP;
use AC\Storage\KeyValueFactory;
use AC\Storage\KeyValuePair;
use ACP\Type\Activation\Key;
use ACP\Type\LicenseKey;
class LicenseKeyRepository
{
/**
* @var KeyValuePair
*/
private $storage;
public function __construct(KeyValueFactory $storage_factory)
{
$this->storage = $storage_factory->create('acp_subscription_key');
}
public function find(): ?LicenseKey
{
$key = defined('ACP_LICENCE') && ACP_LICENCE
? ACP_LICENCE
: $this->storage->get();
if ( ! Key::is_valid($key)) {
return null;
}
$source = $this->is_defined()
? LicenseKey::SOURCE_CODE
: LicenseKey::SOURCE_DATABASE;
return new LicenseKey($key, $source);
}
private function is_defined(): bool
{
return defined('ACP_LICENCE') && ACP_LICENCE;
}
public function delete(): bool
{
return $this->storage->delete();
}
}