forked from symfony-tools/carsonbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryProvider.php
More file actions
53 lines (43 loc) · 1.36 KB
/
Copy pathRepositoryProvider.php
File metadata and controls
53 lines (43 loc) · 1.36 KB
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
<?php
namespace App\Service;
use App\Model\Repository;
/**
* @author Ener-Getick <egetick@gmail.com>
*/
class RepositoryProvider
{
/**
* @var Repository[]
*/
private $repositories = [];
public function __construct(array $repositories)
{
foreach ($repositories as $repositoryFullName => $repositoryData) {
if (1 !== substr_count($repositoryFullName, '/')) {
throw new \InvalidArgumentException(sprintf('The repository name %s is invalid: it must be the form "username/repo_name"', $repositoryFullName));
}
list($vendorName, $repositoryName) = explode('/', $repositoryFullName);
$this->addRepository(new Repository(
$vendorName,
$repositoryName,
$repositoryData['secret'] ?? null
));
}
}
public function getRepository(string $repositoryName): ?Repository
{
$repository = strtolower($repositoryName);
return $this->repositories[$repository] ?? null;
}
/**
* @return Repository[]
*/
public function getAllRepositories(): array
{
return array_values($this->repositories);
}
private function addRepository(Repository $repository)
{
$this->repositories[strtolower($repository->getVendor().'/'.$repository->getName())] = $repository;
}
}