String and Filter validator.
This commit is contained in:
parent
1d02b8ba2e
commit
cfd80212ba
58
src/Validators/FilterValidator.php
Normal file
58
src/Validators/FilterValidator.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Web3\Validators;
|
||||||
|
|
||||||
|
use Web3\Validators\IValidator;
|
||||||
|
use Web3\Validators\QuantityValidator;
|
||||||
|
use Web3\Validators\TagValidator;
|
||||||
|
use Web3\Validators\HexValidator;
|
||||||
|
use Web3\Validators\AddressValidator;
|
||||||
|
|
||||||
|
class FilterValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* validate
|
||||||
|
*
|
||||||
|
* @param array $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function validate($value)
|
||||||
|
{
|
||||||
|
if (!is_array($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isset($value['fromBlock']) &&
|
||||||
|
QuantityValidator::validate($value['fromBlock']) === false &&
|
||||||
|
TagValidator::validate($value['fromBlock']) === false
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isset($value['toBlock']) &&
|
||||||
|
QuantityValidator::validate($value['toBlock']) === false &&
|
||||||
|
TagValidator::validate($value['toBlock']) === false
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isset($value['address']) && AddressValidator::validate($value['address']) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isset($value['topics']) && is_array($value['topics'])) {
|
||||||
|
foreach ($value['topics'] as $topic) {
|
||||||
|
if (is_array($topic)) {
|
||||||
|
foreach ($topic as $v) {
|
||||||
|
if (isset($v) && HexValidator::validate($v) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($topic) && HexValidator::validate($topic) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
19
src/Validators/StringValidator.php
Normal file
19
src/Validators/StringValidator.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Web3\Validators;
|
||||||
|
|
||||||
|
use Web3\Validators\IValidator;
|
||||||
|
|
||||||
|
class StringValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* validate
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function validate($value)
|
||||||
|
{
|
||||||
|
return is_string($value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user