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\DirectoryComponentSource; |
15
|
|
|
use ComponentManager\ComponentSpecification; |
16
|
|
|
use ComponentManager\ComponentVersion; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Filesystem package repository. |
20
|
|
|
* |
21
|
|
|
* Allows sourcing components from a local filesystem. |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
class FilesystemPackageRepository extends AbstractPackageRepository |
|
|
|
|
24
|
|
|
implements PackageRepository { |
25
|
|
|
/** |
26
|
|
|
* @inheritdoc PackageRepository |
27
|
|
|
*/ |
28
|
|
|
public function getId() { |
29
|
|
|
return 'Filesystem'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc PackageRepository |
34
|
|
|
*/ |
35
|
|
|
public function getName() { |
36
|
|
|
return 'Filesystem package repository'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc PackageRepository |
41
|
|
|
*/ |
42
|
|
|
public function resolveComponent(ComponentSpecification $componentSpecification, |
43
|
|
|
LoggerInterface $logger) { |
44
|
|
|
return new Component($componentSpecification->getName(), [ |
45
|
|
|
new ComponentVersion(null, null, null, [ |
46
|
|
|
new DirectoryComponentSource($componentSpecification->getExtra('directory')), |
47
|
|
|
]), |
48
|
|
|
], $this); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc PackageRepository |
53
|
|
|
*/ |
54
|
|
|
public function satisfiesVersion($versionSpecification, ComponentVersion $version) { |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.