JSON validator.

Usage: '<index>' => 'valid_json_string'

@param string $field
@param array  $input

@return mixed
181041
protected function validate_valid_json_string($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if (!is_string($input[$field]) || !is_object(json_decode($input[$field]))) {
            return array(
              'field' => $field,
              'value' => $input[$field],
              'rule' => __FUNCTION__,
              'param' => $param,
            );
        }
    }
825817
protected function validate_alpha_numeric($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if (!preg_match('/^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ])+$/i', $input[$field]) !== false) {
            return array(
                'field' => $field,
                'value' => $input[$field],
                'rule' => __FUNCTION__,
                'param' => $param,
            );
        }
    }
349343
protected function validate_valid_array_size_greater($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if (!is_array($input[$field]) || sizeof($input[$field]) < (int)$param) {
            return array(
              'field' => $field,
              'value' => $input[$field],
              'rule' => __FUNCTION__,
              'param' => $param,
            );
        }
    }
11848
protected function validate_max_len($field, $input, $param = null)
    {
        if (!isset($input[$field])) {
            return;
        }

        if (function_exists('mb_strlen')) {
            if (mb_strlen($input[$field]) <= (int) $param) {
                return;
            }
        } else {
            if (strlen($input[$field]) <= (int) $param) {
                return;
            }
        }

        return array(
            'field' => $field,
            'value' => $input[$field],
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
93887
public static function isJson($input): bool
    {
        $test = json_decode($input);
        return ($test instanceof \stdClass || \is_array($test));
    }
223726
public function validator($field, array $data)
    {
        if (!isset($data[$field]) || $data[$field] === '') {
            return $this->message('{fieldName}不能为空！', [
                '{fieldName}' => $this->getName($field),
            ]);
        }

        return true;
    }
1231030
public static function regexp($input, $regexp, $field_name = 'regexp')
    {
        //Define trivial model
        $model = [
            $field_name => ['type' => Validate::TYPE_REGEXP, 'regexp' => $regexp, Validate::REQUIRED]
        ];

        $parameters = [$field_name => $input];
        Validate::model($parameters, $model);

        return $parameters[$field_name];
    }
1236769
protected function validate_valid_cc($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        $number = preg_replace('/\D/', '', $input[$field]);

        if (function_exists('mb_strlen')) {
            $number_length = mb_strlen($number);
        } else {
            $number_length = strlen($number);
        }


        /**
         * Bail out if $number_length is 0. 
         * This can be the case if a user has entered only alphabets
         * 
         * @since 1.5
         */
        if( $number_length == 0 ) {
            return array(
                'field' => $field,
                'value' => $input[$field],
                'rule' => __FUNCTION__,
                'param' => $param,
            );
        }


        $parity = $number_length % 2;

        $total = 0;

        for ($i = 0; $i < $number_length; ++$i) {
            $digit = $number[$i];

            if ($i % 2 == $parity) {
                $digit *= 2;

                if ($digit > 9) {
                    $digit -= 9;
                }
            }

            $total += $digit;
        }

        if ($total % 10 == 0) {
            return; // Valid
        }

        return array(
            'field' => $field,
            'value' => $input[$field],
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
83653
public function validator($field, array $data)
    {
        $value = isset($data[$field]) ? $data[$field] : null;
        $targetValue = isset($data[$this->target]) ? $data[$this->target] : null;
        if ($value === $targetValue) {
            return true;
        }

        return $this->message('{fieldName}与{targetName}不相等！', [
            '{fieldName}' => $this->getName($field),
            '{targetName}' => $this->getName($this->target),
        ]);
    }
766930
public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            
            $params = $params['0'];
            if (empty($params['ftp_hostname']) || empty($params['ftp_password']) || empty($params['ftp_username']) || empty($params['ftp_port'])) {
                return false;
            }
            
            $filesystem = new Remote(Ftp::getRemoteClient($params));
            if (! $filesystem->getAdapter()->listContents()) {
                return false;
            }
            
            $filesystem->getAdapter()->disconnect();
            return true;
        } catch (\Exception $e) {
            return false;
        }
    }
755416
protected function validate_float($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if (!filter_var($input[$field], FILTER_VALIDATE_FLOAT)) {
            return array(
                'field' => $field,
                'value' => $input[$field],
                'rule' => __FUNCTION__,
                'param' => $param,
            );
        }
    }
85720
protected function validate_required($field, $input, $param = null)
    {
        if (isset($input[$field]) && ($input[$field] === false || $input[$field] === 0 || $input[$field] === 0.0 || $input[$field] === '0' || !empty($input[$field]))) {
            return;
        }

        return array(
            'field' => $field,
            'value' => null,
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
380162
protected function validate_equalsfield($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if ($input[$field] == $input[$param]) {
            return;
        }

        return array(
            'field' => $field,
            'value' => $input[$field],
            'rule' => __FUNCTION__,
            'param' => $param,
        );
    }
336153
public static function jsonEncode($input)
    {
        $json = json_encode($input);

        if ($json === 'null' && $input !== null) {
            throw new DomainException('Null result with non-null input');
        }

        return $json;
    }
861846
public static function parseToIndex($input) {
        if (($input[0] == '{' || $input[0] == '[')) {
            return Arc2JsonLdConverter::jsonLdToIndex($input);
        } else {
            $parser = \ARC2::getRDFParser();
		    $parser->parse('', $input);
            return $parser->getSimpleIndex(false);
        }
    }
56476
private function validate($field)
    {
        //====================================================================//
        // Verify - Field Type is Not Empty
        if (empty($field->type) || !is_string($field->type)) {
            return Splash::log()->err("ErrFieldsNoType");
        }
        //====================================================================//
        // Verify - Field Id is Not Empty
        if (empty($field->id) || !is_string($field->id)) {
            return Splash::log()->err("ErrFieldsNoId");
        }
        //====================================================================//
        // Verify - Field Id No Spacial Chars
        if ($field->id !== preg_replace('/[^a-zA-Z0-9-_@]/u', '', $field->id)) {
            Splash::log()->war("ErrFieldsInvalidId", $field->id);

            return false;
        }
        //====================================================================//
        // Verify - Field Name is Not Empty
        if (empty($field->name) || !is_string($field->name)) {
            return Splash::log()->err("ErrFieldsNoName");
        }
        //====================================================================//
        // Verify - Field Desc is Not Empty
        if (empty($field->desc) || !is_string($field->desc)) {
            return Splash::log()->err("ErrFieldsNoDesc");
        }

        return true;
    }
1112501
public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            
            $params = $params['0'];
            if (empty($params['rcf_username']) || empty($params['rcf_api']) || empty($params['rcf_container'])) {
                return false;
            }
            
            $client = Rcf::getRemoteClient($params, true);
            
            if ($client instanceof \OpenCloud\ObjectStore\Resource\Container) {
                $filesystem = new Remote(new Rcf($client, $params['rcf_container']));
                $filesystem->getAdapter()->listContents();
                return true;
            }
        } catch (\Exception $e) {
            return false;
        }
    }