public function validateJson(string $json, string $schemaName): ValidationResult
    {
        $schemaDir = $this->config->get('schema-dir');
        $schemaPath = $this->configDirectoryPath.$schemaDir.'/'.$schemaName.'.json';
        if(!file_exists($schemaPath)){
            throw new FileNotFoundException("File $schemaPath not found");
        }
        
        $schemaJsonString = file_get_contents($schemaPath);
        $decodedJson = json_decode($json);
        if ($decodedJson === false) {
            $schema = json_decode($schemaJsonString);
            // error decoding json
            return (new ValidationResult())
                ->addError(new ValidationError($json,
                        [],
                        [],
                        $schema,
                        "Failed to decode JSON string")
                );
        }
        return $this->dataValidation($decodedJson, $schemaJsonString);
    }
public function validateJson(string $json, string $schemaName): ValidationResult
    {
        $schemaDir = $this->config->get('schema-dir');
        $schemaPath = $this->configDirectoryPath.$schemaDir.'/'.$schemaName.'.json';
        if(!file_exists($schemaPath)){
            throw new FileNotFoundException("File $schemaPath not found");
        }
        
        $schemaJsonString = file_get_contents($schemaPath);
        $decodedJson = json_decode($json);
        if ($decodedJson === false) {
            $schema = json_decode($schemaJsonString);
            // error decoding json
            return (new ValidationResult())
                ->addError(new ValidationError($json,
                        [],
                        [],
                        $schema,
                        "Failed to decode JSON string")
                );
        }
        return $this->dataValidation($decodedJson, $schemaJsonString);
    }
public function validateJson ( string $ json , string $ schemaName ) : ValidationResult { $ schemaDir = $ this -> config -> get ( 'schema-dir' ) ; $ schemaPath = $ this -> configDirectoryPath . $ schemaDir . '/' . $ schemaName . '.json' ; if ( ! file_exists ( $ schemaPath ) ) { throw new FileNotFoundException ( "File $schemaPath not found" ) ; } $ schemaJsonString = file_get_contents ( $ schemaPath ) ; $ decodedJson = json_decode ( $ json ) ; if ( $ decodedJson === false ) { $ schema = json_decode ( $ schemaJsonString ) ; // error decoding json return ( new ValidationResult ( ) ) -> addError ( new ValidationError ( $ json , [ ] , [ ] , $ schema , "Failed to decode JSON string" ) ) ; } return $ this -> dataValidation ( $ decodedJson , $ schemaJsonString ) ; }
Validates JSON strings against a schema.
@param string $json
@param string $schemaName Name of the .json file providing the schema (without file extension)
@return ValidationResult
Validates JSON strings against a schema .