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\PackageRepository; |
12
|
|
|
|
13
|
|
|
use ComponentManager\Component; |
14
|
|
|
use ComponentManager\ComponentSource\GitComponentSource; |
15
|
|
|
use ComponentManager\ComponentSpecification; |
16
|
|
|
use ComponentManager\ComponentVersion; |
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Git package repository. |
21
|
|
|
* |
22
|
|
|
* Allows sourcing components from arbitrary Git repositories. |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
class GitPackageRepository extends AbstractCachingPackageRepository |
|
|
|
|
25
|
|
|
implements PackageRepository { |
26
|
|
|
/** |
27
|
|
|
* @inheritdoc PackageRepository |
28
|
|
|
*/ |
29
|
|
|
public function getId() { |
30
|
|
|
return 'Git'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc PackageRepository |
35
|
|
|
*/ |
36
|
|
|
public function getName() { |
37
|
|
|
return 'Git package repository'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc PackageRepository |
42
|
|
|
*/ |
43
|
|
|
public function resolveComponent(ComponentSpecification $componentSpecification, |
44
|
|
|
LoggerInterface $logger) { |
45
|
|
|
return new Component($componentSpecification->getName(), [ |
46
|
|
|
new ComponentVersion(null, null, null, [ |
47
|
|
|
new GitComponentSource($componentSpecification->getExtra('uri'), $componentSpecification->getVersion()) |
48
|
|
|
]), |
49
|
|
|
], $this); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc PackageRepository |
54
|
|
|
*/ |
55
|
|
|
public function satisfiesVersion($versionSpecification, ComponentVersion $version) { |
56
|
|
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.