Browse Source

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

main
ghost 6 months ago
parent
commit
f913b7e19b
  1. 14
      README.md
  2. 61
      src/Reader.php

14
README.md

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

61
src/Reader.php

@ -6,60 +6,7 @@ namespace ClitorIsProtocol\Kevacoin; @@ -6,60 +6,7 @@ namespace ClitorIsProtocol\Kevacoin;
class Reader
{
private int $_protocol = 1;
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)
public function data(array $pieces, bool $decode = true): ?string
@ -126,25 +73,25 @@ class Reader @@ -126,25 +73,25 @@ class Reader
// Get File MIME
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
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
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_
public function valid(): bool
{
return !$this->_errors;
return !$this->_errors; // @TODO update protocol API to 1.3.0
}
// Dump tool

Loading…
Cancel
Save