-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathKeyLimitChecker.php
46 lines (42 loc) · 1.46 KB
/
KeyLimitChecker.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
<?php
// Copyright 1999-2025. WebPros International GmbH.
namespace PleskXTest\Utility;
class KeyLimitChecker
{
public const LIMIT_CLIENTS = 'limit_clients';
public const LIMIT_RESELLERS = 'limit_resellers';
public const LIMIT_DOMAINS = 'limit_domains';
/**
* Checks whether limit is within the required constraint.
*
* @param (string|int)[] $keyInfo Structure returned by the getKeyInfo call
* @param string $type Type of the object that should be checked
* @param int $minimalRequirement Minimal value that should satisfy the limit
*
* @return bool if license satisfies set limits
*/
public static function checkByType(array $keyInfo, $type, $minimalRequirement)
{
$field = null;
switch ($type) {
case self::LIMIT_CLIENTS:
if (intval($keyInfo['can-manage-customers']) === 0) {
return false;
}
$field = 'lim_cl';
break;
case self::LIMIT_RESELLERS:
if (intval($keyInfo['can-manage-resellers']) === 0) {
return false;
}
$field = 'lim_cl';
break;
case self::LIMIT_DOMAINS:
$field = 'lim_dom';
break;
default:
return false;
}
return intval($keyInfo[$field]) === -1 || intval($keyInfo[$field]) > $minimalRequirement;
}
}