forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildFactory.php
More file actions
85 lines (76 loc) · 2.28 KB
/
Copy pathBuildFactory.php
File metadata and controls
85 lines (76 loc) · 2.28 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
80
81
82
83
84
85
<?php
namespace PHPCensor;
use PHPCensor\Model\Project;
use PHPCensor\Store\Factory;
use PHPCensor\Model\Build;
/**
* BuildFactory - Takes in a generic "Build" and returns a type-specific build model.
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class BuildFactory
{
/**
* @param integer $buildId
*
* @return Build|null
*/
public static function getBuildById($buildId)
{
$build = Factory::getStore('Build')->getById($buildId);
if (empty($build)) {
return null;
}
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 Project::TYPE_LOCAL:
$type = 'LocalBuild';
break;
case Project::TYPE_GIT:
$type = 'GitBuild';
break;
case Project::TYPE_GITHUB:
$type = 'GithubBuild';
break;
case Project::TYPE_BITBUCKET:
$type = 'BitbucketBuild';
break;
case Project::TYPE_GITLAB:
$type = 'GitlabBuild';
break;
case Project::TYPE_GOGS:
$type = 'GogsBuild';
break;
case Project::TYPE_HG:
$type = 'HgBuild';
break;
case Project::TYPE_BITBUCKET_HG:
$type = 'BitbucketHgBuild';
break;
case Project::TYPE_BITBUCKET_SERVER:
$type = 'BitbucketServerBuild';
break;
case Project::TYPE_SVN:
$type = 'SvnBuild';
break;
default:
return $build;
}
$class = '\\PHPCensor\\Model\\Build\\' . $type;
$build = new $class($build->getDataArray());
}
return $build;
}
}