-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependencyInfo.php
executable file
·69 lines (61 loc) · 2.24 KB
/
DependencyInfo.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace TestPlugin {
/**
* A class used to represent a dependency on something else for the plugin.
* The dependency types this class can represent are: A class, function or constant.
* */
class DependencyInfo {
public $dependencyKeyToCheck;
public $dependencyName;
public $type;
public function __construct($keyToCheck, $name, $type = DependencyType::CLASS_TYPE) {
$this->dependencyKeyToCheck = $keyToCheck;
$this->dependencyName = $name;
$this->type = $type;
}
/**
* Verifies that this dependency is satisfied.
*
* @return bool If this dependency is satisfied
*/
public function verify():bool {
$valid = false;
switch ($this->type) {
case DependencyType::CLASS_TYPE:
$valid = class_exists($this->dependencyKeyToCheck);
break;
case DependencyType::CONSTANT_TYPE:
$valid = defined($this->dependencyKeyToCheck);
break;
case DependencyType::FUNCTION_TYPE:
$valid = function_exists($this->dependencyKeyToCheck);
break;
default:
}
return $valid;
}
/**
* Gets the message to display if this dependency is not satisfied.
*
* @return string The message.
*/
public function getMissingMessage():string {
$msg = "The ";
switch ($this->type) {
case DependencyType::CLASS_TYPE:
$msg .= "Class";
break;
case DependencyType::CONSTANT_TYPE:
$msg .= "Constant";
break;
case DependencyType::FUNCTION_TYPE:
$msg .= "Function";
break;
default:
$msg .= "Dependency";
}
$msg .= " \"{$this->dependencyKeyToCheck}\" was not found, and is part of the plugin \"".$this->dependencyName.".\"";
return $msg;
}
}
}