Added constants for project types (git, hg, github...).
This commit is contained in:
parent
2ed6377971
commit
10d41dba81
4 changed files with 85 additions and 32 deletions
|
|
@ -2,10 +2,21 @@
|
|||
|
||||
namespace PHPCensor\Model\Base;
|
||||
|
||||
use PHPCensor\Exception\HttpException\ValidationException;
|
||||
use PHPCensor\Model;
|
||||
|
||||
class Project extends Model
|
||||
{
|
||||
const TYPE_LOCAL = 'local';
|
||||
const TYPE_GIT = 'git';
|
||||
const TYPE_GITHUB = 'github';
|
||||
const TYPE_BITBUCKET = 'bitbucket';
|
||||
const TYPE_GITLAB = 'gitlab';
|
||||
const TYPE_GOGS = 'gogs';
|
||||
const TYPE_HG = 'hg';
|
||||
const TYPE_BITBUCKET_HG = 'bitbucket-hg';
|
||||
const TYPE_SVN = 'svn';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -32,6 +43,21 @@ class Project extends Model
|
|||
'user_id' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedTypes = [
|
||||
self::TYPE_LOCAL,
|
||||
self::TYPE_GIT,
|
||||
self::TYPE_GITHUB,
|
||||
self::TYPE_BITBUCKET,
|
||||
self::TYPE_GITLAB,
|
||||
self::TYPE_GOGS,
|
||||
self::TYPE_HG,
|
||||
self::TYPE_BITBUCKET_HG,
|
||||
self::TYPE_SVN,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
|
|
@ -247,12 +273,20 @@ class Project extends Model
|
|||
* @param string $value
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function setType($value)
|
||||
{
|
||||
$this->validateNotNull('type', $value);
|
||||
$this->validateString('type', $value);
|
||||
|
||||
if (!in_array($value, $this->allowedTypes, true)) {
|
||||
throw new ValidationException(
|
||||
'Column "type" must be one of: ' . join(', ', $this->allowedTypes) . '.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->data['type'] === $value) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue