Browse Source

update protocol API to 1.3.0 @TODO fileMime, fileSize, fileName

main
ghost 4 months ago
parent
commit
f913b7e19b
  1. 18
      README.md
  2. 63
      src/Reader.php

18
README.md

@ -23,22 +23,16 @@ $client = new \Kevachat\Kevacoin\Client(
); );
// Get meta data by namespace // Get meta data by namespace
if ($meta = $client->kevaGet($namespace, '_CLITOR_IS_')) if ($client->kevaGet($namespace, '_CLITOR_IS_'))
{ {
// Init reader with meta data received // Init reader with meta data received
$reader = new \ClitorIsProtocol\Kevacoin\Reader( $reader = new \ClitorIsProtocol\Kevacoin\Reader;
$meta['value']
);
// Recommended to check the meta is valid // Get namespace records from blockchain
if ($reader->valid()) if ($pieces = $client->kevaFilter($namespace))
{ {
// Grab namespace records from blockchain // Implement app logic
if ($pieces = $client->kevaFilter($namespace)) echo $reader->data($pieces);
{
// Implement your app logic
echo $reader->data($pieces);
}
} }
} }
``` ```

63
src/Reader.php

@ -6,60 +6,7 @@ namespace ClitorIsProtocol\Kevacoin;
class Reader class Reader
{ {
private int $_protocol = 1; private array $_errors = [];
private array $_errors = [];
private array $_meta = [];
public function __construct(string $value)
{
if (!$meta = @json_decode($value, true))
{
$this->_errors[] = _('[_CLITOR_IS_] decode error');
}
if // version valid
(!
(
isset($meta['version']) && preg_match(sprintf('/^%s\./', $this->_protocol), $meta['version'])
)
) $this->_errors[] = _('[_CLITOR_IS_] version not compatible');
if // model valid
(!
(
isset($meta['model']) && is_array($meta['model']) &&
isset($meta['model']['name']) && strtolower($meta['model']['name']) === 'kevacoin' &&
isset($meta['model']['software']) && is_array($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'])
)
) $this->_errors[] = _('[_CLITOR_IS_] model not compatible');
// pieces valid
if
(!
(
isset($meta['pieces']) && is_array($meta['pieces']) &&
isset($meta['pieces']['total']) && is_int($meta['pieces']['total']) && $meta['pieces']['total'] > 0 &&
isset($meta['pieces']['size']) && is_int($meta['pieces']['size']) && $meta['pieces']['size'] >= 1
&& $meta['pieces']['size'] <= 3072
)
) $this->_errors[] = _('[_CLITOR_IS_] pieces not compatible');
if // file valid
(!
(
isset($meta['file']) && is_array($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');
if (!$this->_errors) $this->_meta = $meta;
}
// Decode pieces data (by keva_get namespace response) // Decode pieces data (by keva_get namespace response)
public function data(array $pieces, bool $decode = true): ?string public function data(array $pieces, bool $decode = true): ?string
@ -126,25 +73,25 @@ class Reader
// Get File MIME // Get File MIME
public function fileMime(): ?string public function fileMime(): ?string
{ {
return !empty($this->_meta['file']['mime']) ? $this->_meta['file']['mime'] : null; return null; // @TODO update protocol API to 1.3.0
} }
// Get File Size // Get File Size
public function fileSize(): ?int public function fileSize(): ?int
{ {
return !empty($this->_meta['file']['size']) ? $this->_meta['file']['size'] : null; return null; // @TODO update protocol API to 1.3.0
} }
// Get File Name // Get File Name
public function fileName(): ?string public function fileName(): ?string
{ {
return !empty($this->_meta['file']['name']) ? $this->_meta['file']['name'] : null; return null; // @TODO update protocol API to 1.3.0
} }
// Validate _CLITOR_IS_ // Validate _CLITOR_IS_
public function valid(): bool public function valid(): bool
{ {
return !$this->_errors; return !$this->_errors; // @TODO update protocol API to 1.3.0
} }
// Dump tool // Dump tool

Loading…
Cancel
Save