From f913b7e19bbe2fcf45e46433e8e0e60b24c2cfc4 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 3 Jun 2024 23:22:38 +0300 Subject: [PATCH] update protocol API to 1.3.0 @TODO fileMime, fileSize, fileName --- README.md | 18 +++++---------- src/Reader.php | 63 ++++---------------------------------------------- 2 files changed, 11 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 114cf5c..de538bf 100644 --- a/README.md +++ b/README.md @@ -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()) + // Get namespace records from blockchain + if ($pieces = $client->kevaFilter($namespace)) { - // Grab namespace records from blockchain - if ($pieces = $client->kevaFilter($namespace)) - { - // Implement your app logic - echo $reader->data($pieces); - } + // Implement app logic + echo $reader->data($pieces); } } ``` \ No newline at end of file diff --git a/src/Reader.php b/src/Reader.php index 5786d03..9ed7ee2 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -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; - } + private array $_errors = []; // Decode pieces data (by keva_get namespace response) public function data(array $pieces, bool $decode = true): ?string @@ -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