1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Moodle component manager. |
5
|
|
|
* |
6
|
|
|
* @author Luke Carrier <[email protected]> |
7
|
|
|
* @copyright 2016 Luke Carrier |
8
|
|
|
* @license GPL-3.0+ |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ComponentManager; |
12
|
|
|
|
13
|
|
|
use OutOfBoundsException; |
14
|
|
|
use stdClass; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Component specification. |
18
|
|
|
* |
19
|
|
|
* A component specification is a structure used to hold all information about a |
20
|
|
|
* specific component before we're able to look up the component in the |
21
|
|
|
* associated package source. We should resolve this to obtain a Component |
22
|
|
|
* object as soon as we can during installation. |
23
|
|
|
*/ |
24
|
|
|
class ComponentSpecification { |
25
|
|
|
/** |
26
|
|
|
* Component name. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $name; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Package repository. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $packageRepository; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Package source. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $packageSource; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Component version. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $version; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Extra metadata. |
55
|
|
|
* |
56
|
|
|
* @var stdClass |
57
|
|
|
*/ |
58
|
|
|
protected $extra; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Initialiser. |
62
|
|
|
* |
63
|
|
|
* @param string $name |
64
|
|
|
* @param string $version |
65
|
|
|
* @param string $packageRepository |
|
|
|
|
66
|
|
|
* @param string $packageSource |
|
|
|
|
67
|
|
|
* @param stdClass $extra |
|
|
|
|
68
|
|
|
*/ |
69
|
1 |
|
public function __construct($name, $version, $packageRepository=null, |
70
|
|
|
$packageSource=null, stdClass $extra=null) { |
71
|
1 |
|
$this->name = $name; |
72
|
1 |
|
$this->version = $version; |
73
|
|
|
|
74
|
1 |
|
$this->packageRepository = $packageRepository; |
75
|
1 |
|
$this->packageSource = $packageSource; |
76
|
|
|
|
77
|
1 |
|
$this->extra = $extra; |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the component's name. |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
* |
85
|
|
|
* @codeCoverageIgnore |
86
|
|
|
*/ |
87
|
|
|
public function getName() { |
88
|
|
|
return $this->name; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the ID of the component's package repository. |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
* |
96
|
|
|
* @codeCoverageIgnore |
97
|
|
|
*/ |
98
|
|
|
public function getPackageRepository() { |
99
|
|
|
return $this->packageRepository; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the ID of the component's package source. |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
* |
107
|
|
|
* @codeCoverageIgnore |
108
|
|
|
*/ |
109
|
|
|
public function getPackageSource() { |
110
|
|
|
return $this->packageSource; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get the component's version. |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
* |
118
|
|
|
* @codeCoverageIgnore |
119
|
|
|
*/ |
120
|
|
|
public function getVersion() { |
121
|
|
|
return $this->version; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the specified extra key. |
126
|
|
|
* |
127
|
|
|
* @param string $property |
128
|
|
|
* |
129
|
|
|
* @return mixed |
130
|
|
|
* |
131
|
|
|
* @throws OutOfBoundsException |
132
|
|
|
*/ |
133
|
1 |
|
public function getExtra($property) { |
134
|
1 |
|
if (!property_exists($this->extra, $property)) { |
135
|
1 |
|
throw new OutOfBoundsException(sprintf( |
136
|
1 |
|
'No value specified in project file for "%s"', $property)); |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
return $this->extra->{$property}; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.