EditorJS/BlockHandler.php
private function validate($rules, $blockData)
    {
        /**
         * Make sure that every required param exists in data block
         */
        foreach ($rules as $key => $value) {
            if (($key != BlockHandler::DEFAULT_ARRAY_KEY) && (isset($value['required']) ? $value['required'] : true)) {
                if (!isset($blockData[$key])) {
                    throw new EditorJSException("Not found required param `$key`");
                }
            }
        }

        /**
         * Check if there is not extra params (not mentioned in configuration rule)
         */
        foreach ($blockData as $key => $value) {
            if (!is_integer($key) && !isset($rules[$key])) {
                throw new EditorJSException("Found extra param `$key`");
            }
        }

        /**
         * Validate every key in data block
         */
        foreach ($blockData as $key => $value) {
            /**
             * PHP Array has integer keys
             */
            if (is_integer($key)) {
                $key = BlockHandler::DEFAULT_ARRAY_KEY;
            }

            $rule = $rules[$key];

            $rule = $this->expandToolSettings($rule);

            $elementType = $rule['type'];

            /**
             * Process canBeOnly rule
             */
            if (isset($rule['canBeOnly'])) {
                if (!in_array($value, $rule['canBeOnly'])) {
                    throw new EditorJSException("Option '$key' with value `$value` has invalid value. Check canBeOnly param.");
                }

                // Do not perform additional elements validation in any case
                continue;
            }

            /**
             * Validate element types
             */
            switch ($elementType) {
                case 'string':
                    if (!is_string($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be string");
                    }
                    break;

                case 'integer':
                case 'int':
                    if (!is_integer($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be integer");
                    }
                    break;

                case 'array':
                    $this->validate($rule['data'], $value);
                    break;

                case 'boolean':
                case 'bool':
                    if (!is_bool($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be boolean");
                    }
                    break;

                default:
                    throw new EditorJSException("Unhandled type `$elementType`");
            }
        }

        return true;
    }
private function validate($rules, $blockData)
    {
        /**
         * Make sure that every required param exists in data block
         */
        foreach ($rules as $key => $value) {
            if (($key != BlockHandler::DEFAULT_ARRAY_KEY) && (isset($value['required']) ? $value['required'] : true)) {
                if (!isset($blockData[$key])) {
                    throw new EditorJSException("Not found required param `$key`");
                }
            }
        }

        /**
         * Check if there is not extra params (not mentioned in configuration rule)
         */
        foreach ($blockData as $key => $value) {
            if (!is_integer($key) && !isset($rules[$key])) {
                throw new EditorJSException("Found extra param `$key`");
            }
        }

        /**
         * Validate every key in data block
         */
        foreach ($blockData as $key => $value) {
            /**
             * PHP Array has integer keys
             */
            if (is_integer($key)) {
                $key = BlockHandler::DEFAULT_ARRAY_KEY;
            }

            $rule = $rules[$key];

            $rule = $this->expandToolSettings($rule);

            $elementType = $rule['type'];

            /**
             * Process canBeOnly rule
             */
            if (isset($rule['canBeOnly'])) {
                if (!in_array($value, $rule['canBeOnly'])) {
                    throw new EditorJSException("Option '$key' with value `$value` has invalid value. Check canBeOnly param.");
                }

                // Do not perform additional elements validation in any case
                continue;
            }

            /**
             * Validate element types
             */
            switch ($elementType) {
                case 'string':
                    if (!is_string($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be string");
                    }
                    break;

                case 'integer':
                case 'int':
                    if (!is_integer($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be integer");
                    }
                    break;

                case 'array':
                    $this->validate($rule['data'], $value);
                    break;

                case 'boolean':
                case 'bool':
                    if (!is_bool($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be boolean");
                    }
                    break;

                default:
                    throw new EditorJSException("Unhandled type `$elementType`");
            }
        }

        return true;
    }
private function validate ( $ rules , $ blockData ) { /**
         * Make sure that every required param exists in data block
         */ foreach ( $ rules as $ key => $ value ) { if ( ( $ key != BlockHandler :: DEFAULT_ARRAY_KEY ) && ( isset ( $ value [ 'required' ] ) ? $ value [ 'required' ] : true ) ) { if ( ! isset ( $ blockData [ $ key ] ) ) { throw new EditorJSException ( "Not found required param `$key`" ) ; } } } /**
         * Check if there is not extra params (not mentioned in configuration rule)
         */ foreach ( $ blockData as $ key => $ value ) { if ( ! is_integer ( $ key ) && ! isset ( $ rules [ $ key ] ) ) { throw new EditorJSException ( "Found extra param `$key`" ) ; } } /**
         * Validate every key in data block
         */ foreach ( $ blockData as $ key => $ value ) { /**
             * PHP Array has integer keys
             */ if ( is_integer ( $ key ) ) { $ key = BlockHandler :: DEFAULT_ARRAY_KEY ; } $ rule = $ rules [ $ key ] ; $ rule = $ this -> expandToolSettings ( $ rule ) ; $ elementType = $ rule [ 'type' ] ; /**
             * Process canBeOnly rule
             */ if ( isset ( $ rule [ 'canBeOnly' ] ) ) { if ( ! in_array ( $ value , $ rule [ 'canBeOnly' ] ) ) { throw new EditorJSException ( "Option '$key' with value `$value` has invalid value. Check canBeOnly param." ) ; } // Do not perform additional elements validation in any case continue ; } /**
             * Validate element types
             */ switch ( $ elementType ) { case 'string' : if ( ! is_string ( $ value ) ) { throw new EditorJSException ( "Option '$key' with value `$value` must be string" ) ; } break ; case 'integer' : case 'int' : if ( ! is_integer ( $ value ) ) { throw new EditorJSException ( "Option '$key' with value `$value` must be integer" ) ; } break ; case 'array' : $ this -> validate ( $ rule [ 'data' ] , $ value ) ; break ; case 'boolean' : case 'bool' : if ( ! is_bool ( $ value ) ) { throw new EditorJSException ( "Option '$key' with value `$value` must be boolean" ) ; } break ; default : throw new EditorJSException ( "Unhandled type `$elementType`" ) ; } } return true ; }
Apply validation rule to the data block

@param array $rules
@param array $blockData

@throws EditorJSException

@return bool
Apply validation rule to the data block