mirror of
https://github.com/clitor-is-protocol/kevacoin-php.git
synced 2025-09-09 13:01:59 +00:00
sort methods
This commit is contained in:
parent
329221f0ae
commit
6ced526f8e
98
src/Get.php
98
src/Get.php
@ -8,55 +8,6 @@ class Get
|
|||||||
{
|
{
|
||||||
private array $_errors = [];
|
private array $_errors = [];
|
||||||
|
|
||||||
// Validate keva_get _CLITOR_IS_ value
|
|
||||||
public function clitorIs(string $value): bool
|
|
||||||
{
|
|
||||||
if (!$meta = @json_decode($value))
|
|
||||||
{
|
|
||||||
$this->_errors[] = _('[_CLITOR_IS_] decode error');
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (false)
|
|
||||||
{
|
|
||||||
// version
|
|
||||||
case isset($meta->version) && preg_match('/[\d]{2}\.[\d]{2}\.[\d]{2}/', $meta->version):
|
|
||||||
|
|
||||||
$this->_errors[] = _('[_CLITOR_IS_] version not compatible');
|
|
||||||
|
|
||||||
// model
|
|
||||||
case isset($meta->model->name) && $meta->model->name !== 'kevacoin' &&
|
|
||||||
isset($meta->model->software) && is_object($meta->model->software) &&
|
|
||||||
isset($meta->model->software->version) && is_int($meta->model->software->version) &&
|
|
||||||
isset($meta->model->software->protocol) && is_int($meta->model->software->protocol) &&
|
|
||||||
isset($meta->model->namespace) && preg_match('/^N[0-9A-z]{33}$/', $meta->model->namespace):
|
|
||||||
|
|
||||||
$this->_errors[] = _('[_CLITOR_IS_] model not compatible');
|
|
||||||
|
|
||||||
// pieces
|
|
||||||
case isset($meta->pieces) && is_object($meta->pieces) &&
|
|
||||||
isset($meta->pieces->total) && is_int($meta->pieces->total) && $meta->pieces->total > 1 &&
|
|
||||||
isset($meta->pieces->size) && is_int($meta->pieces->size) && $meta->pieces->size >= 1
|
|
||||||
&& $meta->pieces->size <= 3072:
|
|
||||||
|
|
||||||
$this->_errors[] = _('[_CLITOR_IS_] pieces not compatible');
|
|
||||||
|
|
||||||
// file
|
|
||||||
case isset($meta->file) && is_object($meta->file) &&
|
|
||||||
isset($meta->file->name) && is_string($meta->file->name) &&
|
|
||||||
isset($meta->file->mime) && is_string($meta->file->mime) &&
|
|
||||||
isset($meta->file->size) && is_int($meta->file->size) &&
|
|
||||||
isset($meta->file->md5) && is_string($meta->file->md5):
|
|
||||||
|
|
||||||
$this->_errors[] = _('[_CLITOR_IS_] file not compatible');
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode pieces data (by keva_get namespace response)
|
// Decode pieces data (by keva_get namespace response)
|
||||||
public function decode(array $pieces): ?string
|
public function decode(array $pieces): ?string
|
||||||
{
|
{
|
||||||
@ -114,6 +65,55 @@ class Get
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate keva_get _CLITOR_IS_ value
|
||||||
|
public function clitorIs(string $value): bool
|
||||||
|
{
|
||||||
|
if (!$meta = @json_decode($value))
|
||||||
|
{
|
||||||
|
$this->_errors[] = _('[_CLITOR_IS_] decode error');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (false)
|
||||||
|
{
|
||||||
|
// version
|
||||||
|
case isset($meta->version) && preg_match('/[\d]{2}\.[\d]{2}\.[\d]{2}/', $meta->version):
|
||||||
|
|
||||||
|
$this->_errors[] = _('[_CLITOR_IS_] version not compatible');
|
||||||
|
|
||||||
|
// model
|
||||||
|
case isset($meta->model->name) && $meta->model->name !== 'kevacoin' &&
|
||||||
|
isset($meta->model->software) && is_object($meta->model->software) &&
|
||||||
|
isset($meta->model->software->version) && is_int($meta->model->software->version) &&
|
||||||
|
isset($meta->model->software->protocol) && is_int($meta->model->software->protocol) &&
|
||||||
|
isset($meta->model->namespace) && preg_match('/^N[0-9A-z]{33}$/', $meta->model->namespace):
|
||||||
|
|
||||||
|
$this->_errors[] = _('[_CLITOR_IS_] model not compatible');
|
||||||
|
|
||||||
|
// pieces
|
||||||
|
case isset($meta->pieces) && is_object($meta->pieces) &&
|
||||||
|
isset($meta->pieces->total) && is_int($meta->pieces->total) && $meta->pieces->total > 1 &&
|
||||||
|
isset($meta->pieces->size) && is_int($meta->pieces->size) && $meta->pieces->size >= 1
|
||||||
|
&& $meta->pieces->size <= 3072:
|
||||||
|
|
||||||
|
$this->_errors[] = _('[_CLITOR_IS_] pieces not compatible');
|
||||||
|
|
||||||
|
// file
|
||||||
|
case isset($meta->file) && is_object($meta->file) &&
|
||||||
|
isset($meta->file->name) && is_string($meta->file->name) &&
|
||||||
|
isset($meta->file->mime) && is_string($meta->file->mime) &&
|
||||||
|
isset($meta->file->size) && is_int($meta->file->size) &&
|
||||||
|
isset($meta->file->md5) && is_string($meta->file->md5):
|
||||||
|
|
||||||
|
$this->_errors[] = _('[_CLITOR_IS_] file not compatible');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Dump tool
|
// Dump tool
|
||||||
public function errors(): array
|
public function errors(): array
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user