*/ 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. * @param string $type Set the type manually if you already know it. * @return Build */ public static function getBuild(Build $build, $type = null) { if (is_null($type) && !is_null($build->getProject())) { $type = $build->getProject()->getType(); } switch ($type) { case 'remote': $type = 'RemoteGitBuild'; break; case 'local': $type = 'LocalBuild'; break; case 'github': $type = 'GithubBuild'; break; case 'bitbucket': $type = 'BitbucketBuild'; break; case 'gitlab': $type = 'GitlabBuild'; break; case 'hg': $type = 'MercurialBuild'; break; case 'svn': $type = 'SubversionBuild'; break; default: $type = null; break; } if (!is_null($type)) { $type = '\\PHPCI\\Model\\Build\\' . $type; $build = new $type($build->getDataArray()); } return $build; } }