ShhFilterValidator.
This commit is contained in:
parent
f83a9c6c90
commit
85a5a20570
55
src/Validators/ShhFilterValidator.php
Normal file
55
src/Validators/ShhFilterValidator.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of web3.php package.
|
||||||
|
*
|
||||||
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
|
*
|
||||||
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Web3\Validators;
|
||||||
|
|
||||||
|
use Web3\Validators\IValidator;
|
||||||
|
use Web3\Validators\QuantityValidator;
|
||||||
|
use Web3\Validators\HexValidator;
|
||||||
|
use Web3\Validators\IdentityValidator;
|
||||||
|
|
||||||
|
class ShhFilterValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* validate
|
||||||
|
*
|
||||||
|
* @param array $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function validate($value)
|
||||||
|
{
|
||||||
|
if (!is_array($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isset($value['topics']) || !is_array($value['topics'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach ($value['topics'] as $topic) {
|
||||||
|
if (is_array($topic)) {
|
||||||
|
foreach ($topic as $subTopic) {
|
||||||
|
if (HexValidator::validate($subTopic) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (HexValidator::validate($topic) === false) {
|
||||||
|
if (!is_null($topic)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user