php-censor/src/BuildFactory.php

83 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2016-07-19 20:28:11 +02:00
namespace PHPCensor;
use PHPCensor\Model\Project;
2018-03-04 08:30:34 +01:00
use PHPCensor\Store\Factory;
2016-07-19 20:28:11 +02:00
use PHPCensor\Model\Build;
2013-05-16 03:16:56 +02:00
/**
2017-10-21 10:51:05 +02:00
* BuildFactory - Takes in a generic "Build" and returns a type-specific build model.
*
2017-03-04 16:39:56 +01:00
* @author Dan Cryer <dan@block8.co.uk>
*/
class BuildFactory
{
/**
* @param integer $buildId
2017-11-05 15:48:36 +01:00
*
* @return Build|null
*/
public static function getBuildById($buildId)
{
$build = Factory::getStore('Build')->getById($buildId);
if (empty($build)) {
return null;
}
return self::getBuild($build);
}
/**
2017-11-05 15:48:36 +01:00
* 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
*/
2015-10-05 15:48:17 +02:00
public static function getBuild(Build $build)
{
2015-10-05 15:48:17 +02:00
$project = $build->getProject();
2015-10-05 15:48:17 +02:00
if (!empty($project)) {
switch ($project->getType()) {
case Project::TYPE_LOCAL:
2015-10-05 15:48:17 +02:00
$type = 'LocalBuild';
break;
case Project::TYPE_GIT:
$type = 'GitBuild';
break;
case Project::TYPE_GITHUB:
2015-10-05 15:48:17 +02:00
$type = 'GithubBuild';
break;
case Project::TYPE_BITBUCKET:
2015-10-05 15:48:17 +02:00
$type = 'BitbucketBuild';
break;
case Project::TYPE_GITLAB:
2015-10-05 15:48:17 +02:00
$type = 'GitlabBuild';
break;
case Project::TYPE_GOGS:
$type = 'GogsBuild';
break;
case Project::TYPE_HG:
$type = 'HgBuild';
2015-10-05 15:48:17 +02:00
break;
case Project::TYPE_BITBUCKET_HG:
$type = 'BitbucketHgBuild';
2015-10-05 15:48:17 +02:00
break;
case Project::TYPE_SVN:
$type = 'SvnBuild';
break;
2015-10-09 11:14:54 +02:00
default:
return $build;
2015-10-05 15:48:17 +02:00
}
2015-10-05 16:07:25 +02:00
2016-07-19 20:28:11 +02:00
$class = '\\PHPCensor\\Model\\Build\\' . $type;
2015-10-05 15:48:17 +02:00
$build = new $class($build->getDataArray());
2015-10-05 15:41:13 +02:00
}
2015-10-05 15:41:13 +02:00
return $build;
}
}