src/Composer/Json/JsonFile.php
public function validateSchema($schema = self::STRICT_SCHEMA)
    {
        $content = file_get_contents($this->path);
        $data = json_decode($content);

        if (null === $data && 'null' !== $content) {
            self::validateSyntax($content, $this->path);
        }

        $schemaFile = __DIR__ . '/../../../res/composer-schema.json';
        $schemaData = json_decode(file_get_contents($schemaFile));

        if ($schema === self::LAX_SCHEMA) {
            $schemaData->additionalProperties = true;
            $schemaData->required = array();
        }

        $validator = new Validator();
        $validator->check($data, $schemaData);

        // TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?

        if (!$validator->isValid()) {
            $errors = array();
            foreach ((array) $validator->getErrors() as $error) {
                $errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
            }
            throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
        }

        return true;
    }
public function validateSchema($schema = self::STRICT_SCHEMA)
    {
        $content = file_get_contents($this->path);
        $data = json_decode($content);

        if (null === $data && 'null' !== $content) {
            self::validateSyntax($content, $this->path);
        }

        $schemaFile = __DIR__ . '/../../../res/composer-schema.json';
        $schemaData = json_decode(file_get_contents($schemaFile));

        if ($schema === self::LAX_SCHEMA) {
            $schemaData->additionalProperties = true;
            $schemaData->required = array();
        }

        $validator = new Validator();
        $validator->check($data, $schemaData);

        // TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?

        if (!$validator->isValid()) {
            $errors = array();
            foreach ((array) $validator->getErrors() as $error) {
                $errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
            }
            throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
        }

        return true;
    }
public function validateSchema ( $ schema = self :: STRICT_SCHEMA ) { $ content = file_get_contents ( $ this -> path ) ; $ data = json_decode ( $ content ) ; if ( null === $ data && 'null' !== $ content ) { self :: validateSyntax ( $ content , $ this -> path ) ; } $ schemaFile = __DIR__ . '/../../../res/composer-schema.json' ; $ schemaData = json_decode ( file_get_contents ( $ schemaFile ) ) ; if ( $ schema === self :: LAX_SCHEMA ) { $ schemaData -> additionalProperties = true ; $ schemaData -> required = array ( ) ; } $ validator = new Validator ( ) ; $ validator -> check ( $ data , $ schemaData ) ; // TODO add more validation like check version constraints and such, perhaps build that into the arrayloader? if ( ! $ validator -> isValid ( ) ) { $ errors = array ( ) ; foreach ( ( array ) $ validator -> getErrors ( ) as $ error ) { $ errors [ ] = ( $ error [ 'property' ] ? $ error [ 'property' ] . ' : ' : '' ) . $ error [ 'message' ] ; } throw new JsonValidationException ( '"' . $ this -> path . '" does not match the expected JSON schema' , $ errors ) ; } return true ; }
Validates the schema of the current json file according to composer-schema.json rules

@param  int                     $schema a JsonFile::*_SCHEMA constant
@return bool                    true on success
@throws JsonValidationException
Validates the schema of the current json file according to composer - schema . json rules