1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tylercd100\License\Traits; |
4
|
|
|
|
5
|
|
|
use Tylercd100\License\License; |
6
|
|
|
|
7
|
|
|
trait HasLicenses |
8
|
|
|
{ |
9
|
|
|
public function checkLicensesAvailable($class, $quantity) |
10
|
|
|
{ |
11
|
|
|
$license = $this->getLicenseInstance($class); |
12
|
|
|
$license->check($quantity); |
13
|
|
|
return $this; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function getLicensesRemaining($class) |
17
|
|
|
{ |
18
|
|
|
$license = $this->getLicenseInstance($class); |
19
|
|
|
return $license->remaining(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getLicensesUsed($class) |
23
|
|
|
{ |
24
|
|
|
$license = $this->getLicenseInstance($class); |
25
|
|
|
return $license->used(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function addLicenses($class, $quantity = 1) |
29
|
|
|
{ |
30
|
|
|
// Add quantity of licenses |
31
|
|
|
$license = $this->getLicenseInstance($class); |
32
|
|
|
return $license->add($quantity); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function subLicenses($class, $quantity = 1) |
36
|
|
|
{ |
37
|
|
|
// Subtract quantity of licenses |
38
|
|
|
$license = $this->getLicenseInstance($class); |
39
|
|
|
return $license->sub($quantity); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function setLicenses($class, $quantity = 1) |
43
|
|
|
{ |
44
|
|
|
// Set the quantity of licenses |
45
|
|
|
$license = $this->getLicenseInstance($class); |
46
|
|
|
return $license->set($quantity); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function removeLicenses($class) |
50
|
|
|
{ |
51
|
|
|
// Remove all licenses of type |
52
|
|
|
$license = $this->getLicenseInstance($class); |
53
|
|
|
return $license->remove(); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getLicenseInstance($class) |
57
|
|
|
{ |
58
|
|
|
$license = new $class($this); |
59
|
|
|
if (!($license instanceof License)) { |
60
|
|
|
throw LicenseException("Expected ".get_class($license)." to be an instanceof ".License::class); |
61
|
|
|
} |
62
|
|
|
return $license; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.