mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-31 20:12:29 +01:00
Added the payload models
This commit is contained in:
69
lib/models/PayloadCommitVerification.php
Normal file
69
lib/models/PayloadCommitVerification.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace yii\gitea\models;
|
||||
|
||||
use yii\base\{Model};
|
||||
|
||||
/**
|
||||
* Represents the GPG verification of a commit.
|
||||
*/
|
||||
class PayloadCommitVerification extends Model {
|
||||
|
||||
/**
|
||||
* @var bool Value indicating whether the verification has succeeded.
|
||||
*/
|
||||
public $isVerified = false;
|
||||
|
||||
/**
|
||||
* @var string A custom message sent with the verification request.
|
||||
*/
|
||||
public $payload = '';
|
||||
|
||||
/**
|
||||
* @var string A message providing details about the verification.
|
||||
*/
|
||||
public $reason = '';
|
||||
|
||||
/**
|
||||
* @var string The signing key used for the verification.
|
||||
*/
|
||||
public $signature = '';
|
||||
|
||||
/**
|
||||
* Creates a new commit from the specified JSON map.
|
||||
* @param object $map A JSON map representing a commit.
|
||||
* @return static The instance corresponding to the specified JSON map.
|
||||
*/
|
||||
static function fromJson(object $map): self {
|
||||
return new static([
|
||||
'isVerified' => isset($map->verified) && is_bool($map->verified) ? $map->verified : false,
|
||||
'payload' => isset($map->payload) && is_string($map->payload) ? $map->payload : '',
|
||||
'reason' => isset($map->reason) && is_string($map->reason) ? $map->reason : '',
|
||||
'signature' => isset($map->signature) && is_string($map->signature) ? $map->signature : ''
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of fields that should be returned by default.
|
||||
* @return array The list of field names or field definitions.
|
||||
*/
|
||||
function fields(): array {
|
||||
return [
|
||||
'payload',
|
||||
'reason',
|
||||
'signature',
|
||||
'verified' => 'isVerified'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validation rules for attributes.
|
||||
* @return array[] The validation rules.
|
||||
*/
|
||||
function rules(): array {
|
||||
return [
|
||||
[['payload', 'reason', 'signature'], 'trim'],
|
||||
['isVerified', 'boolean', 'falseValue' => false, 'trueValue' => true]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user