2013-05-16 00:47:37 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
2014-05-12 18:26:17 +02:00
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
2013-05-16 03:57:02 +02:00
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
2014-05-12 18:26:17 +02:00
|
|
|
* @link https://www.phptesting.org/
|
2013-05-16 03:16:56 +02:00
|
|
|
*/
|
2013-05-16 00:47:37 +02:00
|
|
|
|
|
|
|
namespace PHPCI;
|
2013-05-16 03:57:02 +02:00
|
|
|
|
2014-02-25 18:00:05 +01:00
|
|
|
use b8\Store\Factory;
|
2013-05-16 03:57:02 +02:00
|
|
|
use PHPCI\Model\Build;
|
2013-05-16 00:47:37 +02:00
|
|
|
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
|
|
|
* PHPCI Build Factory - Takes in a generic "Build" and returns a type-specific build model.
|
2013-05-16 03:57:02 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
2013-05-16 03:16:56 +02:00
|
|
|
*/
|
2013-05-16 00:47:37 +02:00
|
|
|
class BuildFactory
|
|
|
|
{
|
2014-02-25 18:00:05 +01:00
|
|
|
/**
|
|
|
|
* @param $buildId
|
|
|
|
* @return Build
|
2014-05-09 12:47:42 +02:00
|
|
|
* @throws \Exception
|
2014-02-25 18:00:05 +01:00
|
|
|
*/
|
|
|
|
public static function getBuildById($buildId)
|
|
|
|
{
|
|
|
|
$build = Factory::getStore('Build')->getById($buildId);
|
|
|
|
|
2014-05-09 12:47:42 +02:00
|
|
|
if (empty($build)) {
|
|
|
|
throw new \Exception('Build ID ' . $buildId . ' does not exist.');
|
|
|
|
}
|
|
|
|
|
2014-02-25 18:00:05 +01:00
|
|
|
return self::getBuild($build);
|
|
|
|
}
|
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* Takes a generic build and returns a type-specific build model.
|
2015-10-05 15:41:13 +02:00
|
|
|
* @param Build $build The build from which to get a more specific build type.
|
|
|
|
* @param string $type Set the type manually if you already know it.
|
2014-02-25 18:00:05 +01:00
|
|
|
* @return Build
|
2013-05-16 18:17:29 +02:00
|
|
|
*/
|
2015-10-05 15:41:13 +02:00
|
|
|
public static function getBuild(Build $build, $type = null)
|
2013-05-16 03:57:02 +02:00
|
|
|
{
|
2015-10-05 15:41:13 +02:00
|
|
|
if (is_null($type) && !is_null($build->getProject())) {
|
|
|
|
$type = $build->getProject()->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($type) {
|
2013-06-19 17:47:25 +02:00
|
|
|
case 'remote':
|
|
|
|
$type = 'RemoteGitBuild';
|
|
|
|
break;
|
2013-05-16 03:57:02 +02:00
|
|
|
case 'local':
|
|
|
|
$type = 'LocalBuild';
|
|
|
|
break;
|
|
|
|
case 'github':
|
|
|
|
$type = 'GithubBuild';
|
|
|
|
break;
|
|
|
|
case 'bitbucket':
|
|
|
|
$type = 'BitbucketBuild';
|
|
|
|
break;
|
2013-08-23 16:05:12 +02:00
|
|
|
case 'gitlab':
|
|
|
|
$type = 'GitlabBuild';
|
|
|
|
break;
|
2013-09-04 14:54:26 +02:00
|
|
|
case 'hg':
|
|
|
|
$type = 'MercurialBuild';
|
|
|
|
break;
|
2015-01-26 19:12:48 +01:00
|
|
|
case 'svn':
|
|
|
|
$type = 'SubversionBuild';
|
|
|
|
break;
|
2015-10-05 15:41:13 +02:00
|
|
|
default:
|
|
|
|
$type = null;
|
|
|
|
break;
|
2013-05-16 03:57:02 +02:00
|
|
|
}
|
2013-05-16 00:47:37 +02:00
|
|
|
|
2015-10-05 15:41:13 +02:00
|
|
|
if (!is_null($type)) {
|
|
|
|
$type = '\\PHPCI\\Model\\Build\\' . $type;
|
|
|
|
$build = new $type($build->getDataArray());
|
|
|
|
}
|
2013-05-16 00:47:37 +02:00
|
|
|
|
2015-10-05 15:41:13 +02:00
|
|
|
return $build;
|
2013-05-16 03:57:02 +02:00
|
|
|
}
|
|
|
|
}
|