forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuildFactory.php
More file actions
79 lines (70 loc) · 2.08 KB
/
Copy pathBuildFactory.php
File metadata and controls
79 lines (70 loc) · 2.08 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace PHPCensor;
use b8\Store\Factory;
use PHPCensor\Model\Build;
/**
* PHPCI Build Factory - Takes in a generic "Build" and returns a type-specific build model.
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class BuildFactory
{
/**
* @param $buildId
* @return Build
* @throws \Exception
*/
public static function getBuildById($buildId)
{
$build = Factory::getStore('Build')->getById($buildId);
if (empty($build)) {
throw new \Exception('Build ID ' . $buildId . ' does not exist.');
}
return self::getBuild($build);
}
/**
* Takes a generic build and returns a type-specific build model.
* @param Build $build The build from which to get a more specific build type.
* @return Build
*/
public static function getBuild(Build $build)
{
$project = $build->getProject();
if (!empty($project)) {
switch ($project->getType()) {
case 'remote':
$type = 'RemoteGitBuild';
break;
case 'local':
$type = 'LocalBuild';
break;
case 'github':
$type = 'GithubBuild';
break;
case 'bitbucket':
$type = 'BitbucketBuild';
break;
case 'bitbuckethg':
$type = 'BitbucketHgBuild';
break;
case 'gitlab':
$type = 'GitlabBuild';
break;
case 'hg':
$type = 'MercurialBuild';
break;
case 'svn':
$type = 'SubversionBuild';
break;
case 'gogs':
$type = 'GogsBuild';
break;
default:
return $build;
}
$class = '\\PHPCensor\\Model\\Build\\' . $type;
$build = new $class($build->getDataArray());
}
return $build;
}
}